mailkick 1.2.1 → 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: 1c9afb6da6d15f00f76bb8a7845e9d2df1bb32a913a0fa322542a5ddfe1b043e
4
- data.tar.gz: 99c7f94c67e663efa0cdf66cb3d62dff7dc89b214524696bd1e0ee50d43a3ffb
3
+ metadata.gz: f9cc5e031a75a29b20c985acb8b16922338dab5e65a1df97818facd9a94c75e3
4
+ data.tar.gz: 433257564c2918ad55eeb41efc5219e86720d2d29bca3808ff084ba76a085524
5
5
  SHA512:
6
- metadata.gz: dc3f3beb97c4d4a93bc9776318a1052b8954878fc4a971ca7bca813b936baf9198140e4f4b562e505405ce819a77547873bd0ae2375bb663a53d155208868bef
7
- data.tar.gz: a0ce5ec53014a34326743d3331c5d43748a922fd1d0bc1bc84c65b26371e524d64f2e6f0e88a47d58dc2a946722a21cab8fc6ae96c8170e4cbbb10639aa875ec
6
+ metadata.gz: 1c28e41447543e5498ca2f91fa66e1e0cf1dce16160d76d73b883be236f8a5d36091c2e768d3f5668702a371759891e1a3a5187f4a440cb35b313f9021734908
7
+ data.tar.gz: 1fe58111dc7a26644d68a425be18824a660cf16c4305207c8b63ae8916609381d376a72bd449b4e21b02fe1541e571a210b0086d7947b764e619ed67a3f8a5dd
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 1.3.0 (2024-01-18)
2
+
3
+ - Added support for one-click unsubscribe headers (RFC 8058)
4
+
5
+ ## 1.2.2 (2023-10-30)
6
+
7
+ - Fixed error when secret key base set with `SECRET_KEY_BASE_DUMMY`
8
+
1
9
  ## 1.2.1 (2023-07-24)
2
10
 
3
11
  - Fixed issue with inheritance
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
@@ -20,7 +20,7 @@ module Mailkick
20
20
  end
21
21
 
22
22
  token = creds.respond_to?(:secret_key_base) ? creds.secret_key_base : creds.secret_token
23
- Mailkick.message_verifier.rotate(token, serializer: Marshal)
23
+ Mailkick.message_verifier.rotate(token, serializer: Marshal) if token
24
24
  end
25
25
  end
26
26
  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.1"
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.1
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-07-25 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