Fix it so that emails are (hopefully) able to show the one-click unsubscribe button in Gmail and other mail providers that support the List-Unsubscribe header. This way users can unsubscribe instead of marking emails as spam. * Add the List-Unsubscribe-Post header. * Fix the disable email notifications endpoint to support POST as well as DELETE requests. * Fix the disable email notifications endpoint to disable XSRF protection (we don't need users to be logged in because we use a signed URL instead). https://www.rfc-editor.org/rfc/rfc8058#section-3.1 https://www.rfc-editor.org/rfc/rfc8058#section-8.1
27 lines
1.1 KiB
Ruby
27 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# The base class for emails sent by Danbooru.
|
|
#
|
|
# @see https://guides.rubyonrails.org/action_mailer_basics.html
|
|
class ApplicationMailer < ActionMailer::Base
|
|
helper :application
|
|
helper :users
|
|
include UsersHelper
|
|
|
|
default from: "#{Danbooru.config.canonical_app_name} <#{Danbooru.config.contact_email}>", content_type: "text/html"
|
|
|
|
def mail(user, require_verified_email:, **options)
|
|
# https://www.rfc-editor.org/rfc/rfc8058#section-3.1
|
|
#
|
|
# A mail receiver can do a one-click unsubscription by performing an HTTPS POST to the HTTPS URI in the
|
|
# List-Unsubscribe header. It sends the key/value pair in the List-Unsubscribe-Post header as the request body.
|
|
# The List-Unsubscribe-Post header MUST contain the single key/value pair "List-Unsubscribe=One-Click".
|
|
headers["List-Unsubscribe"] = "<#{disable_email_notifications_url(user)}>"
|
|
headers["List-Unsubscribe-Post"] = "List-Unsubscribe=One-Click"
|
|
|
|
message = super(to: user.email_address&.address, **options)
|
|
message.perform_deliveries = user.can_receive_email?(require_verified_email: require_verified_email)
|
|
message
|
|
end
|
|
end
|