FIX: ensure summary emails have the 'List-Unsubscribe' header set

This commit is contained in:
Régis Hanol 2016-07-15 11:39:29 +02:00
parent 9353013b40
commit 7848a84e0e
2 changed files with 11 additions and 7 deletions

View File

@ -90,9 +90,9 @@ class UserNotifications < ActionMailer::Base
def digest(user, opts={})
build_summary_for(user)
min_date = opts[:since] || @user.last_emailed_at || @user.last_seen_at || 1.month.ago
min_date = opts[:since] || user.last_emailed_at || user.last_seen_at || 1.month.ago
@last_seen_at = short_date(@user.last_seen_at || @user.created_at)
@last_seen_at = short_date(user.last_seen_at || user.created_at)
# A list of topics to show the user
@featured_topics = Topic.for_digest(user, min_date, limit: SiteSetting.digest_topics, top_order: true).to_a
@ -116,11 +116,14 @@ class UserNotifications < ActionMailer::Base
@featured_topics, @new_topics = @featured_topics[0..4], @featured_topics[5..-1]
build_email @user.email,
from_alias: I18n.t('user_notifications.digest.from', site_name: SiteSetting.title),
subject: I18n.t('user_notifications.digest.subject_template',
site_name: @site_name,
date: short_date(Time.now))
opts = {
from_alias: I18n.t('user_notifications.digest.from', site_name: SiteSetting.title),
subject: I18n.t('user_notifications.digest.subject_template', site_name: @site_name, date: short_date(Time.now)),
add_unsubscribe_link: true,
unsubscribe_url: "#{Discourse.base_url}/email/unsubscribe/#{@unsubscribe_key}",
}
build_email(user.email, opts)
end
end

View File

@ -164,6 +164,7 @@ describe UserNotifications do
expect(subject.from).to eq([SiteSetting.notification_email])
expect(subject.html_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
it "includes email_prefix in email subject instead of site title" do