Add List-Unsubscribe email header (#26085)
This commit is contained in:
parent
f2257069b2
commit
ca342d4838
5 changed files with 149 additions and 14 deletions
|
@ -9,6 +9,8 @@ class MailSubscriptionsController < ApplicationController
|
|||
before_action :set_user
|
||||
before_action :set_type
|
||||
|
||||
protect_from_forgery with: :null_session
|
||||
|
||||
def show; end
|
||||
|
||||
def create
|
||||
|
@ -20,6 +22,7 @@ class MailSubscriptionsController < ApplicationController
|
|||
|
||||
def set_user
|
||||
@user = GlobalID::Locator.locate_signed(params[:token], for: 'unsubscribe')
|
||||
not_found unless @user
|
||||
end
|
||||
|
||||
def set_body_classes
|
||||
|
@ -35,7 +38,7 @@ class MailSubscriptionsController < ApplicationController
|
|||
when 'follow', 'reblog', 'favourite', 'mention', 'follow_request'
|
||||
"notification_emails.#{params[:type]}"
|
||||
else
|
||||
raise ArgumentError
|
||||
not_found
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,6 +8,7 @@ class NotificationMailer < ApplicationMailer
|
|||
before_action :process_params
|
||||
before_action :set_status, only: [:mention, :favourite, :reblog]
|
||||
before_action :set_account, only: [:follow, :favourite, :reblog, :follow_request]
|
||||
after_action :set_list_headers!
|
||||
|
||||
default to: -> { email_address_with_name(@user.email, @me.username) }
|
||||
|
||||
|
@ -61,6 +62,7 @@ class NotificationMailer < ApplicationMailer
|
|||
@me = params[:recipient]
|
||||
@user = @me.user
|
||||
@type = action_name
|
||||
@unsubscribe_url = unsubscribe_url(token: @user.to_sgid(for: 'unsubscribe').to_s, type: @type)
|
||||
end
|
||||
|
||||
def set_status
|
||||
|
@ -71,6 +73,12 @@ class NotificationMailer < ApplicationMailer
|
|||
@account = @notification.from_account
|
||||
end
|
||||
|
||||
def set_list_headers!
|
||||
headers['List-ID'] = "<#{@type}.#{@me.username}.#{Rails.configuration.x.local_domain}>"
|
||||
headers['List-Unsubscribe'] = "<#{@unsubscribe_url}>"
|
||||
headers['List-Unsubscribe-Post'] = 'List-Unsubscribe=One-Click'
|
||||
end
|
||||
|
||||
def thread_by_conversation(conversation)
|
||||
return if conversation.nil?
|
||||
|
||||
|
|
|
@ -46,9 +46,9 @@
|
|||
%p= t 'about.hosted_on', domain: site_hostname
|
||||
%p
|
||||
= link_to t('application_mailer.notification_preferences'), settings_preferences_notifications_url
|
||||
- if defined?(@type)
|
||||
- if defined?(@unsubscribe_url)
|
||||
·
|
||||
= link_to t('application_mailer.unsubscribe'), unsubscribe_url(token: @user.to_sgid(for: 'unsubscribe').to_s, type: @type)
|
||||
= link_to t('application_mailer.unsubscribe'), @unsubscribe_url
|
||||
%td.column-cell.text-right
|
||||
= link_to root_url do
|
||||
= image_tag full_pack_url('media/images/mailer/logo.png'), alt: 'Mastodon', height: 24
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue