mailkick 0.2.1 → 0.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
- SHA1:
3
- metadata.gz: 71a67112599c83fefbdd086151fcf834a24c217f
4
- data.tar.gz: 609f546b4a4f6a3dc7a5878cb2e0bd2d344e1a97
2
+ SHA256:
3
+ metadata.gz: 7342fb3956753b14f1345a70153ac76cc6cc73290a7b4c1d9e3f9a1b29e6a216
4
+ data.tar.gz: 06a13e7037c2ab1ffcab78f93f7a99272aa00b59f3388878ad10498d7ed73e70
5
5
  SHA512:
6
- metadata.gz: 8d0392c53613b8580030f0b57c9b953cf4863d746200d92a2662abb16fd677017426cc4809ac122244b2d0facc92deb1ee021e191c1181f629179791404155b9
7
- data.tar.gz: 99df02fda98d46cbf4cb1ed07c52f73f62f0f54e87e59e23146cc1250efb40c7e13138b810644c6d13735fde036c506063ec7dc80834cb6b6f863df989e1c600
6
+ metadata.gz: 2d0a3d927fee65871caf6b37d79e83663e45c382396e941e03651ec36de13e19680107f9582e4e9010f65454361d32e16b77787d8e0657857029ff05b3e2e510
7
+ data.tar.gz: 72698be727b60185179d2004af23531cf3812fabf6e68a8ad0d4da4b0119804bc3591dd60aa1f7a5c92b1d3d0c896f5329572a6e331985724f00c8778abb6623
data/.gitignore CHANGED
@@ -20,3 +20,5 @@ tmp
20
20
  *.o
21
21
  *.a
22
22
  mkmf.log
23
+ *.log
24
+ *.sqlite
data/.travis.yml ADDED
@@ -0,0 +1,16 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.4.2
4
+ sudo: false
5
+ script: bundle exec rake test
6
+ before_script:
7
+ - gem install bundler
8
+ notifications:
9
+ email:
10
+ on_success: never
11
+ on_failure: change
12
+ gemfile:
13
+ - Gemfile
14
+ - test/gemfiles/actionmailer51.gemfile
15
+ - test/gemfiles/actionmailer50.gemfile
16
+ - test/gemfiles/actionmailer42.gemfile
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.3.0
2
+
3
+ - Improved performance
4
+ - Fixed `Subscription not found` for Rails 5.2
5
+ - Use `references` in migration
6
+ - Use `smtp_settings[:domain]` for Mailgun
7
+ - Dropped support for ActionMailer < 4.2
8
+
1
9
  ## 0.2.1
2
10
 
3
11
  - Fixed errors with Rails 5+
data/Gemfile CHANGED
@@ -3,4 +3,4 @@ source "https://rubygems.org"
3
3
  # Specify your gem's dependencies in mailkick.gemspec
4
4
  gemspec
5
5
 
6
- gem "actionmailer", "~> 5.1.0"
6
+ gem "actionmailer", "~> 5.2.0"
data/README.md CHANGED
@@ -1,14 +1,15 @@
1
1
  # Mailkick
2
2
 
3
- :bullettrain_side: Email subscriptions made easy
3
+ Email subscriptions made easy
4
4
 
5
5
  - Add one-click unsubscribe links to your emails
6
6
  - Fetch bounces and spam reports from your email service
7
-
8
- Gracefully handles email address changes
7
+ - Gracefully handles email address changes
9
8
 
