griddler-mandrill 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/griddler/mandrill/adapter.rb +5 -4
- data/lib/griddler/mandrill/version.rb +1 -1
- data/spec/griddler/mandrill/adapter_spec.rb +93 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5734cf6f504c80285028a0c25dc9080553d99aa
|
4
|
+
data.tar.gz: 6b0189f1ff8fda257ad92c9301bff5c88f46b19a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc106bc175e483060107cc6a931d0fa6dfd26534365364a1a726e7d8533d9bce5080efbdef5e396c2d7eedb628e42b290264f5fbe9119c43ec0f7b675868680f
|
7
|
+
data.tar.gz: c0369360d8329cb6dd39011c6d7323ec6c7a102be4a31d299f5806228e817d13d48f25c451449c5a25196376fb4c26d31c3aa6737a6cfad3d2a1568ad1d7e00a
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## 1.0.2
|
2
|
+
* Replace slashes in filenames with underscores for temp file creation. #5 and
|
3
|
+
#6 via [ssidelnikov](https://github.com/ssidelnikov)
|
4
|
+
* Only process inbound events. #9 via [mgauthier-joist](https://github.com/mgauthier-joist)
|
5
|
+
* Support BCC attribute
|
6
|
+
|
1
7
|
## 1.0.1
|
2
8
|
* Respect Mandrill's base64 flag to determine whether text attachments should be
|
3
9
|
base64 decoded. #4 via [bdmac](https://github.com/bdmac)
|
@@ -15,6 +15,7 @@ module Griddler
|
|
15
15
|
{
|
16
16
|
to: recipients(:to, event),
|
17
17
|
cc: recipients(:cc, event),
|
18
|
+
bcc: recipients(:bcc, event),
|
18
19
|
from: full_email([ event[:from_email], event[:from_name] ]),
|
19
20
|
subject: event[:subject],
|
20
21
|
text: event.fetch(:text, ''),
|
@@ -30,9 +31,9 @@ module Griddler
|
|
30
31
|
attr_reader :params
|
31
32
|
|
32
33
|
def events
|
33
|
-
@events ||= ActiveSupport::JSON.decode(params[:mandrill_events]).map
|
34
|
-
event['msg'].with_indifferent_access
|
35
|
-
|
34
|
+
@events ||= ActiveSupport::JSON.decode(params[:mandrill_events]).map { |event|
|
35
|
+
event['msg'].with_indifferent_access if event['event'] == 'inbound'
|
36
|
+
}.compact
|
36
37
|
end
|
37
38
|
|
38
39
|
def recipients(field, event)
|
@@ -60,7 +61,7 @@ module Griddler
|
|
60
61
|
end
|
61
62
|
|
62
63
|
def create_tempfile(attachment)
|
63
|
-
filename = attachment[:name]
|
64
|
+
filename = attachment[:name].gsub(/\/|\\/, '_')
|
64
65
|
tempfile = Tempfile.new(filename, Dir::tmpdir, encoding: 'ascii-8bit')
|
65
66
|
content = attachment[:content]
|
66
67
|
content = Base64.decode64(content) if attachment[:base64]
|
@@ -9,16 +9,19 @@ end
|
|
9
9
|
describe Griddler::Mandrill::Adapter, '.normalize_params' do
|
10
10
|
it 'normalizes parameters' do
|
11
11
|
Griddler::Mandrill::Adapter.normalize_params(default_params).each do |params|
|
12
|
-
expect(params).to be_normalized_to(
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
12
|
+
expect(params).to be_normalized_to(params_hash_normalized)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'does not process events that are not inbound' do
|
17
|
+
params = mixed_event_params
|
18
|
+
|
19
|
+
normalized_params = Griddler::Mandrill::Adapter.normalize_params(params)
|
20
|
+
|
21
|
+
expect(JSON.parse(params[:mandrill_events]).size).to eq(4)
|
22
|
+
expect(normalized_params.size).to eq(2)
|
23
|
+
normalized_params.each do |params|
|
24
|
+
expect(params).to be_normalized_to(params_hash_normalized)
|
22
25
|
end
|
23
26
|
end
|
24
27
|
|
@@ -55,6 +58,13 @@ describe Griddler::Mandrill::Adapter, '.normalize_params' do
|
|
55
58
|
expect(file.size).to eq(upload_3_params[:length])
|
56
59
|
end
|
57
60
|
|
61
|
+
it 'works with filenames containing slashes' do
|
62
|
+
params = params_with_attachments_with_slashes
|
63
|
+
|
64
|
+
adapter = Griddler::Mandrill::Adapter.new(params)
|
65
|
+
expect{adapter.normalize_params}.to_not raise_error
|
66
|
+
end
|
67
|
+
|
58
68
|
describe 'when the email has no text part' do
|
59
69
|
before do
|
60
70
|
@params = params_hash
|
@@ -104,10 +114,33 @@ describe Griddler::Mandrill::Adapter, '.normalize_params' do
|
|
104
114
|
mandrill_events (params * 2).to_json
|
105
115
|
end
|
106
116
|
|
117
|
+
def mixed_event_params
|
118
|
+
mandrill_events ((params_hash * 2) + (mixed_params_hash*2)).to_json
|
119
|
+
end
|
120
|
+
|
107
121
|
def mandrill_events(json)
|
108
122
|
{ mandrill_events: json }
|
109
123
|
end
|
110
124
|
|
125
|
+
def mixed_params_hash
|
126
|
+
[{
|
127
|
+
type: 'blacklist',
|
128
|
+
action: 'change',
|
129
|
+
reject: {
|
130
|
+
reason: 'hard-bounce',
|
131
|
+
detail: ' smtp;550 Requested action not taken: mailbox unavailable\n',
|
132
|
+
last_event_at: '2014-11-03 04:56:18',
|
133
|
+
email: 'herman@example.com',
|
134
|
+
created_at: '2014-08-07 04:59:20',
|
135
|
+
expires_at: '2014-11-24 04:56:18',
|
136
|
+
expired: false,
|
137
|
+
subaccount: nil,
|
138
|
+
sender: nil
|
139
|
+
},
|
140
|
+
ts: 1414990578
|
141
|
+
}]
|
142
|
+
end
|
143
|
+
|
111
144
|
def params_hash
|
112
145
|
[{
|
113
146
|
event: 'inbound',
|
@@ -123,6 +156,7 @@ describe Griddler::Mandrill::Adapter, '.normalize_params' do
|
|
123
156
|
to: [['token@reply.example.com', 'The Token']],
|
124
157
|
cc: [['emily@example.mandrillapp.com', 'Emily'],
|
125
158
|
['joey@example.mandrillapp.com', 'Joey']],
|
159
|
+
bcc: [['hidden@example.mandrillapp.com', 'Roger']],
|
126
160
|
subject: "hello",
|
127
161
|
spam_report: {
|
128
162
|
score: -0.8,
|
@@ -137,6 +171,20 @@ describe Griddler::Mandrill::Adapter, '.normalize_params' do
|
|
137
171
|
}]
|
138
172
|
end
|
139
173
|
|
174
|
+
def params_hash_normalized
|
175
|
+
{
|
176
|
+
to: ['The Token <token@reply.example.com>'],
|
177
|
+
cc: ['Emily <emily@example.mandrillapp.com>',
|
178
|
+
'Joey <joey@example.mandrillapp.com>'],
|
179
|
+
bcc: ['Roger <hidden@example.mandrillapp.com>'],
|
180
|
+
from: 'Hernan Example <hernan@example.com>',
|
181
|
+
subject: 'hello',
|
182
|
+
text: %r{Dear bob},
|
183
|
+
html: %r{<p>Dear bob</p>},
|
184
|
+
raw_body: %r{raw}
|
185
|
+
}
|
186
|
+
end
|
187
|
+
|
140
188
|
def params_with_attachments
|
141
189
|
params = params_hash
|
142
190
|
params[0][:msg][:attachments] = {
|
@@ -146,6 +194,15 @@ describe Griddler::Mandrill::Adapter, '.normalize_params' do
|
|
146
194
|
mandrill_events params.to_json
|
147
195
|
end
|
148
196
|
|
197
|
+
def params_with_attachments_with_slashes
|
198
|
+
params = params_hash
|
199
|
+
params[0][:msg][:attachments] = {
|
200
|
+
'=?UTF-8?B?0JrQvtC/0LjRjyB0ZW5kZXJfMTJfcm9zdGEueGxz?=' => upload_4_params,
|
201
|
+
'=?UTF-8?B?0JrQvtC\0LjRjyB0ZW5kZXJfMTJfcm9zdGEueGxz?=' => upload_5_params
|
202
|
+
}
|
203
|
+
mandrill_events params.to_json
|
204
|
+
end
|
205
|
+
|
149
206
|
def params_with_csv_attachment
|
150
207
|
params = params_hash
|
151
208
|
params[0][:msg][:attachments] = {
|
@@ -214,4 +271,30 @@ describe Griddler::Mandrill::Adapter, '.normalize_params' do
|
|
214
271
|
}
|
215
272
|
end
|
216
273
|
end
|
274
|
+
|
275
|
+
def upload_4_params
|
276
|
+
@upload_4_params ||= begin
|
277
|
+
content = 'Some | csv | file | here'
|
278
|
+
{
|
279
|
+
name: '=?UTF-8?B?0JrQvtC/0LjRjyB0ZW5kZXJfMTJfcm9zdGEueGxz?=',
|
280
|
+
content: content,
|
281
|
+
type: 'image/jpeg',
|
282
|
+
type: 'text/plain',
|
283
|
+
base64: false
|
284
|
+
}
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
def upload_5_params
|
289
|
+
@upload_5_params ||= begin
|
290
|
+
content = 'Some | csv | file | here'
|
291
|
+
{
|
292
|
+
name: '=?UTF-8?B?0JrQvtC\0LjRjyB0ZW5kZXJfMTJfcm9zdGEueGxz?=',
|
293
|
+
content: content,
|
294
|
+
type: 'text/plain',
|
295
|
+
length: content.length,
|
296
|
+
base64: false
|
297
|
+
}
|
298
|
+
end
|
299
|
+
end
|
217
300
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: griddler-mandrill
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stafford Brunk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: griddler
|