mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 13:51:09 +08:00
FIX: Add random suffix to outbound Message-ID for email (#15179)
Currently the Message-IDs we send out for outbound email are not unique; for a post they look like: topic/TOPIC_ID/POST_ID@HOST And for a topic they look like: topic/TOPIC_ID@HOST This commit changes the outbound Message-IDs to also have a random suffix before the host, so the new format is like this: topic/TOPIC_ID/POST_ID.RANDOM_SUFFIX@HOST Or: topic/TOPIC_ID.RANDOM_SUFFIX@HOST This should help with email deliverability. This change is backwards-compatible, the old Message-ID format will still be recognized in the mail receiver flow, so people will still be able to reply using Message-IDs, In-Reply-To, and References headers that have already been sent. This commit also refactors Message-ID related logic to a central location, and adds judicious amounts of tests and documentation.
This commit is contained in:
13
lib/email.rb
13
lib/email.rb
@ -52,21 +52,8 @@ module Email
|
||||
SiteSetting.email_site_title.presence || SiteSetting.title
|
||||
end
|
||||
|
||||
# https://tools.ietf.org/html/rfc850#section-2.1.7
|
||||
def self.message_id_rfc_format(message_id)
|
||||
message_id.present? && !is_message_id_rfc?(message_id) ? "<#{message_id}>" : message_id
|
||||
end
|
||||
|
||||
def self.message_id_clean(message_id)
|
||||
message_id.present? && is_message_id_rfc?(message_id) ? message_id.gsub(/^<|>$/, "") : message_id
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.is_message_id_rfc?(message_id)
|
||||
message_id.start_with?('<') && message_id.include?('@') && message_id.end_with?('>')
|
||||
end
|
||||
|
||||
def self.obfuscate_part(part)
|
||||
if part.size < 3
|
||||
"*" * part.size
|
||||
|
Reference in New Issue
Block a user