10
9
  :postbox: Check out [Ahoy Email](https://github.com/ankane/ahoy_email) for analytics
11
10
 
11
+ [![Build Status](https://travis-ci.org/ankane/mailkick.svg?branch=master)](https://travis-ci.org/ankane/mailkick)
12
+
12
13
  ## Installation
13
14
 
14
15
  Add this line to your application’s Gemfile:
@@ -21,7 +22,7 @@ And run the generator. This creates a model to store opt-outs.
21
22
 
22
23
  ```sh
23
24
  rails generate mailkick:install
24
- rake db:migrate
25
+ rails db:migrate
25
26
  ```
26
27
 
27
28
  ## How It Works
@@ -57,7 +58,7 @@ Before sending marketing emails, make sure the user has not opted out.
57
58
  Add the following method to models with email addresses.
58
59
 
59
60
  ```ruby
60
- class User < ActiveRecord::Base
61
+ class User < ApplicationRecord
61
62
  mailkick_user
62
63
  end
63
64
  ```
@@ -137,21 +138,12 @@ Mailkick.services = [
137
138
  ]
138
139
  ```
139
140
 
140
- ## Multiple Lists [beta]
141
+ ## Multiple Lists
141
142
 
142
- You may want to split your emails into multiple categories, like sale emails and order reminders.
143
-
144
- Set the list in the mailer.
143
+ You may want to split your emails into multiple categories, like sale emails and order reminders. Set the list in the url:
145
144
 
146
145
  ```ruby
147
- class UserMailer < ActionMailer::Base
148
-
149
- def order_reminder(user)
150
- headers[:mailkick_list] = "order_reminders"
151
- # ...
152
- end
153
-
154
- end
146
+ mailkick_unsubscribe_url(list: "order_reminders")
155
147
  ```
156
148
 
157
149
  Pass the `list` option to methods.
@@ -185,17 +177,12 @@ More great gems for email
185
177
  - [Roadie](https://github.com/Mange/roadie) - inline CSS
186
178
  - [Letter Opener](https://github.com/ryanb/letter_opener) - preview email in development
187
179
 
188
- ## TODO
189
-
190
- - Make it easy to customize controller
191
- - Subscribe to events
192
-
193
180
  ## Reference
194
181
 
195
182
  Change how the user is determined
196
183
 
197
184
  ```ruby
198
- Mailkick.user_method = -> (email) { User.find_by(email: email) }
185
+ Mailkick.user_method = ->(email) { User.find_by(email: email) }
199
186
  ```
200
187
 
201
188
  Use a different email field
@@ -20,19 +20,20 @@ module Mailkick
20
20
  protected
21
21
 
22
22
  def set_email
23
- verifier = ActiveSupport::MessageVerifier.new(Mailkick.secret_token)
24
- begin
25
- @email, user_id, user_type, @list = verifier.verify(params[:id])
26
- if user_type
27
- # on the unprobabilistic chance user_type is compromised, not much damage
28
- @user = user_type.constantize.find(user_id)
29
- end
30
- @options = {
31
- email: @email,
32
- user: @user,
33
- list: @list
34
- }
35
- rescue ActiveSupport::MessageVerifier::InvalidSignature
23
+ @email, user_id, user_type, @list = Mailkick.message_verifier.verify(params[:id])
24
+ if user_type
25
+ # on the unprobabilistic chance user_type is compromised, not much damage
26
+ @user = user_type.constantize.find(user_id)
27
+ end
28
+ @options = {
29
+ email: @email,
30
+ user: @user,
31
+ list: @list
32
+ }
33
+ rescue ActiveSupport::MessageVerifier::InvalidSignature
34
+ if Rails::VERSION::MAJOR >= 5
35
+ render plain: "Subscription not found", status: :bad_request
36
+ else
36
37
  render text: "Subscription not found", status: :bad_request
37
38
  end
38
39
  end
@@ -1,11 +1,12 @@
1
1
  module Mailkick
2
2
  module UrlHelper
3
- def mailkick_unsubscribe_url
3
+ def mailkick_unsubscribe_url(email: nil, list: nil, **options)
4
+ email ||= controller.message.to.first
4
5
  Mailkick::Engine.routes.url_helpers.url_for(
5
- (ActionMailer::Base.default_url_options || {}).merge(
6
+ (ActionMailer::Base.default_url_options || {}).merge(options).merge(
6
7
  controller: "mailkick/subscriptions",
7
8
  action: "unsubscribe",
8
- id: "{{MAILKICK_TOKEN}}"
9
+ id: Mailkick.generate_token(email, list: list)
9
10
  )
10
11
  )
11
12
  end
data/config/routes.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  Rails.application.routes.draw do
2
- mount Mailkick::Engine => "/mailkick" if Mailkick.mount
2
+ unless respond_to?(:has_named_route?) && has_named_route?("mailkick")
3
+ mount Mailkick::Engine => "/mailkick" if Mailkick.mount
4
+ end
3
5
  end
4
6
 
5
7
  Mailkick::Engine.routes.draw do
@@ -2,8 +2,7 @@ class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version
2
2
  def change
3
3
  create_table :mailkick_opt_outs do |t|
4
4
  t.string :email
5
- t.integer :user_id
6
- t.string :user_type
5
+ t.references :user, polymorphic: true
7
6
  t.boolean :active, null: false, default: true
8
7
  t.string :reason
9
8
  t.string :list
@@ -11,6 +10,5 @@ class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version
11
10
  end
12
11
 
13
12
  add_index :mailkick_opt_outs, :email
14
- add_index :mailkick_opt_outs, [:user_id, :user_type]
15
13
  end
16
14
  end
data/lib/mailkick.rb CHANGED
@@ -1,21 +1,19 @@
1
1
  require "set"
2
- require "safely/core"
3
2
  require "active_support"
3
+
4
4
  require "mailkick/engine" if defined?(Rails)
5
- require "mailkick/processor"
6
- require "mailkick/mailer"
7
5
  require "mailkick/model"
8
6
  require "mailkick/service"
9
7
  require "mailkick/service/mailchimp"
8
+ require "mailkick/service/mailgun"
10
9
  require "mailkick/service/mandrill"
11
10
  require "mailkick/service/sendgrid"
12
- require "mailkick/service/mailgun"
13
11
  require "mailkick/version"
14
12
 
15
13
  module Mailkick
16
14
  mattr_accessor :services, :user_method, :secret_token, :mount
17
15
  self.services = []
18
- self.user_method = proc { |email| User.where(email: email).first rescue nil }
16
+ self.user_method = ->(email) { User.where(email: email).first rescue nil }
19
17
  self.mount = true
20
18
 
21
19
  def self.fetch_opt_outs
@@ -65,7 +63,7 @@ module Mailkick
65
63
  binds << email
66
64
  end
67
65
  if (user = options[:user])
68
- parts << "user_id = ? and user_type = ?"
66
+ parts << "(user_id = ? and user_type = ?)"
69
67
  binds.concat [user.id, user.class.name]
70
68
  end
71
69
  relation = relation.where(parts.join(" OR "), *binds) if parts.any?
@@ -88,10 +86,15 @@ module Mailkick
88
86
  def self.opted_out_users(options = {})
89
87
  Set.new(opt_outs(options).where("user_id IS NOT NULL").map(&:user))
90
88
  end
91
- end
92
89
 
93
- ActiveSupport.on_load(:action_mailer) do
94
- prepend Mailkick::Mailer
90
+ def self.message_verifier
91
+ @message_verifier ||= ActiveSupport::MessageVerifier.new(Mailkick.secret_token)
92
+ end
93
+
94
+ def self.generate_token(email, list: nil)
95
+ user = Mailkick.user_method.call(email) if Mailkick.user_method
96
+ message_verifier.generate([email, user.try(:id), user.try(:class).try(:name), list])
97
+ end
95
98
  end
96
99
 
97
100
  ActiveSupport.on_load(:active_record) do
@@ -4,8 +4,20 @@ module Mailkick
4
4
 
5
5
  initializer "mailkick" do |app|
6
6
  Mailkick.discover_services unless Mailkick.services.any?
7
- secrets = app.respond_to?(:secrets) ? app.secrets : app.config
8
- Mailkick.secret_token ||= secrets.respond_to?(:secret_key_base) ? secrets.secret_key_base : secrets.secret_token
7
+
8
+ Mailkick.secret_token ||= begin
9
+ creds =
10
+ if app.respond_to?(:credentials)
11
+ app.credentials
12
+ elsif app.respond_to?(:secrets)
13
+ app.secrets
14
+ else
15
+ app.config
16
+ end
17
+
18
+ creds.respond_to?(:secret_key_base) ? creds.secret_key_base : creds.secret_token
19
+ end
20
+
9
21
  ActiveSupport.on_load :action_mailer do
10
22
  helper Mailkick::UrlHelper
11
23
  end
@@ -15,6 +15,7 @@ module Mailkick
15
15
  )
16
16
  end
17
17
  end
18
+
18
19
  true
19
20
  end
20
21
  end
@@ -6,7 +6,7 @@ module Mailkick
6
6
  def initialize(options = {})
7
7
  require "mailgun"
8
8
  mailgun_client = ::Mailgun::Client.new(options[:api_key] || ENV["MAILGUN_API_KEY"])
9
- domain = options[:domain] || ActionMailer::Base.default_url_options[:host]
9
+ domain = options[:domain] || ActionMailer::Base.smtp_settings[:domain]
10
10
  @mailgun_events = ::Mailgun::Events.new(mailgun_client, domain)
11
11
  end
12
12
 
@@ -1,3 +1,3 @@
1
1
  module Mailkick
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
data/mailkick.gemspec CHANGED
@@ -9,7 +9,6 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Andrew Kane"]
10
10
  spec.email = ["andrew@chartkick.com"]
11
11
  spec.summary = "Email subscriptions made easy"
12
- spec.description = "Email subscriptions made easy"
13
12
  spec.homepage = "https://github.com/ankane/mailkick"
14
13
  spec.license = "MIT"
15
14
 
@@ -18,14 +17,16 @@ Gem::Specification.new do |spec|
18
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
18
  spec.require_paths = ["lib"]
20
19
 
21
- spec.add_dependency "activesupport"
22
- spec.add_dependency "safely_block", ">= 0.1.1"
20
+ spec.add_dependency "activesupport", ">= 4.2"
23
21
 
24
22
  spec.add_development_dependency "bundler"
25
- spec.add_development_dependency "rake"
26
- spec.add_development_dependency "minitest"
27
- spec.add_development_dependency "sendgrid_toolkit"
28
- spec.add_development_dependency "mandrill-api"
29
23
  spec.add_development_dependency "gibbon", ">= 2"
30
24
  spec.add_development_dependency "mailgun-ruby"
25
+ spec.add_development_dependency "mandrill-api"
26
+ spec.add_development_dependency "minitest"
27
+ spec.add_development_dependency "rake"
28
+ spec.add_development_dependency "sendgrid_toolkit"
29
+ spec.add_development_dependency "combustion"
30
+ spec.add_development_dependency "rails"
31
+ spec.add_development_dependency "sqlite3"
31
32
  end
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in mailkick.gemspec
4
+ gemspec path: "../../"
5
+
6
+ gem "actionmailer", "~> 4.2.0"
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in mailkick.gemspec
4
+ gemspec path: "../../"
5
+
6
+ gem "actionmailer", "~> 5.0.0"
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in mailkick.gemspec
4
+ gemspec path: "../../"
5
+
6
+ gem "actionmailer", "~> 5.1.0"
@@ -0,0 +1,7 @@
1
+ class UserMailer < ActionMailer::Base
2
+ default from: "from@example.com"
3
+
4
+ def welcome
5
+ mail to: "test@example.org", subject: "Hello"
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ class User < ActiveRecord::Base
2
+ mailkick_user
3
+ end
@@ -0,0 +1 @@
1
+ <p><%= mailkick_unsubscribe_url %></p>
@@ -0,0 +1 @@
1
+ Unsubscribe: <%= mailkick_unsubscribe_url %>
@@ -0,0 +1,3 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: db/combustion_test.sqlite
@@ -0,0 +1,16 @@
1
+ ActiveRecord::Schema.define do
2
+ create_table :mailkick_opt_outs do |t|
3
+ t.string :email
4
+ t.references :user, polymorphic: true
5
+ t.boolean :active, null: false, default: true
6
+ t.string :reason
7
+ t.string :list
8
+ t.timestamps
9
+ end
10
+
11
+ add_index :mailkick_opt_outs, :email
12
+
13
+ create_table :users do |t|
14
+ t.string :email
15
+ end
16
+ end
@@ -4,8 +4,26 @@ class MailkickTest < Minitest::Test
4
4
  def test_unsubscribe_url
5
5
  message = UserMailer.welcome.deliver_now
6
6
  html_body = message.html_part.body.to_s
7
- assert_equal "<p>BAhbCUkiFXRlc3RAZXhhbXBsZS5vcmcGOgZFVDAwMA%3D%3D--f435e91ba90e1732d3e999af1f2126dcc8182a5d</p>", html_body
7
+ assert_includes html_body, "BAhbCUkiFXRlc3RAZXhhbXBsZS5vcmcGOgZFVDAwMA==--f435e91ba90e1732d3e999af1f2126dcc8182a5d"
8
8
  text_body = message.text_part.body.to_s
9
- assert_equal "Boom: BAhbCUkiFXRlc3RAZXhhbXBsZS5vcmcGOgZFVDAwMA%3D%3D--f435e91ba90e1732d3e999af1f2126dcc8182a5d", text_body
9
+ assert_includes text_body, "BAhbCUkiFXRlc3RAZXhhbXBsZS5vcmcGOgZFVDAwMA==--f435e91ba90e1732d3e999af1f2126dcc8182a5d"
10
+ end
11
+
12
+ def test_opt_out
13
+ email = "test2@example.org"
14
+ user = User.create!(email: email)
15
+
16
+ Mailkick.opt_out(email: email, user: user)
17
+
18
+ opt_outs = Mailkick::OptOut.all.to_a
19
+ assert_equal 1, opt_outs.size
20
+
21
+ opt_out = opt_outs.first
22
+ assert_equal email, opt_out.email
23
+ assert_equal user, opt_out.user
24
+
25
+ assert user.opted_out?
26
+ assert_equal 1, User.opted_out.count
27
+ assert_equal 0, User.not_opted_out.count
10
28
  end
11
29
  end
data/test/test_helper.rb CHANGED
@@ -1,22 +1,20 @@
1
1
  require "bundler/setup"
2
+ require "combustion"
2
3
  Bundler.require(:default)
3
4
  require "minitest/autorun"
4
5
  require "minitest/pride"
5
6
  require "logger"
6
- require "action_mailer"
7
7
 
8
8
  Minitest::Test = Minitest::Unit::TestCase unless defined?(Minitest::Test)
9
- ActionMailer::Base.delivery_method = :test
10
-
11
- Mailkick.secret_token = "test123"
12
-
13
- class UserMailer < ActionMailer::Base
14
- default from: "from@example.com"
15
9
 
16
- def welcome
17
- mail to: "test@example.org", subject: "Hello" do |format|
18
- format.html { render plain: "<p>%7B%7BMAILKICK_TOKEN%7D%7D</p>" }
19
- format.text { render plain: "Boom: %7B%7BMAILKICK_TOKEN%7D%7D" }
20
- end
10
+ Combustion.path = "test/internal"
11
+ Combustion.initialize! :all do
12
+ if config.active_record.sqlite3.respond_to?(:represent_boolean_as_integer)
13
+ config.active_record.sqlite3.represent_boolean_as_integer = false
21
14
  end
22
15
  end
16
+
17
+ ActiveRecord::Base.logger = ActiveSupport::Logger.new(STDOUT) if ENV["VERBOSE"]
18
+ ActionMailer::Base.delivery_method = :test
19
+
20
+ Mailkick.secret_token = "test123"
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: 0.2.1
4
+ version: 0.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: 2017-10-30 00:00:00.000000000 Z
11
+ date: 2018-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,30 +16,44 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '4.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - ">="
25
39
  - !ruby/object:Gem::Version
26
40
  version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
- name: safely_block
42
+ name: gibbon
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
32
46
  - !ruby/object:Gem::Version
33
- version: 0.1.1
34
- type: :runtime
47
+ version: '2'
48
+ type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - ">="
39
53
  - !ruby/object:Gem::Version
40
- version: 0.1.1
54
+ version: '2'
41
55
  - !ruby/object:Gem::Dependency
42
- name: bundler
56
+ name: mailgun-ruby
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - ">="
@@ -53,7 +67,7 @@ dependencies:
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
- name: rake
70
+ name: mandrill-api
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - ">="
@@ -80,6 +94,20 @@ dependencies:
80
94
  - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: sendgrid_toolkit
85
113
  requirement: !ruby/object:Gem::Requirement
@@ -95,7 +123,7 @@ dependencies:
95
123
  - !ruby/object:Gem::Version
96
124
  version: '0'
97
125
  - !ruby/object:Gem::Dependency
98
- name: mandrill-api
126
+ name: combustion
99
127
  requirement: !ruby/object:Gem::Requirement
100
128
  requirements:
101
129
  - - ">="
@@ -109,21 +137,21 @@ dependencies:
109
137
  - !ruby/object:Gem::Version
110
138
  version: '0'
111
139
  - !ruby/object:Gem::Dependency
112
- name: gibbon
140
+ name: rails
113
141
  requirement: !ruby/object:Gem::Requirement
114
142
  requirements:
115
143
  - - ">="
116
144
  - !ruby/object:Gem::Version
117
- version: '2'
145
+ version: '0'
118
146
  type: :development
119
147
  prerelease: false
120
148
  version_requirements: !ruby/object:Gem::Requirement
121
149
  requirements:
122
150
  - - ">="
123
151
  - !ruby/object:Gem::Version
124
- version: '2'
152
+ version: '0'
125
153
  - !ruby/object:Gem::Dependency
126
- name: mailgun-ruby
154
+ name: sqlite3
127
155
  requirement: !ruby/object:Gem::Requirement
128
156
  requirements:
129
157
  - - ">="
@@ -136,7 +164,7 @@ dependencies:
136
164
  - - ">="
137
165
  - !ruby/object:Gem::Version
138
166
  version: '0'
139
- description: Email subscriptions made easy
167
+ description:
140
168
  email:
141
169
  - andrew@chartkick.com
142
170
  executables: []
@@ -144,6 +172,7 @@ extensions: []
144
172
  extra_rdoc_files: []
145
173
  files:
146
174
  - ".gitignore"
175
+ - ".travis.yml"
147
176
  - CHANGELOG.md
148
177
  - Gemfile
149
178
  - LICENSE.txt
@@ -159,9 +188,7 @@ files:
159
188
  - lib/generators/mailkick/views_generator.rb
160
189
  - lib/mailkick.rb
161
190
  - lib/mailkick/engine.rb
162
- - lib/mailkick/mailer.rb
163
191
  - lib/mailkick/model.rb
164
- - lib/mailkick/processor.rb
165
192
  - lib/mailkick/service.rb
166
193
  - lib/mailkick/service/mailchimp.rb
167
194
  - lib/mailkick/service/mailgun.rb
@@ -169,6 +196,15 @@ files:
169
196
  - lib/mailkick/service/sendgrid.rb
170
197
  - lib/mailkick/version.rb
171
198
  - mailkick.gemspec
199
+ - test/gemfiles/actionmailer42.gemfile
200
+ - test/gemfiles/actionmailer50.gemfile
201
+ - test/gemfiles/actionmailer51.gemfile
202
+ - test/internal/app/mailers/user_mailer.rb
203
+ - test/internal/app/models/user.rb
204
+ - test/internal/app/views/user_mailer/welcome.html.erb
205
+ - test/internal/app/views/user_mailer/welcome.text.erb
206
+ - test/internal/config/database.yml
207
+ - test/internal/db/schema.rb
172
208
  - test/mailkick_test.rb
173
209
  - test/test_helper.rb
174
210
  homepage: https://github.com/ankane/mailkick
@@ -191,10 +227,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
227
  version: '0'
192
228
  requirements: []
193
229
  rubyforge_project:
194
- rubygems_version: 2.6.13
230
+ rubygems_version: 2.7.6
195
231
  signing_key:
196
232
  specification_version: 4
197
233
  summary: Email subscriptions made easy
198
234
  test_files:
235
+ - test/gemfiles/actionmailer42.gemfile
236
+ - test/gemfiles/actionmailer50.gemfile
237
+ - test/gemfiles/actionmailer51.gemfile
238
+ - test/internal/app/mailers/user_mailer.rb
239
+ - test/internal/app/models/user.rb
240
+ - test/internal/app/views/user_mailer/welcome.html.erb
241
+ - test/internal/app/views/user_mailer/welcome.text.erb
242
+ - test/internal/config/database.yml
243
+ - test/internal/db/schema.rb
199
244
  - test/mailkick_test.rb
200
245
  - test/test_helper.rb
@@ -1,11 +0,0 @@
1
- module Mailkick
2
- module Mailer
3
- def mail(headers = {}, &block)
4
- message = super
5
-
6
- Safely.safely { Mailkick::Processor.new(message).process }
7
-
8
- message
9
- end
10
- end
11
- end
@@ -1,29 +0,0 @@
1
- module Mailkick
2
- class Processor
3
- attr_reader :message
4
-
5
- def initialize(message)
6
- @message = message
7
- end
8
-
9
- def process
10
- email = message.to.first
11
- user = Mailkick.user_method.call(email) if Mailkick.user_method
12
- list = message[:mailkick_list].try(:value)
13
- if list
14
- # remove header
15
- message[:mailkick_list] = nil
16
- end
17
-
18
- verifier = ActiveSupport::MessageVerifier.new(Mailkick.secret_token)
19
- token = verifier.generate([email, user.try(:id), user.try(:class).try(:name), list])
20
-
21
- parts = message.parts.any? ? message.parts : [message]
22
- parts.each do |part|
23
- if part.content_type.match(/text\/(html|plain)/)
24
- part.body = part.body.decoded.gsub(/%7B%7BMAILKICK_TOKEN%7D%7D/, CGI.escape(token))
25
- end
26
- end
27
- end
28
- end
29
- end