From 3d105fcfdbaacd5dcfd357859ac48b97dfec113b Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Wed, 31 Jan 2024 06:44:07 +0000 Subject: [PATCH] Keep gmail happy by allowing one click post unsubscribe --- app/mailers/alert_mailer.rb | 4 ++-- config/routes.rb | 1 + spec/mailers/alert_mailer_spec.rb | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/mailers/alert_mailer.rb b/app/mailers/alert_mailer.rb index fd4dfc6df..4924b7495 100644 --- a/app/mailers/alert_mailer.rb +++ b/app/mailers/alert_mailer.rb @@ -19,8 +19,8 @@ def alert(alert:, applications: [], comments: []) @comments = T.let(comments, T.nilable(T::Array[Comment])) headers( - # The List-Unsubscribe header appears not to be working in gmail anymore - # TODO: Figure out what's going on. Is it fixable? + # The unsubscribe URL needs to accept a post + "List-Unsubscribe-Post" => "List-Unsubscribe=One-Click", "List-Unsubscribe" => "<#{unsubscribe_alert_url(confirm_id: alert.confirm_id)}>", # This special header sets arbitrary metadata on the email in Cuttlefish # It's not sent on in the outgoing email diff --git a/config/routes.rb b/config/routes.rb index 3ae63846f..03b7c19fd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -96,6 +96,7 @@ def matches?(request) resources :alerts, only: %i[new create], path_names: { new: "signup" }, param: :confirm_id do member do get :unsubscribe + post :unsubscribe end end diff --git a/spec/mailers/alert_mailer_spec.rb b/spec/mailers/alert_mailer_spec.rb index 9699177f9..3c8e52d5a 100644 --- a/spec/mailers/alert_mailer_spec.rb +++ b/spec/mailers/alert_mailer_spec.rb @@ -56,6 +56,7 @@ it "has the unsubscribe header" do expect(email.header["List-Unsubscribe"].to_s).to eq("") + expect(email.header["List-Unsubscribe-Post"].to_s).to eq("List-Unsubscribe=One-Click") end end