Merge pull request #1157 from abbat/email-custom-headers

Add custom headers for email messages
This commit is contained in:
Robin Ward 2013-07-10 07:12:51 -07:00
commit cc47616cdb
4 changed files with 34 additions and 0 deletions

View file

@ -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 # 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(:notification_email, 'info@discourse.org')
setting(:email_custom_headers, 'Auto-Submitted: auto-generated')
setting(:allow_index_in_robots_txt, true) setting(:allow_index_in_robots_txt, true)

View file

@ -477,6 +477,7 @@ en:
apple_touch_icon_url: "Icon used for Apple touch devices. Recommended size is 144px by 144px." 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" 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)" 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_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" best_of_posts_required: "Minimum posts in a topic before 'best of' mode is enabled"

View file

@ -75,6 +75,19 @@ module Email
result['Reply-To'] = from_value result['Reply-To'] = from_value
end 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 result
end end

View file

@ -75,6 +75,25 @@ describe Email::MessageBuilder do
end 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 context "header args" do
let(:message_with_header_args) { Email::MessageBuilder.new(to_address, let(:message_with_header_args) { Email::MessageBuilder.new(to_address,