mirror of
https://github.com/discourse/discourse.git
synced 2024-12-14 04:03:42 +08:00
a6be4972a8
When we build and send emails using MessageBuilder and Email::Sender we add custom headers defined in SiteSetting.email_custom_headers. However this was causing errors in cases where the custom headers defined a header that we already specify in outbound emails (e.g. the Precedence: list header for topic/post emails). This commit makes it so we always use the header value defined in Discourse core if there is a duplicate, discarding the custom header value from the site setting. cf. https://meta.discourse.org/t/email-notifications-fail-if-duplicate-headers-exist/222960/14
30 lines
1.1 KiB
Ruby
30 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# We already have Email::Sender and Email::MessageBuilder specs along
|
|
# with mailer specific mailer specs like UserEmail, but sometimes we need
|
|
# to test things along the whole outbound flow including the MessageBuilder
|
|
# and the Sender.
|
|
describe "Outbound Email" do
|
|
def send_email(opts = {})
|
|
message = TestMailer.send_test("test@test.com", opts)
|
|
result = Email::Sender.new(message, :test_message).send
|
|
[message, result]
|
|
end
|
|
|
|
context "email custom headers" do
|
|
it "discards the custom header if it is one that has already been set based on arguments" do
|
|
SiteSetting.email_custom_headers = "Precedence: bulk"
|
|
post = Fabricate(:post)
|
|
message, result = send_email(post_id: post.id, topic_id: post.topic_id)
|
|
expect(message.header["Precedence"].value).to eq("list")
|
|
end
|
|
|
|
it "does send unique custom headers" do
|
|
SiteSetting.email_custom_headers = "SuperUrgent: wow-cool"
|
|
post = Fabricate(:post)
|
|
message, result = send_email(post_id: post.id, topic_id: post.topic_id)
|
|
expect(message.header["SuperUrgent"].value).to eq("wow-cool")
|
|
end
|
|
end
|
|
end
|