mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Use our header value instead of custom header on duplicates (#16711)
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
This commit is contained in:
29
spec/integration/email_outbound_spec.rb
Normal file
29
spec/integration/email_outbound_spec.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
# 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
|
||||
Reference in New Issue
Block a user