diff --git a/app/models/site_setting.rb b/app/models/site_setting.rb index 6396179a492..0bcbe1f7808 100644 --- a/app/models/site_setting.rb +++ b/app/models/site_setting.rb @@ -130,6 +130,7 @@ class SiteSetting < ActiveRecord::Base # we need to think of a way to force users to enter certain settings, this is a minimal config thing setting(:notification_email, 'info@discourse.org') + setting(:email_custom_headers, 'Auto-Submitted: auto-generated') setting(:allow_index_in_robots_txt, true) diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 9edfc8ad0be..dfae8d8f225 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -477,6 +477,7 @@ en: apple_touch_icon_url: "Icon used for Apple touch devices. Recommended size is 144px by 144px." notification_email: "The return email address used when sending system emails such as notifying users of lost passwords, new accounts etc" + email_custom_headers: "A pipe-delimited list of custom email headers" use_ssl: "Should the site be accessible via SSL? (NOT IMPLEMENTED, EXPERIMENTAL)" best_of_score_threshold: "The minimum score of a post to be included in the 'best of'" best_of_posts_required: "Minimum posts in a topic before 'best of' mode is enabled" diff --git a/lib/email/message_builder.rb b/lib/email/message_builder.rb index 10bc3f21dfb..3d0687ee0f4 100644 --- a/lib/email/message_builder.rb +++ b/lib/email/message_builder.rb @@ -75,6 +75,19 @@ module Email result['Reply-To'] = from_value end + result.merge(MessageBuilder.custom_headers(SiteSetting.email_custom_headers)) + end + + def self.custom_headers(string) + result = {} + string.split('|').each { |item| + header = item.split(':', 2) + if header.length == 2 + name = header[0].strip + value = header[1].strip + result[name] = value if name.length > 0 && value.length > 0 + end + } unless string.nil? result end diff --git a/spec/components/email/message_builder_spec.rb b/spec/components/email/message_builder_spec.rb index 944100893a0..3e1310e63a3 100644 --- a/spec/components/email/message_builder_spec.rb +++ b/spec/components/email/message_builder_spec.rb @@ -75,6 +75,25 @@ describe Email::MessageBuilder do end + context "custom headers" do + + let(:custom_headers_string) { " Precedence : bulk | :: | No-colon | No-Value: | Multi-colon : : value : : | Auto-Submitted : auto-generated " } + let(:custom_headers_result) { { "Precedence" => "bulk", "Multi-colon" => ": value : :", "Auto-Submitted" => "auto-generated" } } + + it "custom headers builder" do + expect(Email::MessageBuilder.custom_headers(custom_headers_string)).to eq(custom_headers_result) + end + + it "empty headers builder" do + expect(Email::MessageBuilder.custom_headers("")).to eq({}) + end + + it "null headers builder" do + expect(Email::MessageBuilder.custom_headers(nil)).to eq({}) + end + + end + context "header args" do let(:message_with_header_args) { Email::MessageBuilder.new(to_address,