mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 15:28:37 +08:00
Adds a List-Id header to outgoing mail
This commit is contained in:
@ -7,6 +7,7 @@
|
||||
# It also adds an HTML part for the plain text body
|
||||
#
|
||||
require_dependency 'email/renderer'
|
||||
require 'uri'
|
||||
|
||||
module Email
|
||||
class Sender
|
||||
@ -45,6 +46,9 @@ module Email
|
||||
to_address: to_address,
|
||||
user_id: @user.try(:id))
|
||||
|
||||
|
||||
@message.header['List-Id'] = Email::Sender.list_id_for(SiteSetting.title, Discourse.base_url)
|
||||
|
||||
add_header_to_log('X-Discourse-Reply-Key', email_log, :reply_key)
|
||||
add_header_to_log('X-Discourse-Post-Id', email_log, :post_id)
|
||||
add_header_to_log('X-Discourse-Topic-Id', email_log, :topic_id)
|
||||
@ -62,6 +66,20 @@ module Email
|
||||
|
||||
end
|
||||
|
||||
def self.list_id_for(site_name, base_url)
|
||||
|
||||
host = "localhost"
|
||||
if base_url.present?
|
||||
begin
|
||||
uri = URI.parse(base_url)
|
||||
host = uri.host.downcase if uri.host.present?
|
||||
rescue URI::InvalidURIError
|
||||
end
|
||||
end
|
||||
|
||||
"\"#{site_name.gsub(/\"/, "'")}\" <#{Slug.for(site_name)}.#{host}>"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def add_header_to_log(name, email_log, email_log_field)
|
||||
|
Reference in New Issue
Block a user