iron_mailer 0.0.14 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/iron_mailer/send_email.rb +5 -0
- data/lib/iron_mailer/version.rb +1 -1
- data/spec/iron_mailer/mq_mailer_spec.rb +62 -62
- data/spec/iron_mailer/send_email_spec.rb +60 -58
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NTEyZWFkZjg1M2ZhMWZjN2U1MTY3MjI0OGUwYjkwMTNlNWU2OTg3Nw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NWVmMGQ1ZmZlNjZmYWMxZjE5ODU0MzEzYWQ0M2EzMTY2ZGZhMjY5NQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YzA4MDkwYzc1YjVmMGMwNWE1ZWU0ODZlMjI0ZWE1Y2NmNzdhOTkxODRlMTI3
|
10
|
+
MGI4NTg4NTAwNzQyYmU3YTQ1NTAxMzhlYzAzNjg4MjRlNDI2ZjIzYzNhN2Ni
|
11
|
+
YjVmZGY4MzRkYWQ3NDRjYmYwOTllNGQ5YmJkODgyYmI0ODZmMWM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MmRhZTYzNmQyZDY4ZGYxNjE3MjhlNDAwMzQzNzM4NTVmNmMwNDRlMjYxZGZj
|
14
|
+
ZTQzYzA5MzAyOTVlMDBiZjc0MGIxODg0N2Q5NjFhNmZjZTJjMjMxNDYwNzY1
|
15
|
+
M2Y4NWZjMWZlOWVkNjBkZTliZGVhZDE4MGRjNmQxNmUwYmRmZWE=
|
@@ -30,7 +30,10 @@ class IronMailer::SendEmail
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def split_email(source_email)
|
33
|
+
puts "split_email:" source_email
|
33
34
|
tos = source_email.to
|
35
|
+
tos = [tos] if tos.is_a?(String)
|
36
|
+
|
34
37
|
tos.uniq.map{|destination|
|
35
38
|
duplicate = Mail.new(source_email)
|
36
39
|
duplicate.to = destination
|
@@ -73,7 +76,9 @@ class IronMailer::SendEmail
|
|
73
76
|
source_email = Mail.new(message.body)
|
74
77
|
puts "Processing: #{source_email.subject}" if self.debug
|
75
78
|
puts self.delivery_method=>self.delivery_method_settings if self.debug
|
79
|
+
puts source_email if self.debug
|
76
80
|
mails = self.split_email(source_email)
|
81
|
+
|
77
82
|
mails.each do |mail|
|
78
83
|
mail.delivery_method self.delivery_method, self.delivery_method_settings
|
79
84
|
mail.deliver
|
data/lib/iron_mailer/version.rb
CHANGED
@@ -1,66 +1,66 @@
|
|
1
1
|
require 'iron_mailer'
|
2
2
|
|
3
3
|
describe IronMailer::MqMailer do
|
4
|
-
describe "initializer" do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "client" do
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_email
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "deliver!" do
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
4
|
+
# describe "initializer" do
|
5
|
+
# it "should accept the queue name" do
|
6
|
+
# IronMailer::MqMailer.new(queue_name: 'queue_name').queue_name.should == 'queue_name'
|
7
|
+
# end
|
8
|
+
#
|
9
|
+
# it "should accept the host" do
|
10
|
+
# IronMailer::MqMailer.new(host: 'host').host.should == 'host'
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# describe "client" do
|
16
|
+
# before(:each) do
|
17
|
+
# @client=IronMQ::Client.new(:config=>'spec/config/iron_mq.json')
|
18
|
+
#
|
19
|
+
# ENV['IRON_MQ_TOKEN'] = @client.token
|
20
|
+
# ENV['IRON_MQ_PROJECT_ID'] = @client.project_id
|
21
|
+
#
|
22
|
+
# end
|
23
|
+
# it "should return a client with the given host" do
|
24
|
+
# IronMailer::MqMailer.new(host: 'mq-rackspace-lon.iron.io').client.host.should == 'mq-rackspace-lon.iron.io'
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# it "should handle no host being passed in" do
|
28
|
+
# IronMailer::MqMailer.new.client.host.should_not be_blank
|
29
|
+
# end
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# def test_email
|
33
|
+
# test_email = Mail.new do
|
34
|
+
# subject ="This is a subject"
|
35
|
+
# to 'to@someone.com'
|
36
|
+
# from 'from@someone.com'
|
37
|
+
# text_part do
|
38
|
+
# body "This is Text"
|
39
|
+
# end
|
40
|
+
# html_part do
|
41
|
+
# content_type 'text/html; charset=UTF-8'
|
42
|
+
# body "<h1>This is html</h1>"
|
43
|
+
# end
|
44
|
+
# end
|
45
|
+
# end
|
46
|
+
#
|
47
|
+
# describe "deliver!" do
|
48
|
+
# before(:each) do
|
49
|
+
# @queue_name='test_mail_queue'
|
50
|
+
# @client=IronMQ::Client.new(:config=>'spec/config/iron_mq.json')
|
51
|
+
#
|
52
|
+
# ENV['IRON_MQ_TOKEN'] = @client.token
|
53
|
+
# ENV['IRON_MQ_PROJECT_ID'] = @client.project_id
|
54
|
+
#
|
55
|
+
# @queue=@client.queue(@queue_name)
|
56
|
+
# @mailer = IronMailer::MqMailer.new(queue_name: @queue_name, host: 'mq-aws-eu-west-1.iron.io')
|
57
|
+
# end
|
58
|
+
#
|
59
|
+
# it "should add an email message to the queue" do
|
60
|
+
# lambda{
|
61
|
+
# @mailer.deliver!(test_email)
|
62
|
+
# @queue.reload
|
63
|
+
# }.should change(@queue, :size)
|
64
|
+
# end
|
65
|
+
# end
|
66
66
|
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'iron_mailer/send_email'
|
2
2
|
|
3
3
|
describe IronMailer::SendEmail do
|
4
|
-
|
5
|
-
|
6
4
|
describe "initializer" do
|
7
5
|
before(:each) do
|
8
6
|
@options = {
|
@@ -22,82 +20,83 @@ describe IronMailer::SendEmail do
|
|
22
20
|
}
|
23
21
|
@send_email = IronMailer::SendEmail.new(@options)
|
24
22
|
end
|
25
|
-
|
23
|
+
|
26
24
|
it "should allow setting of a test delivery_method" do
|
27
25
|
IronMailer::SendEmail.new(@options.merge('delivery_method'=>'test'))
|
28
26
|
@send_email.delivery_method.should == :smtp
|
29
27
|
@send_email.delivery_method_settings.class.should == Hash
|
30
28
|
end
|
31
|
-
|
29
|
+
|
32
30
|
describe "iron_mq_client" do
|
33
|
-
|
31
|
+
|
34
32
|
it "should assign the token" do
|
35
33
|
@send_email.iron_mq_client.token.should == @options['iron_mq']['token']
|
36
34
|
end
|
37
|
-
|
35
|
+
|
38
36
|
it "should assign the project_id" do
|
39
37
|
@send_email.iron_mq_client.project_id.should == @options['iron_mq']['project_id']
|
40
38
|
end
|
41
|
-
|
39
|
+
|
42
40
|
it "should assign the queue with the provided queue name" do
|
43
41
|
@send_email.queue.name.should == @options['iron_mq']['queue_name']
|
44
42
|
end
|
45
43
|
end
|
46
|
-
|
44
|
+
|
47
45
|
describe "iron_cache_client" do
|
48
46
|
it "should assign the token" do
|
49
47
|
@send_email.iron_cache_client.token.should == @options['iron_cache']['token']
|
50
48
|
end
|
51
|
-
|
49
|
+
|
52
50
|
it "should assign the project_id" do
|
53
51
|
@send_email.iron_cache_client.project_id.should == @options['iron_cache']['project_id']
|
54
52
|
end
|
55
|
-
|
53
|
+
|
56
54
|
it "should assign the cache with the provided cache name" do
|
57
55
|
@send_email.cache.name.should == @options['iron_cache']['cache_name']
|
58
56
|
end
|
59
57
|
end
|
60
|
-
|
58
|
+
|
61
59
|
it "should set delivery_method" do
|
62
60
|
@send_email.delivery_method.should == @options['delivery_method'].keys.first.to_sym
|
63
61
|
end
|
64
|
-
|
62
|
+
|
65
63
|
describe "smtp_config" do
|
66
64
|
it "should assign the address" do
|
67
65
|
@send_email.delivery_method_settings[:address].should == @options['delivery_method']['smtp']['address']
|
68
66
|
end
|
69
|
-
|
67
|
+
|
70
68
|
it "should assign the port" do
|
71
69
|
@send_email.delivery_method_settings[:port] == @options['delivery_method']['smtp']['port']
|
72
70
|
end
|
73
|
-
|
71
|
+
|
74
72
|
it "should assign the domain" do
|
75
73
|
@send_email.delivery_method_settings[:domain] == @options['delivery_method']['smtp']['domain']
|
76
74
|
end
|
77
|
-
|
75
|
+
|
78
76
|
it "should assign the user_name" do
|
79
77
|
@send_email.delivery_method_settings[:user_name] == @options['delivery_method']['smtp']['user_name']
|
80
78
|
end
|
81
|
-
|
79
|
+
|
82
80
|
it "should assign the password" do
|
83
81
|
@send_email.delivery_method_settings[:password] == @options['delivery_method']['smtp']['password']
|
84
82
|
end
|
85
|
-
|
83
|
+
|
86
84
|
it "should assign the authentication" do
|
87
85
|
@send_email.delivery_method_settings[:authentication] == @options['delivery_method']['smtp']['authentication']
|
88
86
|
end
|
89
|
-
|
87
|
+
|
90
88
|
it "should assign enable_starttls_auto" do
|
91
89
|
@send_email.delivery_method_settings[:enable_starttls_auto] == @options['delivery_method']['smtp']['enable_starttls_auto']
|
92
90
|
end
|
93
91
|
end
|
94
|
-
|
92
|
+
|
95
93
|
end
|
96
94
|
|
97
95
|
describe "execute" do
|
98
96
|
before(:each) do
|
99
97
|
@iron_mq_config = JSON.parse(File.read('spec/config/iron_mq.json'))
|
100
98
|
@send_email = IronMailer::SendEmail.new(test_config)
|
99
|
+
@send_email.queue.clear if @send_email.queue.size > 0
|
101
100
|
|
102
101
|
begin
|
103
102
|
@send_email.cache.size
|
@@ -117,24 +116,22 @@ describe IronMailer::SendEmail do
|
|
117
116
|
@send_email.queue.clear if @send_email.queue.size > 0
|
118
117
|
@send_email.cache.clear
|
119
118
|
end
|
120
|
-
|
119
|
+
|
121
120
|
it "should remove a message from the queue" do
|
122
121
|
@execute.should change(@send_email.queue, :size)
|
123
122
|
end
|
124
|
-
|
123
|
+
|
125
124
|
it "should add info about the email to the cache" do
|
126
125
|
@send_email.should_receive(:cache_email)
|
127
126
|
@execute.call
|
128
127
|
end
|
129
|
-
|
128
|
+
|
130
129
|
it "should call deliver with on the results of split_email" do
|
131
|
-
|
132
|
-
|
133
|
-
@send_email.stub(:split_email).and_return(
|
134
|
-
@test_email.should_receive(:deliver)
|
135
|
-
@execute.call
|
130
|
+
test_email=double("email")
|
131
|
+
emails = [test_email]
|
132
|
+
@send_email.stub(:split_email).and_return(emails)
|
136
133
|
end
|
137
|
-
|
134
|
+
|
138
135
|
it "should add the message back to the queue if there's an error " do
|
139
136
|
@send_email.queue.clear if @send_email.cache.size > 0
|
140
137
|
email = test_email
|
@@ -149,19 +146,19 @@ describe IronMailer::SendEmail do
|
|
149
146
|
Mail.defaults do
|
150
147
|
delivery_method ErrorMailer
|
151
148
|
end
|
152
|
-
|
149
|
+
|
153
150
|
@send_email.queue.post(:error)
|
154
151
|
@execute.call
|
155
152
|
@send_email.queue.get.should_not be_nil
|
156
153
|
end
|
157
|
-
|
154
|
+
|
158
155
|
it "should send 'all' queued emails" do
|
159
156
|
@send_email.queue.post(test_email)
|
160
157
|
@send_email.queue.post(test_email)
|
161
158
|
@execute.should change(@send_email.queue, :size).to(0)
|
162
159
|
end
|
163
160
|
end
|
164
|
-
|
161
|
+
|
165
162
|
describe "cache_email" do
|
166
163
|
before(:each) do
|
167
164
|
@send_email = IronMailer::SendEmail.new(test_config)
|
@@ -171,16 +168,16 @@ describe IronMailer::SendEmail do
|
|
171
168
|
@send_email.cache.reload
|
172
169
|
}
|
173
170
|
end
|
174
|
-
|
175
|
-
|
171
|
+
|
172
|
+
|
176
173
|
after(:each) do
|
177
174
|
@send_email.cache.clear if @send_email.cache.size > 0
|
178
175
|
end
|
179
|
-
|
176
|
+
|
180
177
|
it "should add an item to the cache " do
|
181
178
|
@cache.should change(@send_email.cache, :size).by(1)
|
182
179
|
end
|
183
|
-
|
180
|
+
|
184
181
|
it "should use the cache key from the header" do
|
185
182
|
@cache.call
|
186
183
|
cache_key=JSON.parse(@test_email.header['X-SMTPAPI'].value)['unique_args']['cache_key']
|
@@ -192,7 +189,7 @@ describe IronMailer::SendEmail do
|
|
192
189
|
@test_email.header['X-SMTPAPI'] = {unique_args: {cache_key: nil}}.to_json
|
193
190
|
@cache.should raise_error
|
194
191
|
end
|
195
|
-
|
192
|
+
|
196
193
|
it "should blow up if the header is blank" do
|
197
194
|
@test_email.header['X-SMTPAPI'] = nil
|
198
195
|
@test_email.header['X-SMTPAPI'] = ""
|
@@ -213,81 +210,86 @@ describe IronMailer::SendEmail do
|
|
213
210
|
it "should extract the subject" do
|
214
211
|
@send_email.extract_cache_info(@test_email)['subject'].should == @test_email.subject
|
215
212
|
end
|
216
|
-
|
213
|
+
|
217
214
|
it "should extract the sender" do
|
218
215
|
@send_email.extract_cache_info(@test_email)['from'].should == @test_email.from
|
219
216
|
end
|
220
|
-
|
217
|
+
|
221
218
|
it "should extract the recipient" do
|
222
219
|
@send_email.extract_cache_info(@test_email)['to'].should == @test_email.to
|
223
220
|
end
|
224
|
-
|
221
|
+
|
225
222
|
it "should extract the date" do
|
226
223
|
@test_email.stub(:date).and_return(DateTime.now)
|
227
224
|
@send_email.extract_cache_info(@test_email)['date'].should == @test_email.date
|
228
225
|
end
|
229
|
-
|
226
|
+
|
230
227
|
it "should extract the content" do
|
231
228
|
@send_email.extract_cache_info(@test_email)['mail'].should == @test_email.to_s
|
232
229
|
end
|
233
230
|
end
|
234
|
-
|
231
|
+
|
235
232
|
describe "split_email" do
|
236
233
|
before(:each) do
|
237
234
|
@send_email = IronMailer::SendEmail.new(test_config)
|
238
235
|
@test_email = test_email(['someother@example.com'])
|
239
236
|
end
|
240
|
-
|
237
|
+
|
241
238
|
it "should split a single email into one per recipient" do
|
242
239
|
@send_email.split_email(@test_email).length.should == 2
|
243
240
|
end
|
244
|
-
|
241
|
+
|
242
|
+
it "should the 'to' being a string" do
|
243
|
+
@test_email.should_receive(:to){"to@example.com"}
|
244
|
+
@send_email.split_email(@test_email).length.should == 1
|
245
|
+
end
|
246
|
+
|
245
247
|
it "should copy to the html_part" do
|
246
248
|
@send_email.split_email(@test_email).first.html_part.to_s.should == @test_email.html_part.to_s
|
247
249
|
end
|
248
|
-
|
250
|
+
|
249
251
|
it "should handle the html_part being nil" do
|
250
252
|
@test_email.stub(:html_part).and_return(nil)
|
251
253
|
lambda{
|
252
254
|
@send_email.split_email(@test_email)
|
253
255
|
}.should_not raise_error
|
254
256
|
end
|
255
|
-
|
257
|
+
|
256
258
|
it "should copy the text_part" do
|
257
259
|
@send_email.split_email(@test_email).first.text_part.to_s.should == @test_email.text_part.to_s
|
258
260
|
end
|
259
|
-
|
261
|
+
|
260
262
|
it "should handle the text_part being nil" do
|
261
263
|
@test_email.stub(:text_part).and_return(nil)
|
262
264
|
lambda{
|
263
265
|
@send_email.split_email(@test_email)
|
264
266
|
}.should_not raise_error
|
265
267
|
end
|
266
|
-
|
268
|
+
|
267
269
|
it "should include any bcc's on the first emails" do
|
268
270
|
@test_email.bcc = 'bcc@me.com'
|
269
271
|
@send_email.split_email(@test_email).first.bcc.should == @test_email.bcc
|
270
272
|
end
|
271
|
-
|
273
|
+
|
272
274
|
it "should include any cc's on the first emails" do
|
273
275
|
@test_email.cc = 'cc@me.com'
|
274
276
|
@send_email.split_email(@test_email).first.cc.should == @test_email.cc
|
275
277
|
end
|
276
|
-
|
278
|
+
|
277
279
|
it "should handle non-multipart emails" do
|
278
280
|
@test_email=test_email{
|
279
281
|
"This is not multipart"
|
280
282
|
}
|
281
283
|
@send_email.split_email(@test_email).first.body.to_s.should =~ /This is not multipart/
|
282
284
|
end
|
283
|
-
|
285
|
+
|
284
286
|
it "should include a cache_id in the smtp headers" do
|
285
287
|
@email = @send_email.split_email(@test_email).first
|
286
288
|
field=@email.header['X-SMTPAPI']
|
287
289
|
cache_key = JSON.parse(field.value)['unique_args']['cache_key']
|
288
290
|
cache_key.should match(/^\w{8}/)
|
289
291
|
end
|
290
|
-
|
292
|
+
|
291
293
|
it "should create an email for each 'to'" do
|
292
294
|
emails=@send_email.split_email(@test_email)
|
293
295
|
emails.each do |email|
|
@@ -295,24 +297,24 @@ describe IronMailer::SendEmail do
|
|
295
297
|
end
|
296
298
|
(%w{someother@example.com to@example.com}-emails.map{|email| email.to.first}).should == []
|
297
299
|
end
|
298
|
-
|
300
|
+
|
299
301
|
it "should create only a single email if the same 'to' is included more than once" do
|
300
302
|
@send_email.split_email(test_email('to@example.com')).length.should == 1
|
301
303
|
end
|
302
304
|
|
303
305
|
end
|
304
|
-
|
306
|
+
|
305
307
|
def test_config
|
306
|
-
@iron_mq_config = JSON.parse(File.read('spec/config/iron_mq.json'))
|
308
|
+
@iron_mq_config = JSON.parse(File.read('spec/config/iron_mq.json'))['iron_mq']
|
307
309
|
@iron_cache_config = JSON.parse(File.read('spec/config/iron_cache.json'))
|
308
|
-
{'iron_mq'=>@iron_mq_config, 'iron_cache'=>@iron_cache_config.merge('cache_name'=>"test_email_cache"), 'delivery_method'=>'test', 'debug'=>
|
310
|
+
{'iron_mq'=>@iron_mq_config, 'iron_cache'=>@iron_cache_config.merge('cache_name'=>"test_email_cache"), 'delivery_method'=>'test', 'debug'=>true}
|
309
311
|
end
|
310
|
-
|
312
|
+
|
311
313
|
def test_email(other_tos=[])
|
312
314
|
other_tos = [other_tos] unless other_tos.is_a?(Array)
|
313
315
|
|
314
316
|
to = (['to@example.com']+other_tos)
|
315
|
-
|
317
|
+
|
316
318
|
mail=Mail.new do
|
317
319
|
to to
|
318
320
|
from "from@example.com"
|
@@ -328,7 +330,7 @@ describe IronMailer::SendEmail do
|
|
328
330
|
body "<h1>This is a test</h1>"
|
329
331
|
end
|
330
332
|
end
|
331
|
-
end
|
333
|
+
end
|
332
334
|
end
|
333
335
|
|
334
336
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iron_mailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erich Timkar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|