mailgun-ruby 1.1.11 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mailgun/version.rb +1 -1
- data/lib/railgun/mailer.rb +19 -6
- data/mailgun.gemspec +2 -2
- data/spec/unit/railgun/mailer_spec.rb +59 -8
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68010cfb6e35b2a015974c634c156f502a7fe76e75e571ad394761d8e6a50d97
|
4
|
+
data.tar.gz: 14f7dc96ffbb2d5bf1e499a336efe276235e0b260c580b40171236b3ea5f77fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39d8397545a5c30c703cde0c32558c595d4479faa91595299232b113b23d60d0e0ad88f197616fc6a8d2cde2c1952cc3c9effe5fced19a208f5f290cca45f658
|
7
|
+
data.tar.gz: 2eed77f10d1090339987b0a9b120a65017267ced80e694a7710b5058fd14145bab6a2c091c39fa6495c52242648b9524fc88c0a35c782b6dd7057aa57691c16e
|
data/lib/mailgun/version.rb
CHANGED
data/lib/railgun/mailer.rb
CHANGED
@@ -11,7 +11,7 @@ module Railgun
|
|
11
11
|
class Mailer
|
12
12
|
|
13
13
|
# List of the headers that will be ignored when copying headers from `mail.header_fields`
|
14
|
-
IGNORED_HEADERS = %w[ to from subject ]
|
14
|
+
IGNORED_HEADERS = %w[ to from subject reply-to ]
|
15
15
|
|
16
16
|
# [Hash] config ->
|
17
17
|
# Requires *at least* `api_key` and `domain` keys.
|
@@ -27,7 +27,12 @@ module Railgun
|
|
27
27
|
raise Railgun::ConfigurationError.new("Config requires `#{k}` key", @config) unless @config.has_key?(k)
|
28
28
|
end
|
29
29
|
|
30
|
-
@mg_client = Mailgun::Client.new(
|
30
|
+
@mg_client = Mailgun::Client.new(
|
31
|
+
config[:api_key],
|
32
|
+
config[:api_host] || 'api.mailgun.net',
|
33
|
+
config[:api_version] || 'v3',
|
34
|
+
config[:api_ssl].nil? ? true : config[:api_ssl],
|
35
|
+
)
|
31
36
|
@domain = @config[:domain]
|
32
37
|
|
33
38
|
# To avoid exception in mail gem v2.6
|
@@ -62,6 +67,9 @@ module Railgun
|
|
62
67
|
# After prefixing them with the proper option type, they are added to
|
63
68
|
# the message hash where they will then be sent to the API as JSON.
|
64
69
|
#
|
70
|
+
# It is important to note that headers set in `mailgun_headers` on the message
|
71
|
+
# WILL overwrite headers set via `mail.headers()`.
|
72
|
+
#
|
65
73
|
# @param [Mail::Message] mail message to transform
|
66
74
|
#
|
67
75
|
# @return [Hash] transformed message hash
|
@@ -85,12 +93,17 @@ module Railgun
|
|
85
93
|
msg_headers = Hash.new
|
86
94
|
|
87
95
|
# h:* attributes (headers)
|
88
|
-
mail.mailgun_headers.try(:each) do |k, v|
|
89
|
-
msg_headers[k] = v
|
90
|
-
end
|
91
96
|
|
97
|
+
# Let's set all of these headers on the [Mail::Message] so that
|
98
|
+
# the are created inside of a [Mail::Header] instance and processed there.
|
99
|
+
mail.headers(mail.mailgun_headers || {})
|
92
100
|
mail.header_fields.each do |field|
|
93
|
-
|
101
|
+
header = field.name.downcase
|
102
|
+
if msg_headers.include? header
|
103
|
+
msg_headers[header] = [msg_headers[header], field.value].flatten
|
104
|
+
else
|
105
|
+
msg_headers[header] = field.value
|
106
|
+
end
|
94
107
|
end
|
95
108
|
|
96
109
|
msg_headers.each do |k, v|
|
data/mailgun.gemspec
CHANGED
@@ -24,9 +24,9 @@ Gem::Specification.new do |spec|
|
|
24
24
|
|
25
25
|
spec.required_ruby_version = '>= 2.2.2'
|
26
26
|
|
27
|
-
spec.add_development_dependency 'bundler', '
|
27
|
+
spec.add_development_dependency 'bundler', '>= 1.16.2'
|
28
28
|
spec.add_development_dependency 'rspec', '~> 3.8.0'
|
29
|
-
spec.add_development_dependency 'rake', '~> 12.3.
|
29
|
+
spec.add_development_dependency 'rake', '~> 12.3.2'
|
30
30
|
spec.add_development_dependency 'webmock', '~> 3.4.2'
|
31
31
|
spec.add_development_dependency 'pry', '~> 0.11.3'
|
32
32
|
spec.add_development_dependency 'vcr', '~> 3.0.3'
|
@@ -92,24 +92,24 @@ describe 'Railgun::Mailer' do
|
|
92
92
|
it 'adds headers to message body' do
|
93
93
|
message = UnitTestMailer.plain_message('test@example.org', '', {})
|
94
94
|
message.mailgun_headers ||= {
|
95
|
-
'
|
95
|
+
'x-unit-test' => 'true',
|
96
96
|
}
|
97
97
|
|
98
98
|
body = Railgun.transform_for_mailgun(message)
|
99
99
|
|
100
|
-
expect(body).to include('h:
|
101
|
-
expect(body['h:
|
100
|
+
expect(body).to include('h:x-unit-test')
|
101
|
+
expect(body['h:x-unit-test']).to eq('true')
|
102
102
|
end
|
103
103
|
|
104
104
|
it 'adds headers to message body from mailer' do
|
105
105
|
message = UnitTestMailer.plain_message('test@example.org', '', {
|
106
|
-
'
|
106
|
+
'x-unit-test-2' => 'true',
|
107
107
|
})
|
108
108
|
|
109
109
|
body = Railgun.transform_for_mailgun(message)
|
110
110
|
|
111
|
-
expect(body).to include('h:
|
112
|
-
expect(body['h:
|
111
|
+
expect(body).to include('h:x-unit-test-2')
|
112
|
+
expect(body['h:x-unit-test-2']).to eq('true')
|
113
113
|
end
|
114
114
|
|
115
115
|
it 'properly handles headers that are passed as separate POST params' do
|
@@ -131,7 +131,7 @@ describe 'Railgun::Mailer' do
|
|
131
131
|
expect(body).not_to include("h:#{header}")
|
132
132
|
end
|
133
133
|
|
134
|
-
['bcc', 'cc', 'to', 'h:
|
134
|
+
['bcc', 'cc', 'to', 'h:x-source'].each do |param|
|
135
135
|
expect(body).to include(param)
|
136
136
|
end
|
137
137
|
|
@@ -142,7 +142,7 @@ describe 'Railgun::Mailer' do
|
|
142
142
|
expect(body[:html]).to eq(['<p>Test!</p>'.html_safe])
|
143
143
|
expect(body['bcc']).to eq(['list@example.org'])
|
144
144
|
expect(body['cc']).to eq(['admin@example.com'])
|
145
|
-
expect(body['h:
|
145
|
+
expect(body['h:x-source']).to eq('unit tests')
|
146
146
|
end
|
147
147
|
|
148
148
|
it 'properly adds attachments' do
|
@@ -163,4 +163,55 @@ describe 'Railgun::Mailer' do
|
|
163
163
|
expect(ActionMailer::Base.deliveries).to include(message)
|
164
164
|
end
|
165
165
|
|
166
|
+
it 'ignores `reply-to` in headers' do
|
167
|
+
message = UnitTestMailer.plain_message('test@example.org', '', {
|
168
|
+
'reply-to' => 'user@example.com',
|
169
|
+
})
|
170
|
+
message.mailgun_headers = {
|
171
|
+
'Reply-To' => 'administrator@example.org',
|
172
|
+
}
|
173
|
+
message.headers({'REPLY-TO' => 'admin@example.net'})
|
174
|
+
message.reply_to = "dude@example.com.au"
|
175
|
+
|
176
|
+
body = Railgun.transform_for_mailgun(message)
|
177
|
+
expect(body).to include('h:reply-to')
|
178
|
+
expect(body).not_to include('h:Reply-To')
|
179
|
+
expect(body['h:reply-to']).to eq('dude@example.com.au')
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'treats `headers()` names as case-insensitve' do
|
183
|
+
message = UnitTestMailer.plain_message('test@example.org', '', {
|
184
|
+
'X-BIG-VALUE' => 1,
|
185
|
+
})
|
186
|
+
|
187
|
+
body = Railgun.transform_for_mailgun(message)
|
188
|
+
expect(body).to include('h:x-big-value')
|
189
|
+
expect(body['h:x-big-value']).to eq("1")
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'treats `mailgun_headers` names as case-insensitive' do
|
193
|
+
message = UnitTestMailer.plain_message('test@example.org', '', {})
|
194
|
+
message.mailgun_headers = {
|
195
|
+
'X-BIG-VALUE' => 1,
|
196
|
+
}
|
197
|
+
|
198
|
+
body = Railgun.transform_for_mailgun(message)
|
199
|
+
expect(body).to include('h:x-big-value')
|
200
|
+
expect(body['h:x-big-value']).to eq("1")
|
201
|
+
end
|
202
|
+
|
203
|
+
it 'handles multi-value, mixed case headers correctly' do
|
204
|
+
message = UnitTestMailer.plain_message('test@example.org', '', {})
|
205
|
+
message.headers({
|
206
|
+
'x-neat-header' => 'foo',
|
207
|
+
'X-Neat-Header' => 'bar',
|
208
|
+
'X-NEAT-HEADER' => 'zoop',
|
209
|
+
})
|
210
|
+
|
211
|
+
body = Railgun.transform_for_mailgun(message)
|
212
|
+
expect(body).to include('h:x-neat-header')
|
213
|
+
expect(body['h:x-neat-header']).to include('foo')
|
214
|
+
expect(body['h:x-neat-header']).to include('bar')
|
215
|
+
expect(body['h:x-neat-header']).to include('zoop')
|
216
|
+
end
|
166
217
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailgun-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mailgun
|
@@ -9,20 +9,20 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2019-08-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "
|
18
|
+
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: 1.16.2
|
21
21
|
type: :development
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- - "
|
25
|
+
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: 1.16.2
|
28
28
|
- !ruby/object:Gem::Dependency
|
@@ -45,14 +45,14 @@ dependencies:
|
|
45
45
|
requirements:
|
46
46
|
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: 12.3.
|
48
|
+
version: 12.3.2
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 12.3.
|
55
|
+
version: 12.3.2
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: webmock
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|