mirror of
https://github.com/discourse/discourse.git
synced 2025-03-24 06:42:37 +08:00
Add custom headers for email messages
See http://meta.discourse.org/t/custom-headers-in-emails-site-settings/7480
This commit is contained in:
parent
337f393af5
commit
4e04c4dddd
app/models
config/locales
lib/email
spec/components/email
@ -129,6 +129,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, 'Precedence: bulk|Auto-Submitted: auto-generated')
|
||||||
|
|
||||||
setting(:allow_index_in_robots_txt, true)
|
setting(:allow_index_in_robots_txt, true)
|
||||||
|
|
||||||
|
@ -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"
|
||||||
|
@ -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
|
||||||
|
}
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -75,6 +75,17 @@ 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
|
||||||
|
|
||||||
|
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,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user