2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-05 08:59:27 +08:00

The EmailBuilder now creates the Reply by Email Key if necessary.

This commit is contained in:
Robin Ward 2013-06-13 10:56:16 -04:00
parent cf9b6beb13
commit 49c09898e2
8 changed files with 77 additions and 100 deletions

View file

@ -35,6 +35,10 @@ module Email
body
end
def allow_reply_by_email?
SiteSetting.reply_by_email_enabled? && @opts[:allow_reply_by_email]
end
def template_args
@template_args ||= { site_name: SiteSetting.title,
base_url: Discourse.base_url,
@ -60,6 +64,9 @@ module Email
if @opts[:add_unsubscribe_link]
result['List-Unsubscribe'] = "<#{template_args[:user_preferences_url]}>" if @opts[:add_unsubscribe_link]
end
result['Discourse-Reply-Key'] = SecureRandom.hex(16) if allow_reply_by_email?
result
end

View file

@ -42,7 +42,13 @@ module Email
to_address = @message.to
to_address = to_address.first if to_address.is_a?(Array)
EmailLog.create!(email_type: @email_type, to_address: to_address, user_id: @user.try(:id))
email_log = EmailLog.new(email_type: @email_type, to_address: to_address, user_id: @user.try(:id))
reply_key = @message.header['Discourse-Reply-Key'].to_s
email_log.reply_key = reply_key if reply_key.present?
email_log.save!
email_log
end
end