Use headers shorthand in mailers (#31956)

This commit is contained in:
Matt Jankowski 2024-09-19 09:38:32 -04:00 committed by GitHub
parent 6801afa12f
commit 2946a9286b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 26 additions and 18 deletions

View file

@ -56,9 +56,11 @@ class AdminMailer < ApplicationMailer
def new_critical_software_updates def new_critical_software_updates
@software_updates = SoftwareUpdate.where(urgent: true).to_a.sort_by(&:gem_version) @software_updates = SoftwareUpdate.where(urgent: true).to_a.sort_by(&:gem_version)
headers['Priority'] = 'urgent' headers(
headers['X-Priority'] = '1' 'Importance' => 'high',
headers['Importance'] = 'high' 'Priority' => 'urgent',
'X-Priority' => '1'
)
locale_for_account(@me) do locale_for_account(@me) do
mail subject: default_i18n_subject(instance: @instance) mail subject: default_i18n_subject(instance: @instance)

View file

@ -16,8 +16,10 @@ class ApplicationMailer < ActionMailer::Base
end end
def set_autoreply_headers! def set_autoreply_headers!
headers['Precedence'] = 'list' headers(
headers['X-Auto-Response-Suppress'] = 'All' 'Auto-Submitted' => 'auto-generated',
headers['Auto-Submitted'] = 'auto-generated' 'Precedence' => 'list',
'X-Auto-Response-Suppress' => 'All'
)
end end
end end

View file

@ -6,7 +6,10 @@ class NotificationMailer < ApplicationMailer
:routing :routing
before_action :process_params before_action :process_params
before_action :set_status, only: [:mention, :favourite, :reblog] with_options only: %i(mention favourite reblog) do
before_action :set_status
after_action :thread_by_conversation!
end
before_action :set_account, only: [:follow, :favourite, :reblog, :follow_request] before_action :set_account, only: [:follow, :favourite, :reblog, :follow_request]
after_action :set_list_headers! after_action :set_list_headers!
@ -18,7 +21,6 @@ class NotificationMailer < ApplicationMailer
return unless @user.functional? && @status.present? return unless @user.functional? && @status.present?
locale_for_account(@me) do locale_for_account(@me) do
thread_by_conversation(@status.conversation)
mail subject: default_i18n_subject(name: @status.account.acct) mail subject: default_i18n_subject(name: @status.account.acct)
end end
end end
@ -35,7 +37,6 @@ class NotificationMailer < ApplicationMailer
return unless @user.functional? && @status.present? return unless @user.functional? && @status.present?
locale_for_account(@me) do locale_for_account(@me) do
thread_by_conversation(@status.conversation)
mail subject: default_i18n_subject(name: @account.acct) mail subject: default_i18n_subject(name: @account.acct)
end end
end end
@ -44,7 +45,6 @@ class NotificationMailer < ApplicationMailer
return unless @user.functional? && @status.present? return unless @user.functional? && @status.present?
locale_for_account(@me) do locale_for_account(@me) do
thread_by_conversation(@status.conversation)
mail subject: default_i18n_subject(name: @account.acct) mail subject: default_i18n_subject(name: @account.acct)
end end
end end
@ -76,17 +76,21 @@ class NotificationMailer < ApplicationMailer
end end
def set_list_headers! def set_list_headers!
headers['List-ID'] = "<#{@type}.#{@me.username}.#{Rails.configuration.x.local_domain}>" headers(
headers['List-Unsubscribe'] = "<#{@unsubscribe_url}>" 'List-ID' => "<#{@type}.#{@me.username}.#{Rails.configuration.x.local_domain}>",
headers['List-Unsubscribe-Post'] = 'List-Unsubscribe=One-Click' 'List-Unsubscribe-Post' => 'List-Unsubscribe=One-Click',
'List-Unsubscribe' => "<#{@unsubscribe_url}>"
)
end end
def thread_by_conversation(conversation) def thread_by_conversation!
return if conversation.nil? return if @status.conversation.nil?
msg_id = "<conversation-#{conversation.id}.#{conversation.created_at.strftime('%Y-%m-%d')}@#{Rails.configuration.x.local_domain}>" conversation_message_id = "<conversation-#{@status.conversation.id}.#{@status.conversation.created_at.to_date}@#{Rails.configuration.x.local_domain}>"
headers['In-Reply-To'] = msg_id headers(
headers['References'] = msg_id 'In-Reply-To' => conversation_message_id,
'References' => conversation_message_id
)
end end
end end