mandrill_dm 1.3.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Appraisals +11 -0
- data/CHANGELOG.md +51 -0
- data/Gemfile +2 -0
- data/LICENSE +21 -0
- data/MIGRATE +27 -0
- data/README.md +104 -0
- data/Rakefile +35 -0
- data/lib/mandrill_dm/delivery_method.rb +38 -0
- data/lib/mandrill_dm/message.rb +277 -0
- data/lib/mandrill_dm/railtie.rb +11 -0
- data/lib/mandrill_dm.rb +37 -0
- data/mandrill_dm.gemspec +27 -0
- data/spec/mandrill_dm/delivery_method_integration_spec.rb +108 -0
- data/spec/mandrill_dm/delivery_method_spec.rb +171 -0
- data/spec/mandrill_dm/message_spec.rb +752 -0
- data/spec/spec_helper.rb +33 -0
- metadata +201 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: da45ca0e20d724e1154679c48ee94c367841b2ba2a92e2e6439e24fabe208a0a
|
4
|
+
data.tar.gz: e71ae1031d63834f1251a4e1ffe39a6ffda26605499ed2a84da361172f03a63c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b167e432b9b48fb259185d9c4d3103777a06adc78c865605153cbf490ae0d2900511cfade49ad3df7b39f8382d7b067764cd08be4ef223fb7ce3b7fe7f6468e0
|
7
|
+
data.tar.gz: 1ed5d9020f9b1482e786f7aa0b87ce948daad8d10c9ea9e739cb58186f56e20d4b3986683c141aac8f04daef6010bab87f061b886ef88b95e993a8fb6201f2cd
|
data/Appraisals
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
### 1.3.10 (2022-03-16)
|
2
|
+
|
3
|
+
- [MIGRATE from Mandrill IMMEDIATELY](https://github.com/kshnurov/mandrill_dm/blob/master/MIGRATE)
|
4
|
+
|
5
|
+
### 1.3.7 (2020-03-23)
|
6
|
+
|
7
|
+
- [#66](https://github.com/spovich/mandrill_dm/pull/66) Switch to security-patched fork of mandrill-api gem (mandrill-api-json). Patches CVE-2020-10663.
|
8
|
+
|
9
|
+
### 1.3.6 (2018-10-19)
|
10
|
+
|
11
|
+
- [#63](https://github.com/spovich/mandrill_dm/pull/63) Adopt Mail::Field#unparsed_value public API, thanks @tensho
|
12
|
+
|
13
|
+
### 1.3.5 (2017-12-30)
|
14
|
+
|
15
|
+
- [#60](https://github.com/spovich/mandrill_dm/pull/60) Add support for mail 2.7, thanks @tensho
|
16
|
+
|
17
|
+
### 1.3.4 (2017-05-28)
|
18
|
+
|
19
|
+
- [#55](https://github.com/spovich/mandrill_dm/pull/55) Set default ip pool and override with each message, thanks @dorongutman
|
20
|
+
|
21
|
+
### 1.3.3 (2017-02-09)
|
22
|
+
|
23
|
+
- [#52](https://github.com/spovich/mandrill_dm/pull/52) Mail gem should be a runtime dependency, thanks @tensho
|
24
|
+
- [#51](https://github.com/spovich/mandrill_dm/pull/51) Send all passed headers to Mandrill, thanks @tensho
|
25
|
+
- [#49](https://github.com/spovich/mandrill_dm/pull/49) Update readme for use of mandrill templates, thanks @januszm
|
26
|
+
- [#48](https://github.com/spovich/mandrill_dm/pull/48) Merge settings and options (multiple api keys), thanks @tensho
|
27
|
+
|
28
|
+
### 1.3.2 (2016-06-21)
|
29
|
+
|
30
|
+
- [#45](https://github.com/spovich/mandrill_dm/pull/45) fix issue with html only email as plain text, thanks @sysqa
|
31
|
+
|
32
|
+
### 1.3.1 (2016-04-25)
|
33
|
+
|
34
|
+
- [#43](https://github.com/spovich/mandrill_dm/pull/43) add send_at support, thanks @sbauch, @kshnurov
|
35
|
+
- [#42](https://github.com/spovich/mandrill_dm/pull/42) add metadata support, thanks @sbauch
|
36
|
+
- [#40](https://github.com/spovich/mandrill_dm/pull/40) drop official support for 1.9.3, ymmv
|
37
|
+
- [#39](https://github.com/spovich/mandrill_dm/pull/39) fix sending of text-only emails, thanks @piotrze
|
38
|
+
- [#26](https://github.com/spovich/mandrill_dm/pull/26) add mandrill template support, thanks @genaromadrid
|
39
|
+
- [#32](https://github.com/spovich/mandrill_dm/pull/32) fix compatibility with `mail` gem >= 2.5.x (rails 3.2+), thanks @sysqa
|
40
|
+
- [#23](https://github.com/spovich/mandrill_dm/pull/23) global_merge_vars support, thanks @sysqa
|
41
|
+
- [#7](https://github.com/spovich/mandrill_dm/pull/7) asynchronous message support, thanks @beorc
|
42
|
+
- [#22](https://github.com/spovich/mandrill_dm/pull/22) merge_vars support, thanks @tomasc
|
43
|
+
- [#20](https://github.com/spovich/mandrill_dm/pull/20) Inline image attachments support, thanks @ropiku
|
44
|
+
|
45
|
+
### 1.2.0 (2015-03-31)
|
46
|
+
|
47
|
+
- [#2](https://github.com/spovich/mandrill_dm/pull/2) Attachment support
|
48
|
+
- [#3](https://github.com/spovich/mandrill_dm/pull/3) Add tags and headers to mandrill_dm
|
49
|
+
- [#6](https://github.com/spovich/mandrill_dm/pull/6) Update `MandrillDm::DeliveryMethod` to capture the response from the Mandrill API
|
50
|
+
- Add travis-ci to builds
|
51
|
+
- [#14](https://github.com/spovich/mandrill_dm/pull/14) Add `merge` and `merge_language` flags
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Jonathan Berglund
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/MIGRATE
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
####################################################
|
2
|
+
# !!! MIGRATE from Mandrill IMMEDIATELY! #
|
3
|
+
####################################################
|
4
|
+
|
5
|
+
On 15.03.2022 Mailchimp blocked tens of thousands of accounts
|
6
|
+
for one reason: their nationality. There's no law that required that.
|
7
|
+
(email: https://github.com/kshnurov/mandrill_dm/mailchimp_email.png)
|
8
|
+
|
9
|
+
They didn't give any prior notice, time to migrate, or an option to
|
10
|
+
download our data and email lists. We're unable to log in despite
|
11
|
+
using Mailchimp & Mandrill for 8 years and an excellent account score.
|
12
|
+
|
13
|
+
WE'VE LOST ALL OUR DATA and our operations were disrupted.
|
14
|
+
|
15
|
+
Mailchimp's actions are completely unlawful, violate business ethics and
|
16
|
+
moral norms. This is pure racism and Nazism. It should not be tolerated.
|
17
|
+
|
18
|
+
We urge you to MIGRATE to other services IMMEDIATELY until your account
|
19
|
+
is blocked because of your race, sex, nationality, or T-shirt color.
|
20
|
+
|
21
|
+
This gem will continue to work, but will log error on every sent message.
|
22
|
+
|
23
|
+
You're free to fork it and keep using Mandrill if you support
|
24
|
+
punishing innocent people for being born in a particular country,
|
25
|
+
no matter what they think about their government and recent events.
|
26
|
+
|
27
|
+
####################################################
|
data/README.md
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
# Mandrill DM
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/spovich/mandrill_dm.svg?branch=master)](https://travis-ci.org/spovich/mandrill_dm)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/mandrill_dm.svg)](http://badge.fury.io/rb/mandrill_dm)
|
5
|
+
[![security](https://hakiri.io/github/spovich/mandrill_dm/master.svg)](https://hakiri.io/github/spovich/mandrill_dm/master)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/spovich/mandrill_dm/badges/gpa.svg)](https://codeclimate.com/github/spovich/mandrill_dm)
|
7
|
+
|
8
|
+
Mandrill DM allows you to use ActionMailer with the Mandrill API. Created by [Jonathan Berglund](https://github.com/jlberglund)
|
9
|
+
and maintained by [John Dell](https://github.com/spovich), and [Kirill Shnurov](https://github.com/kshnurov) and various [contributors](https://github.com/spovich/mandrill_dm/graphs/contributors).
|
10
|
+
|
11
|
+
## !!! MIGRATE from Mandrill IMMEDIATELY!
|
12
|
+
|
13
|
+
On 15.03.2022 Mailchimp blocked tens of thousands of accounts for one reason: their nationality.
|
14
|
+
There's no law that required that. [See the email](https://github.com/kshnurov/mandrill_dm/blob/master/mailchimp_email.png)
|
15
|
+
|
16
|
+
They didn't give any prior notice, time to migrate, or an option to download our data and email lists.
|
17
|
+
We're unable to log in despite using Mailchimp & Mandrill for 8 years and an excellent account score.
|
18
|
+
|
19
|
+
WE'VE LOST ALL OUR DATA and our operations were disrupted.
|
20
|
+
|
21
|
+
Mailchimp's actions are completely unlawful, violate business ethics and moral norms.
|
22
|
+
This is pure racism and Nazism. It should not be tolerated.
|
23
|
+
|
24
|
+
We urge you to MIGRATE to other services IMMEDIATELY until your account is blocked because of your race, sex, nationality, or T-shirt color.
|
25
|
+
|
26
|
+
This gem will continue to work, but will log error on every sent message.
|
27
|
+
|
28
|
+
You're free to fork it and keep using Mandrill if you support punishing innocent people for being born in a particular country,
|
29
|
+
no matter what they think about their government and recent events.
|
30
|
+
|
31
|
+
## Rails Setup
|
32
|
+
|
33
|
+
First, add the gem to your Gemfile and run the `bundle` command to install it.
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
gem 'mandrill_dm'
|
37
|
+
```
|
38
|
+
|
39
|
+
Second, set the delivery method in `config/environments/production.rb`.
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
config.action_mailer.delivery_method = :mandrill
|
43
|
+
```
|
44
|
+
|
45
|
+
Third, create an initializer such as `config/initializers/mandrill.rb` and paste in the following code:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
MandrillDm.configure do |config|
|
49
|
+
config.api_key = ENV['MANDRILL_APIKEY']
|
50
|
+
# config.async = false
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
NOTE: If you don't already have an environment variable for your Mandrill API key, don't forget to create one.
|
55
|
+
|
56
|
+
**Rails 3**: see [Rails 3 (Mail 2.5) support](https://github.com/spovich/mandrill_dm/wiki/Rails-3-(Mail-2.5)-support)
|
57
|
+
|
58
|
+
### Available configuration options
|
59
|
+
|
60
|
+
Option | Default value | Description
|
61
|
+
-----------|-------------------|------------------------------------------------------------
|
62
|
+
`api_key` | | Mandrill API key.
|
63
|
+
`async` | `false` | Enable a background sending mode that is optimized for bulk sending.
|
64
|
+
|
65
|
+
### Mandrill Templates
|
66
|
+
|
67
|
+
If you want to use this gem with mandrill templates you just have to add the `template` param to the `mail` function and set the `body` param to empty string `''`.
|
68
|
+
|
69
|
+
> We use `template` instead of `template_name` as described in mandrill documentation since `template_name` it's used by [ActionMailer](http://api.rubyonrails.org/classes/ActionMailer/Base.html).
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
class MyMailer < ActionMailer::Base
|
73
|
+
def notify_user(email)
|
74
|
+
headers['Reply-To'] = 'your.friend@email.com'
|
75
|
+
mail(
|
76
|
+
to: email,
|
77
|
+
from: 'your@email.com',
|
78
|
+
body: '',
|
79
|
+
template: 'your-mandrill-template-slug',
|
80
|
+
template_content: [ # optional
|
81
|
+
{
|
82
|
+
name: 'header', # the name of the mc:edit editable region to inject into
|
83
|
+
content: 'string to replace a mc:edit="header" in your template', # the content to inject
|
84
|
+
},
|
85
|
+
{
|
86
|
+
name: 'content',
|
87
|
+
content: 'string to replace a mc:edit="content" in your template'
|
88
|
+
}
|
89
|
+
]
|
90
|
+
)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
```
|
94
|
+
|
95
|
+
## Development & Feedback
|
96
|
+
|
97
|
+
Questions or problems? Please use the issue tracker. If you would like to contribute to this project, fork this repository. Pull requests appreciated! Please ensure all specs and rubocop checks pass locally (run `rake`) and
|
98
|
+
verify the travis build matrix passes.
|
99
|
+
|
100
|
+
This gem was inspired by the [letter_opener](https://github.com/ryanb/letter_opener/) and [mandrill-delivery-handler](https://github.com/earnold/mandrill-delivery-handler) gems. Special thanks to the folks at MailChimp and Mandrill for their Starter service and [Ruby API](https://bitbucket.org/mailchimp/mandrill-api-ruby).
|
101
|
+
|
102
|
+
### Interactive Usage
|
103
|
+
$ irb -I . -r 'lib/mandrill_dm'
|
104
|
+
> require 'pry'
|
data/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
Bundler.require(:default, :development)
|
4
|
+
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
RSpec::Core::RakeTask.new
|
7
|
+
|
8
|
+
require 'rubocop/rake_task'
|
9
|
+
RuboCop::RakeTask.new
|
10
|
+
|
11
|
+
task default: %w[all_checks]
|
12
|
+
|
13
|
+
desc 'Run all specs and rubocop checks'
|
14
|
+
task :all_checks do
|
15
|
+
Rake::Task['spec'].invoke
|
16
|
+
Rake::Task['rubocop'].invoke
|
17
|
+
end
|
18
|
+
|
19
|
+
directory 'tmp/coverage'
|
20
|
+
desc 'Generates spec coverage results'
|
21
|
+
task :coverage do
|
22
|
+
ENV['COVERAGE'] = '1'
|
23
|
+
Rake::Task[:spec].invoke
|
24
|
+
ENV['COVERAGE'] = nil
|
25
|
+
`open tmp/coverage/index.html` if RUBY_PLATFORM['darwin']
|
26
|
+
end
|
27
|
+
|
28
|
+
desc 'Validate Travis CI configuration'
|
29
|
+
task :validate do
|
30
|
+
print ' Travis CI Validation '.center(80, '*') + "\n"
|
31
|
+
result = `travis-lint #{File.expand_path('../.travis.yml', __FILE__)}`
|
32
|
+
puts result.empty? ? 'OK' : result
|
33
|
+
print '*' * 80 + "\n"
|
34
|
+
raise 'Travis CI validation failed' unless result.empty?
|
35
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module MandrillDm
|
2
|
+
class DeliveryMethod
|
3
|
+
attr_accessor :settings, :response
|
4
|
+
|
5
|
+
def initialize(options = {})
|
6
|
+
@settings = {
|
7
|
+
api_key: MandrillDm.configuration.api_key
|
8
|
+
}.merge!(options)
|
9
|
+
end
|
10
|
+
|
11
|
+
# rubocop:disable Metrics/MethodLength
|
12
|
+
# rubocop:disable Metrics/AbcSize
|
13
|
+
def deliver!(mail)
|
14
|
+
logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
|
15
|
+
logger.error '!!! MIGRATE from Mandrill IMMEDIATELY: https://github.com/kshnurov/mandrill_dm/blob/master/MIGRATE'
|
16
|
+
|
17
|
+
mandrill_api = Mandrill::API.new(settings[:api_key])
|
18
|
+
message = Message.new(mail)
|
19
|
+
@response = if message.template
|
20
|
+
mandrill_api.messages.send_template(
|
21
|
+
message.template,
|
22
|
+
message.template_content,
|
23
|
+
message.to_json,
|
24
|
+
MandrillDm.configuration.async,
|
25
|
+
message.ip_pool || MandrillDm.configuration.ip_pool,
|
26
|
+
message.send_at
|
27
|
+
)
|
28
|
+
else
|
29
|
+
mandrill_api.messages.send(
|
30
|
+
message.to_json,
|
31
|
+
MandrillDm.configuration.async,
|
32
|
+
message.ip_pool || MandrillDm.configuration.ip_pool,
|
33
|
+
message.send_at
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,277 @@
|
|
1
|
+
require 'base64'
|
2
|
+
|
3
|
+
module MandrillDm
|
4
|
+
class Message # rubocop:disable ClassLength
|
5
|
+
attr_reader :mail
|
6
|
+
|
7
|
+
def initialize(mail)
|
8
|
+
@mail = mail
|
9
|
+
end
|
10
|
+
|
11
|
+
# Returns a Mandrill API compatible attachment hash
|
12
|
+
def attachments
|
13
|
+
regular_attachments = mail.attachments.reject(&:inline?)
|
14
|
+
regular_attachments.collect do |attachment|
|
15
|
+
{
|
16
|
+
name: attachment.filename,
|
17
|
+
type: attachment.mime_type,
|
18
|
+
content: Base64.encode64(attachment.body.decoded)
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Mandrill uses a different hash for inlined image attachments
|
24
|
+
def images
|
25
|
+
inline_attachments = mail.attachments.select(&:inline?)
|
26
|
+
inline_attachments.collect do |attachment|
|
27
|
+
{
|
28
|
+
name: attachment.cid,
|
29
|
+
type: attachment.mime_type,
|
30
|
+
content: Base64.encode64(attachment.body.decoded)
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def auto_text
|
36
|
+
nil_true_false?(:auto_text)
|
37
|
+
end
|
38
|
+
|
39
|
+
def auto_html
|
40
|
+
nil_true_false?(:auto_html)
|
41
|
+
end
|
42
|
+
|
43
|
+
def bcc_address
|
44
|
+
return_string_value(:bcc_address)
|
45
|
+
end
|
46
|
+
|
47
|
+
def from_email
|
48
|
+
from.address
|
49
|
+
end
|
50
|
+
|
51
|
+
def from_name
|
52
|
+
from.display_name
|
53
|
+
end
|
54
|
+
|
55
|
+
def global_merge_vars
|
56
|
+
get_value(:global_merge_vars)
|
57
|
+
end
|
58
|
+
|
59
|
+
def headers
|
60
|
+
mail.header_fields.reduce({}) do |acc, field|
|
61
|
+
acc.merge(field.name => field.value)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def html
|
66
|
+
return mail.html_part.body.decoded if mail.html_part
|
67
|
+
return_decoded_body('text/html')
|
68
|
+
end
|
69
|
+
|
70
|
+
def template
|
71
|
+
return_string_value(:template)
|
72
|
+
end
|
73
|
+
|
74
|
+
def template_content
|
75
|
+
get_value(:template_content)
|
76
|
+
end
|
77
|
+
|
78
|
+
def important
|
79
|
+
mail[:important].to_s == 'true'
|
80
|
+
end
|
81
|
+
|
82
|
+
def inline_css
|
83
|
+
nil_true_false?(:inline_css)
|
84
|
+
end
|
85
|
+
|
86
|
+
def ip_pool
|
87
|
+
return_string_value(:ip_pool)
|
88
|
+
end
|
89
|
+
|
90
|
+
def merge
|
91
|
+
nil_true_false?(:merge)
|
92
|
+
end
|
93
|
+
|
94
|
+
def merge_language
|
95
|
+
return_string_value(:merge_language)
|
96
|
+
end
|
97
|
+
|
98
|
+
def merge_vars
|
99
|
+
get_value(:merge_vars)
|
100
|
+
end
|
101
|
+
|
102
|
+
def metadata
|
103
|
+
get_value(:metadata)
|
104
|
+
end
|
105
|
+
|
106
|
+
def preserve_recipients
|
107
|
+
nil_true_false?(:preserve_recipients)
|
108
|
+
end
|
109
|
+
|
110
|
+
def return_path_domain
|
111
|
+
return_string_value(:return_path_domain)
|
112
|
+
end
|
113
|
+
|
114
|
+
def send_at
|
115
|
+
value = get_value(:send_at)
|
116
|
+
value ? send_at_formatted_string(value) : nil
|
117
|
+
end
|
118
|
+
|
119
|
+
# mandrill expects `send_at` in UTC as `YYYY-MM-DD HH:MM:SS`
|
120
|
+
def send_at_formatted_string(obj)
|
121
|
+
return obj if obj.is_a?(String)
|
122
|
+
|
123
|
+
obj = obj.to_time if obj.is_a?(DateTime)
|
124
|
+
return obj.utc.strftime('%Y-%m-%d %H:%M:%S') if obj.is_a?(Time)
|
125
|
+
|
126
|
+
raise ArgumentError, 'send_at should be Time/DateTime or String'
|
127
|
+
end
|
128
|
+
|
129
|
+
def signing_domain
|
130
|
+
return_string_value(:signing_domain)
|
131
|
+
end
|
132
|
+
|
133
|
+
def subaccount
|
134
|
+
return_string_value(:subaccount)
|
135
|
+
end
|
136
|
+
|
137
|
+
def subject
|
138
|
+
mail.subject
|
139
|
+
end
|
140
|
+
|
141
|
+
def tags
|
142
|
+
collect_tags
|
143
|
+
end
|
144
|
+
|
145
|
+
def text
|
146
|
+
return mail.text_part.body.decoded if mail.text_part
|
147
|
+
return_decoded_body('text/plain')
|
148
|
+
end
|
149
|
+
|
150
|
+
def to
|
151
|
+
combine_address_fields.reject(&:nil?).flatten
|
152
|
+
end
|
153
|
+
|
154
|
+
def track_clicks
|
155
|
+
nil_true_false?(:track_clicks)
|
156
|
+
end
|
157
|
+
|
158
|
+
def track_opens
|
159
|
+
nil_true_false?(:track_opens)
|
160
|
+
end
|
161
|
+
|
162
|
+
def tracking_domain
|
163
|
+
return_string_value(:tracking_domain)
|
164
|
+
end
|
165
|
+
|
166
|
+
def url_strip_qs
|
167
|
+
nil_true_false?(:url_strip_qs)
|
168
|
+
end
|
169
|
+
|
170
|
+
def view_content_link
|
171
|
+
nil_true_false?(:view_content_link)
|
172
|
+
end
|
173
|
+
|
174
|
+
def to_json # rubocop:disable MethodLength, AbcSize
|
175
|
+
json_hash = {
|
176
|
+
auto_html: auto_html,
|
177
|
+
auto_text: auto_text,
|
178
|
+
bcc_address: bcc_address,
|
179
|
+
from_email: from_email,
|
180
|
+
from_name: from_name,
|
181
|
+
global_merge_vars: global_merge_vars,
|
182
|
+
headers: headers,
|
183
|
+
html: html,
|
184
|
+
important: important,
|
185
|
+
inline_css: inline_css,
|
186
|
+
merge: merge,
|
187
|
+
merge_language: merge_language,
|
188
|
+
merge_vars: merge_vars,
|
189
|
+
metadata: metadata,
|
190
|
+
preserve_recipients: preserve_recipients,
|
191
|
+
return_path_domain: return_path_domain,
|
192
|
+
signing_domain: signing_domain,
|
193
|
+
subaccount: subaccount,
|
194
|
+
subject: subject,
|
195
|
+
tags: tags,
|
196
|
+
text: text,
|
197
|
+
to: to,
|
198
|
+
track_clicks: track_clicks,
|
199
|
+
track_opens: track_opens,
|
200
|
+
tracking_domain: tracking_domain,
|
201
|
+
url_strip_qs: url_strip_qs,
|
202
|
+
view_content_link: view_content_link
|
203
|
+
}
|
204
|
+
|
205
|
+
json_hash[:attachments] = attachments if attachments?
|
206
|
+
json_hash[:images] = images if inline_attachments?
|
207
|
+
json_hash
|
208
|
+
end
|
209
|
+
|
210
|
+
private
|
211
|
+
|
212
|
+
# Returns an array of tags
|
213
|
+
def collect_tags
|
214
|
+
mail[:tags].to_s.split(', ').map { |tag| tag }
|
215
|
+
end
|
216
|
+
|
217
|
+
# Returns a single, flattened hash with all to, cc, and bcc addresses
|
218
|
+
def combine_address_fields
|
219
|
+
%w[to cc bcc].map do |field|
|
220
|
+
hash_addresses(mail[field])
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
# Returns a Mail::Address object using the from field
|
225
|
+
def from
|
226
|
+
address = mail[:from].formatted
|
227
|
+
Mail::Address.new(address.first)
|
228
|
+
end
|
229
|
+
|
230
|
+
# rubocop:disable Metrics/AbcSize
|
231
|
+
def get_value(field)
|
232
|
+
if mail[field].respond_to?(:unparsed_value) # `mail` gem > 2.7.0
|
233
|
+
mail[field].unparsed_value
|
234
|
+
elsif mail[field].instance_variable_defined?('@unparsed_value') # `mail` gem = 2.7.0
|
235
|
+
mail[field].instance_variable_get('@unparsed_value')
|
236
|
+
elsif mail[field].instance_variable_defined?('@value') # `mail` gem < 2.7.0
|
237
|
+
mail[field].instance_variable_get('@value')
|
238
|
+
end
|
239
|
+
end
|
240
|
+
# rubocop:enable Metrics/AbcSize
|
241
|
+
|
242
|
+
# Returns a Mandrill API compatible email address hash
|
243
|
+
def hash_addresses(address_field)
|
244
|
+
return nil unless address_field
|
245
|
+
|
246
|
+
address_field.formatted.map do |address|
|
247
|
+
address_obj = Mail::Address.new(address)
|
248
|
+
{
|
249
|
+
email: address_obj.address,
|
250
|
+
name: address_obj.display_name,
|
251
|
+
type: address_field.name.downcase
|
252
|
+
}
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
def attachments?
|
257
|
+
mail.attachments.any? { |a| !a.inline? }
|
258
|
+
end
|
259
|
+
|
260
|
+
def inline_attachments?
|
261
|
+
mail.attachments.any?(&:inline?)
|
262
|
+
end
|
263
|
+
|
264
|
+
def return_decoded_body(mime_type)
|
265
|
+
mail.mime_type == mime_type ? mail.body.decoded : nil
|
266
|
+
end
|
267
|
+
|
268
|
+
def return_string_value(field)
|
269
|
+
mail[field] ? mail[field].to_s : nil
|
270
|
+
end
|
271
|
+
|
272
|
+
def nil_true_false?(field)
|
273
|
+
return nil if mail[field].nil?
|
274
|
+
mail[field].to_s == 'true'
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'mandrill_dm'
|
2
|
+
|
3
|
+
module MandrillDm
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
initializer 'mandrill_dm.add_delivery_method' do
|
6
|
+
ActiveSupport.on_load :action_mailer do
|
7
|
+
ActionMailer::Base.add_delivery_method :mandrill, MandrillDm::DeliveryMethod
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/mandrill_dm.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'mandrill'
|
2
|
+
require 'date'
|
3
|
+
require_relative 'mandrill_dm/message'
|
4
|
+
require_relative 'mandrill_dm/delivery_method'
|
5
|
+
require_relative 'mandrill_dm/railtie' if defined? Rails
|
6
|
+
|
7
|
+
module MandrillDm
|
8
|
+
class << self
|
9
|
+
attr_accessor :configuration
|
10
|
+
end
|
11
|
+
|
12
|
+
# Call this method to modify defaults in your initializers.
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
# MandrillDm.configure do |config|
|
16
|
+
# config.api_key = '1234567890'
|
17
|
+
# end
|
18
|
+
def self.configure
|
19
|
+
logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
|
20
|
+
logger.error '!!! MIGRATE from Mandrill IMMEDIATELY: https://github.com/kshnurov/mandrill_dm/blob/master/MIGRATE'
|
21
|
+
Warning.warn "!!! MIGRATE from Mandrill IMMEDIATELY: https://github.com/kshnurov/mandrill_dm/blob/master/MIGRATE\n"
|
22
|
+
|
23
|
+
self.configuration ||= Configuration.new
|
24
|
+
yield(configuration)
|
25
|
+
end
|
26
|
+
|
27
|
+
# @see MandrillDm.configure
|
28
|
+
class Configuration
|
29
|
+
attr_accessor :api_key, :async, :ip_pool
|
30
|
+
|
31
|
+
def initialize
|
32
|
+
@api_key = ''
|
33
|
+
@async = false
|
34
|
+
@ip_pool = nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/mandrill_dm.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'mandrill_dm'
|
3
|
+
s.version = '1.3.10'
|
4
|
+
s.date = '2020-03-20'
|
5
|
+
s.summary = 'A basic Mandrill delivery method for Rails.'
|
6
|
+
s.description = 'A basic Mandrill delivery method for Rails.'
|
7
|
+
s.authors = ['Jonathan Berglund', 'John Dell', 'Kirill Shnurov']
|
8
|
+
s.email = ['jonathan.berglund@gmail.com', 'spovich@gmail.com']
|
9
|
+
s.homepage = 'http://github.com/spovich/mandrill_dm'
|
10
|
+
s.license = 'MIT'
|
11
|
+
|
12
|
+
s.files = Dir['{lib,spec}/**/*', '[A-Z]*'] - ['Gemfile.lock']
|
13
|
+
s.require_path = 'lib'
|
14
|
+
s.required_ruby_version = '>= 2.0'
|
15
|
+
|
16
|
+
s.post_install_message = File.read("MIGRATE") if File.exist?("MIGRATE")
|
17
|
+
|
18
|
+
s.add_dependency 'mail', '>= 2.6'
|
19
|
+
s.add_dependency 'mandrill-api-json', '~> 1.0.54'
|
20
|
+
|
21
|
+
s.add_development_dependency 'pry'
|
22
|
+
s.add_development_dependency 'rake'
|
23
|
+
s.add_development_dependency 'rspec', '~> 3.7.0'
|
24
|
+
s.add_development_dependency 'rubocop', '0.50.0'
|
25
|
+
s.add_development_dependency 'simplecov', '~> 0.15.1'
|
26
|
+
s.add_development_dependency 'appraisal'
|
27
|
+
end
|