mailkick 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1c69391f60c043d1a2ad07d45adf6dd4dcfdfae381570e4e5c6ccc81df0d2ae6
4
- data.tar.gz: 18f7747bed0cfd2a802b0ef8464a0d25696acc873c86f2784242c9ff9a8d2db7
3
+ metadata.gz: f9cc5e031a75a29b20c985acb8b16922338dab5e65a1df97818facd9a94c75e3
4
+ data.tar.gz: 433257564c2918ad55eeb41efc5219e86720d2d29bca3808ff084ba76a085524
5
5
  SHA512:
6
- metadata.gz: 39166cce458a3949b88ed4ebc27d49da862039830495693e955a78a7364a8ac5410d6fe4a24f6ba62de6d222e23c13f3920debab9f071223bafae0b57741c1f2
7
- data.tar.gz: 5038361e264b4d953d87d6427ef04832ac3dc724dc4f5bb9c9e8a9631e573f2baa2a5c114dd3dc343e7c655cedf3371d3f9187c3785204be895b2a020c6806df
6
+ metadata.gz: 1c28e41447543e5498ca2f91fa66e1e0cf1dce16160d76d73b883be236f8a5d36091c2e768d3f5668702a371759891e1a3a5187f4a440cb35b313f9021734908
7
+ data.tar.gz: 1fe58111dc7a26644d68a425be18824a660cf16c4305207c8b63ae8916609381d376a72bd449b4e21b02fe1541e571a210b0086d7947b764e619ed67a3f8a5dd
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.3.0 (2024-01-18)
2
+
3
+ - Added support for one-click unsubscribe headers (RFC 8058)
4
+
1
5
  ## 1.2.2 (2023-10-30)
2
6
 
3
7
  - Fixed error when secret key base set with `SECRET_KEY_BASE_DUMMY`
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Email subscriptions for Rails
4
4
 
5
- - Add one-click unsubscribe links to your emails
5
+ - Add one-click unsubscribe links and headers to your emails
6
6
  - Fetch bounces and spam reports from your email service
7
7
 
8
8
  :postbox: Check out [Ahoy Email](https://github.com/ankane/ahoy_email) for analytics
@@ -81,6 +81,16 @@ rails generate mailkick:views
81
81
 
82
82
  which copies the view into `app/views/mailkick`.
83
83
 
84
+ ## Unsubscribe Headers
85
+
86
+ For one-click unsubscribe headers ([RFC 8058](https://datatracker.ietf.org/doc/html/rfc8058)), create `config/initializers/mailkick.rb` with:
87
+
88
+ ```ruby
89
+ Mailkick.headers = true
90
+ ```
91
+
92
+ Headers will automatically be added to emails that call `mailkick_unsubscribe_url`.
93
+
84
94
  ## Bounces and Spam Reports
85
95
 
86
96
  Fetch bounces, spam reports, and unsubscribes from your email service. Create `config/initializers/mailkick.rb` with a method to handle opt outs.
@@ -1,6 +1,7 @@
1
1
  module Mailkick
2
2
  class SubscriptionsController < ActionController::Base
3
3
  protect_from_forgery with: :exception
4
+ skip_forgery_protection only: [:unsubscribe]
4
5
 
5
6
  before_action :set_subscription
6
7
 
@@ -12,7 +13,13 @@ module Mailkick
12
13
 
13
14
  Mailkick::Legacy.opt_out(legacy_options) if Mailkick::Legacy.opt_outs?
14
15
 
15
- redirect_to subscription_path(params[:id])
16
+ if request.post? && params["List-Unsubscribe"] == "One-Click"
17
+ # must not redirect according to RFC 8058
18
+ # could render show action instead
19
+ render plain: "Unsubscribe successful"
20
+ else
21
+ redirect_to subscription_path(params[:id])
22
+ end
16
23
  end
17
24
 
18
25
  def subscribe
data/config/routes.rb CHANGED
@@ -6,7 +6,7 @@ end
6
6
 
7
7
  Mailkick::Engine.routes.draw do
8
8
  resources :subscriptions, only: [:show] do
9
- get :unsubscribe, on: :member
9
+ match :unsubscribe, on: :member, via: [:get, :post]
10
10
  get :subscribe, on: :member
11
11
  end
12
12
  end
@@ -2,7 +2,12 @@ module Mailkick
2
2
  module UrlHelper
3
3
  def mailkick_unsubscribe_url(subscriber, list, **options)
4
4
  token = Mailkick.generate_token(subscriber, list)
5
- mailkick.unsubscribe_subscription_url(token, **options)
5
+ url = mailkick.unsubscribe_subscription_url(token, **options)
6
+ if Mailkick.headers && headers["List-Unsubscribe"].nil?
7
+ headers["List-Unsubscribe-Post"] ||= "List-Unsubscribe=One-Click"
8
+ headers["List-Unsubscribe"] = "<#{url}>"
9
+ end
10
+ url
6
11
  end
7
12
  end
8
13
  end
@@ -1,3 +1,3 @@
1
1
  module Mailkick
2
- VERSION = "1.2.2"
2
+ VERSION = "1.3.0"
3
3
  end
data/lib/mailkick.rb CHANGED
@@ -24,12 +24,13 @@ require_relative "mailkick/version"
24
24
  require_relative "mailkick/engine" if defined?(Rails)
25
25
 
26
26
  module Mailkick
27
- mattr_accessor :services, :mount, :process_opt_outs_method
27
+ mattr_accessor :services, :mount, :process_opt_outs_method, :headers
28
28
  mattr_reader :secret_token
29
29
  mattr_writer :message_verifier
30
30
  self.services = []
31
31
  self.mount = true
32
32
  self.process_opt_outs_method = ->(_) { raise "process_opt_outs_method not defined" }
33
+ self.headers = false
33
34
 
34
35
  def self.fetch_opt_outs
35
36
  services.each(&:fetch_opt_outs)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailkick
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-30 00:00:00.000000000 Z
11
+ date: 2024-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  - !ruby/object:Gem::Version
76
76
  version: '0'
77
77
  requirements: []
78
- rubygems_version: 3.4.10
78
+ rubygems_version: 3.5.3
79
79
  signing_key:
80
80
  specification_version: 4
81
81
  summary: Email subscriptions for Rails