From 3df3a908ac8ba987e9f0a110101674c6ad21bf5f Mon Sep 17 00:00:00 2001 From: riking Date: Fri, 11 Jul 2014 13:01:01 -0700 Subject: [PATCH 1/5] Remove email_in_address and email_in_category site settings The functionality is entirely covered by per-category email in addresses, and the category being a number was confusing people. --- config/site_settings.yml | 4 ---- ...711193923_remove_email_in_address_setting.rb | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20140711193923_remove_email_in_address_setting.rb diff --git a/config/site_settings.yml b/config/site_settings.yml index fe7b5a0987d..a68035def3a 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -384,13 +384,9 @@ email: email_in: default: false client: true - email_in_address: - default: '' - type: email email_in_min_trust: default: 2 enum: 'TrustLevelSetting' - email_in_category: -1 email_prefix: '' email_site_title: '' diff --git a/db/migrate/20140711193923_remove_email_in_address_setting.rb b/db/migrate/20140711193923_remove_email_in_address_setting.rb new file mode 100644 index 00000000000..cc2f6b63119 --- /dev/null +++ b/db/migrate/20140711193923_remove_email_in_address_setting.rb @@ -0,0 +1,17 @@ +class RemoveEmailInAddressSetting < ActiveRecord::Migration + def up + cat_id_r = ActiveRecord::Base.exec_sql("SELECT value FROM site_settings WHERE name = 'email_in_category'").first + email_r = ActiveRecord::Base.exec_sql("SELECT value FROM site_settings WHERE name = 'email_in_address'").first + if cat_id_r && email_r + category_id = cat_id_r["value"].to_i + email = email_r["value"] + ActiveRecord::Base.exec_sql("UPDATE categories SET email_in = ? WHERE id = ?", email, category_id) + end + + ActiveRecord::Base.exec_sql("DELETE FROM site_settings WHERE name = 'email_in_category' OR name = 'email_in_address'") + end + + def down + # this change is backwards-compatible + end +end From 17db265b414cd69b2ff2db17723a382f3a2147bd Mon Sep 17 00:00:00 2001 From: riking Date: Fri, 11 Jul 2014 13:30:08 -0700 Subject: [PATCH 2/5] Remove use of email_in_address and email_in_category --- config/locales/server.en.yml | 4 +- docs/MAILING-LIST-SETUP.md | 6 +- lib/email/receiver.rb | 8 +-- spec/components/email/receiver_spec.rb | 93 -------------------------- 4 files changed, 6 insertions(+), 105 deletions(-) diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index f1d6c5a4748..9aa130752c7 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -912,10 +912,8 @@ en: pop3s_polling_host: "The host to poll for email via POP3S." pop3s_polling_username: "The username for the POP3S account to poll for email." pop3s_polling_password: "The password for the POP3S account to poll for email." - email_in: "Allow users to post new topics via email." - email_in_address: "The email address the users can post new topics to. None means users can't post globally." + email_in: "Allow users to post new topics via email (requires pop3 polling). Configure the addresses in the \"Settings\" tab of each category." email_in_min_trust: "The minimum trust level a user needs to have to be allowed to post new topics via email." - email_in_category: "The category new emails are posted into." email_prefix: "The [label] used in the subject of emails. It will default to 'title' if not set." email_site_title: "The title of the site used as the sender of emails from the site. Default to 'title' if not set. If your 'title' contains characters that are not allowed in email sender strings, use this setting." diff --git a/docs/MAILING-LIST-SETUP.md b/docs/MAILING-LIST-SETUP.md index 25dd3394c6d..594abb0acf8 100644 --- a/docs/MAILING-LIST-SETUP.md +++ b/docs/MAILING-LIST-SETUP.md @@ -7,13 +7,13 @@ Acting like a Mailing list is disabled per default in Discourse. This guide show First of, you need a POP3s enabled server receiving your email. Then make sure to enable "reply_by_email_enabled" and configured the server appropriately in your Admin-Settings under "Email": ![enable-reply-by-email](https://f.cloud.github.com/assets/2879972/2242953/97d5dd52-9d17-11e3-915e-037758cc68a7.png) -Once that is in place, you can enable the "email_in"-feature globally in the same email-section. If you provide another "email_in_address" all emails arriving in the inbox to that address will be handeled and posted to the "email_in_category" (defaults to "uncategorised"). For spam protection only users of a high trust level can post via email per default. You can change this via the "email_in_min_trust" setting. +Once that is in place, you can enable the "email_in"-feature globally in the same email-section. ### Per category email address -Once "email_in" is enabled globally a new configuration option appears in your category settings dialog allowing you to specify an email-address for that category. Emails going to the previously configured inbox to that email-address will be posted in this category instead of the default configuration. **Attention** User-Permissions and the minimum trust levels still apply. +Once "email_in" is enabled globally a new configuration option appears in your category settings dialog allowing you to specify an email-address for that category. Emails going to the previously configured inbox to that email-address will be posted in this category. -Additionally, by checking the "accept non-user emails"-checkbox in the category settings, emails to the given email but from unknown email-addresses will be posted in the category by the System-User in a quoted fashion, showing the original email-address and content in the quotes. +For spam protection only users of a high trust level can post via email per default. You can change this via the "email_in_min_trust" setting. Additionally, by checking the "accept non-user emails"-checkbox in the category settings, emails to the given email but from unknown email-addresses will be posted in the category by the System-User in a quoted fashion, showing the original email-address and content in the quotes. ### Troubleshooting diff --git a/lib/email/receiver.rb b/lib/email/receiver.rb index 9fc25af104a..b452214f737 100644 --- a/lib/email/receiver.rb +++ b/lib/email/receiver.rb @@ -44,7 +44,7 @@ module Email end raise UserNotFoundError if @user.blank? - raise UserNotSufficientTrustLevelError.new @user unless @user.has_trust_level?(TrustLevel.levels[SiteSetting.email_in_min_trust.to_i]) + raise UserNotSufficientTrustLevelError.new @user unless @allow_strangers || @user.has_trust_level?(TrustLevel.levels[SiteSetting.email_in_min_trust.to_i]) create_new_topic else @@ -134,11 +134,7 @@ module Email def is_in_email? @allow_strangers = false - - if SiteSetting.email_in && SiteSetting.email_in_address == @message.to.first - @category_id = SiteSetting.email_in_category.to_i - return true - end + return false unless SiteSetting.email_in category = Category.find_by_email(@message.to.first) return false unless category diff --git a/spec/components/email/receiver_spec.rb b/spec/components/email/receiver_spec.rb index 9e0b6c29ce6..b1162a09b35 100644 --- a/spec/components/email/receiver_spec.rb +++ b/spec/components/email/receiver_spec.rb @@ -198,99 +198,8 @@ greatest show ever created. Everyone should watch it. end - describe "processes a valid incoming email" do - before do - SiteSetting.stubs(:email_in_address).returns("discourse-in@appmail.adventuretime.ooo") - SiteSetting.stubs(:email_in_category).returns("42") - SiteSetting.stubs(:email_in).returns(true) - end - - let(:incoming_email) { fixture_file("emails/valid_incoming.eml") } - let(:receiver) { Email::Receiver.new(incoming_email) } - let(:user) { Fabricate.build(:user, id: 3456) } - let(:subject) { "We should have a post-by-email-feature." } - let(:email_body) { -"Hey folks, - -I was thinking. Wouldn't it be great if we could post topics via email? Yes it would! - -Jakie" } - - describe "email from non user" do - - before do - User.expects(:find_by_email).returns(nil) - end - - it "raises user not found error" do - expect { receiver.process }.to raise_error(Email::Receiver::UserNotFoundError) - end - - end - - describe "email from untrusted user" do - before do - User.expects(:find_by_email).with( - "jake@adventuretime.ooo").returns(user) - SiteSetting.stubs(:email_in_min_trust).returns(TrustLevel.levels[:elder].to_s) - end - - it "raises untrusted user error" do - expect { receiver.process }.to raise_error(Email::Receiver::UserNotSufficientTrustLevelError) - end - - end - - describe "with proper user" do - - before do - SiteSetting.stubs(:email_in_min_trust).returns(TrustLevel.levels[:newuser].to_s) - User.expects(:find_by_email).with( - "jake@adventuretime.ooo").returns(user) - - topic_creator = mock() - TopicCreator.expects(:new).with(instance_of(User), - instance_of(Guardian), - has_entries(title: subject, - category: 42)) - .returns(topic_creator) - - topic_creator.expects(:create).returns(topic_creator) - topic_creator.expects(:id).twice.returns(12345) - - - post_creator = mock - PostCreator.expects(:new).with(instance_of(User), - has_entries(raw: email_body, - topic_id: 12345, - cooking_options: {traditional_markdown_linebreaks: true})) - .returns(post_creator) - - post_creator.expects(:create) - - EmailLog.expects(:create).with(has_entries( - email_type: 'topic_via_incoming_email', - to_address: "discourse-in@appmail.adventuretime.ooo", - user_id: 3456, - topic_id: 12345 - )) - end - - let!(:result) { receiver.process } - - it "extracts the body" do - expect(receiver.body).to eq(email_body) - end - - end - - end - - describe "processes an email to a category" do before do - SiteSetting.stubs(:email_in_address).returns("") - SiteSetting.stubs(:email_in_category).returns("42") SiteSetting.stubs(:email_in).returns(true) end @@ -398,8 +307,6 @@ Jakie" } describe "processes an unknown email sender to category" do before do - SiteSetting.stubs(:email_in_address).returns("") - SiteSetting.stubs(:email_in_category).returns("42") SiteSetting.stubs(:email_in).returns(true) end From 73ceeda1f9a4f46a45af1bed76b83f39ac5261f4 Mon Sep 17 00:00:00 2001 From: riking Date: Fri, 11 Jul 2014 15:12:15 -0700 Subject: [PATCH 3/5] Stop unnecessarily suppressing settings for uncategorized Fix migration for emailing into uncategorized --- .../discourse/templates/modal/edit-category.js.handlebars | 4 ++-- .../20140711193923_remove_email_in_address_setting.rb | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/discourse/templates/modal/edit-category.js.handlebars b/app/assets/javascripts/discourse/templates/modal/edit-category.js.handlebars index 6f1b67241b5..786de606f49 100644 --- a/app/assets/javascripts/discourse/templates/modal/edit-category.js.handlebars +++ b/app/assets/javascripts/discourse/templates/modal/edit-category.js.handlebars @@ -3,9 +3,9 @@ {{edit-category-tab selectedTab=selectedTab tab="general"}} {{#unless isUncategorizedCategory}} {{edit-category-tab selectedTab=selectedTab tab="security"}} - {{edit-category-tab selectedTab=selectedTab tab="settings"}} - {{edit-category-tab selectedTab=selectedTab tab="images"}} {{/unless}} + {{edit-category-tab selectedTab=selectedTab tab="settings"}} + {{edit-category-tab selectedTab=selectedTab tab="images"}}