FIX: 'List-Unsubscribe' header wasn't added to emails sent when mailing_list_mode was enabled

This commit is contained in:
Régis Hanol 2016-08-01 20:19:00 +02:00
parent 5b270b6b06
commit 829143bf88
2 changed files with 8 additions and 4 deletions

View file

@ -83,9 +83,14 @@ class UserNotifications < ActionMailer::Base
return unless @posts_by_topic.present? return unless @posts_by_topic.present?
build_summary_for(user) build_summary_for(user)
apply_notification_styles build_email @user.email, opts = {
from_alias: I18n.t('user_notifications.mailing_list.from', site_name: SiteSetting.title), from_alias: I18n.t('user_notifications.mailing_list.from', site_name: SiteSetting.title),
subject: I18n.t('user_notifications.mailing_list.subject_template', site_name: @site_name, date: @date) subject: I18n.t('user_notifications.mailing_list.subject_template', site_name: @site_name, date: @date),
mailing_list_mode: true,
add_unsubscribe_link: true,
unsubscribe_url: "#{Discourse.base_url}/email/unsubscribe/#{@unsubscribe_key}",
}
apply_notification_styles(build_email(@user.email, opts))
end end
def digest(user, opts={}) def digest(user, opts={})
@ -236,7 +241,6 @@ class UserNotifications < ActionMailer::Base
end end
def self.get_context_posts(post, topic_user, user) def self.get_context_posts(post, topic_user, user)
if user.user_option.email_previous_replies == UserOption.previous_replies_type[:never] if user.user_option.email_previous_replies == UserOption.previous_replies_type[:never]
return [] return []
end end
@ -376,7 +380,6 @@ class UserNotifications < ActionMailer::Base
template << "_staged" if user.staged? template << "_staged" if user.staged?
end end
email_opts = { email_opts = {
topic_title: title, topic_title: title,
message: message, message: message,

View file

@ -100,6 +100,7 @@ describe UserNotifications do
expect(subject.from).to eq([SiteSetting.notification_email]) expect(subject.from).to eq([SiteSetting.notification_email])
expect(subject.html_part.body.to_s).to include topic.title expect(subject.html_part.body.to_s).to include topic.title
expect(subject.text_part.body.to_s).to be_present expect(subject.text_part.body.to_s).to be_present
expect(subject.header["List-Unsubscribe"].to_s).to match(/\/email\/unsubscribe\/\h{64}/)
end end
it "includes posts less than 24 hours old" do it "includes posts less than 24 hours old" do