FIX: Strip Auto-Submitted email header from group SMTP emails (#15057)

Remove Auto-Submitted header for group private message emails, it does
not make sense there and may hurt deliverability.

From https://www.iana.org/assignments/auto-submitted-keywords/auto-submitted-keywords.xhtml:

> Indicates that a message was generated by an automatic process, and is not a direct response to another message.
This commit is contained in:
Martin Brennan 2021-11-24 10:54:01 +10:00 committed by GitHub
parent d40e56272f
commit 44be79f095
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -213,9 +213,20 @@ module Email
@message.header[Email::MessageBuilder::ALLOW_REPLY_BY_EMAIL_HEADER] = nil
end
# Replace reply_key in custom headers or remove
MessageBuilder.custom_headers(SiteSetting.email_custom_headers).each do |key, _|
value = header_value(key)
# Remove Auto-Submitted header for group private message emails, it does
# not make sense there and may hurt deliverability.
#
# From https://www.iana.org/assignments/auto-submitted-keywords/auto-submitted-keywords.xhtml:
#
# > Indicates that a message was generated by an automatic process, and is not a direct response to another message.
if key.downcase == "auto-submitted" && smtp_group_id
@message.header[key] = nil
end
# Replace reply_key in custom headers or remove
if value&.include?('%{reply_key}')
# Delete old header first or else the same header will be added twice
@message.header[key] = nil

View File

@ -414,6 +414,13 @@ describe Email::Sender do
expect(message.header['Precedence']).to eq(nil)
expect(message.header['List-Unsubscribe']).to eq(nil)
end
it "removes the Auto-Submitted header" do
TopicAllowedGroup.create!(topic: post.topic, group: group)
email_sender.send
expect(message.header['Auto-Submitted']).to eq(nil)
end
end
end