FIX: Remove List-Post email header (#14554)

* FIX: Remove List-Post email header

This header is used for mailing lists and can confuse some email clients
such as Thunderbird to display wrong replying options.

* FIX: Replace reply_key in email custom headers

Admins can add custom email headers from site settings. Email sender
will try to replace the reply key if %{reply_key} exists or remove the
header if a reply key does not exist.
This commit is contained in:
Bianca Nenciu
2021-10-11 20:57:42 +03:00
committed by GitHub
parent 8b99a7f73d
commit 79e55ec3f0
2 changed files with 52 additions and 11 deletions

View File

@ -102,7 +102,7 @@ module Email
post_id = header_value('X-Discourse-Post-Id')
topic_id = header_value('X-Discourse-Topic-Id')
reply_key = set_reply_key(post_id, user_id)
reply_key = get_reply_key(post_id, user_id)
from_address = @message.from&.first
smtp_group_id = from_address.blank? ? nil : Group.where(
email_username: from_address, smtp_enabled: true
@ -192,11 +192,6 @@ module Email
end
end
if reply_key.present? && @message.header['Reply-To'].to_s =~ /\<([^\>]+)\>/ && !smtp_group_id
email = Regexp.last_match[1]
@message.header['List-Post'] = "<mailto:#{email}>"
end
if Email::Sender.bounceable_reply_address?
email_log.bounce_key = SecureRandom.hex
@ -214,9 +209,22 @@ module Email
@message.header['X-Discourse-Post-Id'] = nil if post_id.present?
if reply_key.present?
@message.header['Reply-To'] = header_value('Reply-To').gsub!("%{reply_key}", reply_key)
@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)
if value&.include?('%{reply_key}')
# Delete old header first or else the same header will be added twice
@message.header[key] = nil
if reply_key.present?
@message.header[key] = value.gsub!('%{reply_key}', reply_key)
end
end
end
# pass the original message_id when using mailjet/mandrill/sparkpost
case ActionMailer::Base.smtp_settings[:address]
when /\.mailjet\.com/
@ -430,7 +438,7 @@ module Email
@message.header[name] = data.to_json
end
def set_reply_key(post_id, user_id)
def get_reply_key(post_id, user_id)
# ALLOW_REPLY_BY_EMAIL_HEADER is only added if we are _not_ sending
# via group SMTP and if reply by email site settings are configured
return if !user_id || !post_id || !header_value(Email::MessageBuilder::ALLOW_REPLY_BY_EMAIL_HEADER).present?
@ -440,9 +448,6 @@ module Email
post_id: post_id,
user_id: user_id
).reply_key
@message.header['Reply-To'] =
header_value('Reply-To').gsub!("%{reply_key}", reply_key)
end
def self.bounceable_reply_address?