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

Unsubscribe via email

This commit is contained in:
James Kiesel 2016-01-20 22:25:25 +13:00
parent 11ea16a91a
commit c7283751a3
13 changed files with 159 additions and 5 deletions

View file

@ -63,6 +63,13 @@ module Email
if @opts[:add_unsubscribe_link]
unsubscribe_link = PrettyText.cook(I18n.t('unsubscribe_link', template_args), sanitize: false).html_safe
html_override.gsub!("%{unsubscribe_link}", unsubscribe_link)
if SiteSetting.unsubscribe_via_email_footer && @opts[:add_unsubscribe_via_email_link]
unsubscribe_via_email_link = PrettyText.cook(I18n.t('unsubscribe_via_email_link', hostname: Discourse.current_hostname), sanitize: false).html_safe
html_override.gsub!("%{unsubscribe_via_email_link}", unsubscribe_via_email_link)
else
html_override.gsub!("%{unsubscribe_via_email_link}", "")
end
else
html_override.gsub!("%{unsubscribe_link}", "")
end
@ -103,6 +110,9 @@ module Email
if @opts[:add_unsubscribe_link]
body << "\n"
body << I18n.t('unsubscribe_link', template_args)
if SiteSetting.unsubscribe_via_email_footer && @opts[:add_unsubscribe_via_email_link]
body << I18n.t('unsubscribe_via_email_link', hostname: Discourse.current_hostname)
end
end
body

View file

@ -59,7 +59,10 @@ module Email
raise InactiveUserError if !user.active && !user.staged
if post = find_related_post
if action = subscription_action_for(body, @mail.subject)
message = SubscriptionMailer.send(action, user)
Email::Sender.new(message, :subscription).send
elsif post = find_related_post
create_reply(user: user, raw: body, post: post, topic: post.topic)
else
destination = destinations.first
@ -226,6 +229,13 @@ module Email
@likes ||= Set.new ["+1", I18n.t('post_action_types.like.title').downcase]
end
def subscription_action_for(body, subject)
return unless SiteSetting.unsubscribe_via_email
if ([subject, body].compact.map(&:to_s).map(&:downcase) & ['unsubscribe']).any?
:confirm_unsubscribe
end
end
def post_action_for(body)
if likes.include?(body.strip.downcase)
PostActionType.types[:like]