multi_mail 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +57 -34
  3. data/bin/multi_mail_post +71 -0
  4. data/lib/mail_ext/message.rb +11 -0
  5. data/lib/multi_mail.rb +25 -8
  6. data/lib/multi_mail/cloudmailin/receiver.rb +24 -3
  7. data/lib/multi_mail/mailgun/message.rb +6 -1
  8. data/lib/multi_mail/mailgun/sender.rb +4 -4
  9. data/lib/multi_mail/mandrill/message.rb +4 -3
  10. data/lib/multi_mail/mandrill/sender.rb +9 -2
  11. data/lib/multi_mail/message/base.rb +14 -0
  12. data/lib/multi_mail/postmark/message.rb +74 -0
  13. data/lib/multi_mail/postmark/receiver.rb +2 -1
  14. data/lib/multi_mail/postmark/sender.rb +54 -24
  15. data/lib/multi_mail/sendgrid/message.rb +4 -4
  16. data/lib/multi_mail/sendgrid/sender.rb +2 -2
  17. data/lib/multi_mail/simple/receiver.rb +31 -1
  18. data/lib/multi_mail/version.rb +1 -1
  19. data/multi_mail.gemspec +2 -1
  20. data/spec/cloudmailin/receiver_spec.rb +89 -84
  21. data/spec/fixtures/cloudmailin/json/attachment_store.txt +65 -0
  22. data/spec/fixtures/cloudmailin/multipart/attachment_store.txt +174 -0
  23. data/spec/fixtures/cloudmailin/raw/attachment_store.txt +162 -0
  24. data/spec/fixtures/mailgun/parsed/valid.txt +107 -101
  25. data/spec/fixtures/simple/invalid.txt +4 -0
  26. data/spec/fixtures/simple/missing.txt +4 -0
  27. data/spec/fixtures/simple/valid.txt +1 -1
  28. data/spec/mail_ext/message_spec.rb +45 -0
  29. data/spec/mailgun/message_spec.rb +38 -8
  30. data/spec/mailgun/receiver_spec.rb +104 -110
  31. data/spec/mailgun/sender_spec.rb +13 -7
  32. data/spec/mandrill/message_spec.rb +25 -1
  33. data/spec/mandrill/receiver_spec.rb +81 -83
  34. data/spec/mandrill/sender_spec.rb +13 -6
  35. data/spec/message/base_spec.rb +33 -1
  36. data/spec/postmark/message_spec.rb +292 -0
  37. data/spec/postmark/receiver_spec.rb +46 -48
  38. data/spec/postmark/sender_spec.rb +10 -10
  39. data/spec/sendgrid/message_spec.rb +6 -1
  40. data/spec/sendgrid/receiver_spec.rb +56 -58
  41. data/spec/sendgrid/sender_spec.rb +9 -7
  42. data/spec/service_spec.rb +1 -1
  43. data/spec/simple/receiver_spec.rb +38 -25
  44. data/spec/spec_helper.rb +6 -8
  45. metadata +185 -203
@@ -0,0 +1,4 @@
1
+ HTTP/1.1 200 OK
2
+ Content-Type: application/x-www-form-urlencoded
3
+
4
+ message=Return-Path%3A+%3Cjames%40opennorth.ca%3E%0AReceived%3A+from+%5B192.168.0.104%5D+%28%5B69.165.204.186%5D%29%0A++++++++by+mx.google.com+with+ESMTPS+id+ez8sm24876706igb.17.2012.12.27.12.25.27%0A++++++++%28version%3DTLSv1%2FSSLv3+cipher%3DOTHER%29%3B%0A++++++++Thu%2C+27+Dec+2012+12%3A25%3A28+-0800+%28PST%29%0AFrom%3A+James+McKinney+%3Cjames%40opennorth.ca%3E%0AContent-Type%3A+multipart%2Falternative%3B+boundary%3D%22Apple-Mail%3D_9BF84D11-673B-4F5C-B5F7-46FA0E73983F%22%0ASubject%3A+Test%0ADate%3A+Thu%2C+27+Dec+2012+15%3A25%3A37+-0500%0AMessage-Id%3A+%3C24D8D853-1C75-4F64-ABA5-33A6C81471FA%40opennorth.ca%3E%0ATo%3A+foo%2Bbar%40govkit.org%0AMime-Version%3A+1.0+%28Apple+Message+framework+v1283%29%0AX-Mailer%3A+Apple+Mail+%282.1283%29%0A%0A%0A--Apple-Mail%3D_9BF84D11-673B-4F5C-B5F7-46FA0E73983F%0AContent-Transfer-Encoding%3A+7bit%0AContent-Type%3A+text%2Fplain%3B%0A++charset%3Dus-ascii%0A%0Abold+text%0A%0A%0A%3E+multiline%0A%3E+quoted%0A%3E+text%0A%0A--%0ASignature+block%0A--Apple-Mail%3D_9BF84D11-673B-4F5C-B5F7-46FA0E73983F%0AContent-Transfer-Encoding%3A+7bit%0AContent-Type%3A+text%2Fhtml%3B%0A++charset%3Dus-ascii%0A%0A%3Chtml%3E%3Chead%3E%3C%2Fhead%3E%3Cbody+style%3D%22word-wrap%3A+break-word%3B+-webkit-nbsp-mode%3A+space%3B+-webkit-line-break%3A+after-white-space%3B+%22%3E%3Cdiv%3E%3Cb%3Ebold+text%3C%2Fb%3E%3C%2Fdiv%3E%3Cdiv%3E%3Cbr%3E%3C%2Fdiv%3E%3Cdiv%3E%3Cblockquote+type%3D%22cite%22%3E%3C%2Fblockquote%3E%3C%2Fdiv%3E%3Cdiv%3E%3Cblockquote+type%3D%22cite%22%3Emultiline%3C%2Fblockquote%3E%3C%2Fdiv%3E%3Cblockquote+type%3D%22cite%22%3E%3Cdiv%3Equoted%3C%2Fdiv%3E%3Cdiv%3Etext%3C%2Fdiv%3E%3C%2Fblockquote%3E%3Cbr%3E%3Cdiv%3E--%3C%2Fdiv%3E%3Cdiv%3ESignature+block%3C%2Fdiv%3E%3C%2Fbody%3E%3C%2Fhtml%3E%0A--Apple-Mail%3D_9BF84D11-673B-4F5C-B5F7-46FA0E73983F--%0A&timestamp=1366071615&token=5o56tmpwd3dnwthehwclemd-i-7u2gv9vb3u745ywj67d0mc87&signature=xxx
@@ -0,0 +1,4 @@
1
+ HTTP/1.1 200 OK
2
+ Content-Type: application/x-www-form-urlencoded
3
+
4
+ message=Return-Path%3A+%3Cjames%40opennorth.ca%3E%0AReceived%3A+from+%5B192.168.0.104%5D+%28%5B69.165.204.186%5D%29%0A++++++++by+mx.google.com+with+ESMTPS+id+ez8sm24876706igb.17.2012.12.27.12.25.27%0A++++++++%28version%3DTLSv1%2FSSLv3+cipher%3DOTHER%29%3B%0A++++++++Thu%2C+27+Dec+2012+12%3A25%3A28+-0800+%28PST%29%0AFrom%3A+James+McKinney+%3Cjames%40opennorth.ca%3E%0AContent-Type%3A+multipart%2Falternative%3B+boundary%3D%22Apple-Mail%3D_9BF84D11-673B-4F5C-B5F7-46FA0E73983F%22%0ASubject%3A+Test%0ADate%3A+Thu%2C+27+Dec+2012+15%3A25%3A37+-0500%0AMessage-Id%3A+%3C24D8D853-1C75-4F64-ABA5-33A6C81471FA%40opennorth.ca%3E%0ATo%3A+foo%2Bbar%40govkit.org%0AMime-Version%3A+1.0+%28Apple+Message+framework+v1283%29%0AX-Mailer%3A+Apple+Mail+%282.1283%29%0A%0A%0A--Apple-Mail%3D_9BF84D11-673B-4F5C-B5F7-46FA0E73983F%0AContent-Transfer-Encoding%3A+7bit%0AContent-Type%3A+text%2Fplain%3B%0A++charset%3Dus-ascii%0A%0Abold+text%0A%0A%0A%3E+multiline%0A%3E+quoted%0A%3E+text%0A%0A--%0ASignature+block%0A--Apple-Mail%3D_9BF84D11-673B-4F5C-B5F7-46FA0E73983F%0AContent-Transfer-Encoding%3A+7bit%0AContent-Type%3A+text%2Fhtml%3B%0A++charset%3Dus-ascii%0A%0A%3Chtml%3E%3Chead%3E%3C%2Fhead%3E%3Cbody+style%3D%22word-wrap%3A+break-word%3B+-webkit-nbsp-mode%3A+space%3B+-webkit-line-break%3A+after-white-space%3B+%22%3E%3Cdiv%3E%3Cb%3Ebold+text%3C%2Fb%3E%3C%2Fdiv%3E%3Cdiv%3E%3Cbr%3E%3C%2Fdiv%3E%3Cdiv%3E%3Cblockquote+type%3D%22cite%22%3E%3C%2Fblockquote%3E%3C%2Fdiv%3E%3Cdiv%3E%3Cblockquote+type%3D%22cite%22%3Emultiline%3C%2Fblockquote%3E%3C%2Fdiv%3E%3Cblockquote+type%3D%22cite%22%3E%3Cdiv%3Equoted%3C%2Fdiv%3E%3Cdiv%3Etext%3C%2Fdiv%3E%3C%2Fblockquote%3E%3Cbr%3E%3Cdiv%3E--%3C%2Fdiv%3E%3Cdiv%3ESignature+block%3C%2Fdiv%3E%3C%2Fbody%3E%3C%2Fhtml%3E%0A--Apple-Mail%3D_9BF84D11-673B-4F5C-B5F7-46FA0E73983F--%0A
@@ -1,4 +1,4 @@
1
1
  HTTP/1.1 200 OK
2
2
  Content-Type: application/x-www-form-urlencoded
3
3
 
4
- message=Return-Path%3A+%3Cjames%40opennorth.ca%3E%0AReceived%3A+from+%5B192.168.0.104%5D+%28%5B69.165.204.186%5D%29%0A++++++++by+mx.google.com+with+ESMTPS+id+ez8sm24876706igb.17.2012.12.27.12.25.27%0A++++++++%28version%3DTLSv1%2FSSLv3+cipher%3DOTHER%29%3B%0A++++++++Thu%2C+27+Dec+2012+12%3A25%3A28+-0800+%28PST%29%0AFrom%3A+James+McKinney+%3Cjames%40opennorth.ca%3E%0AContent-Type%3A+multipart%2Falternative%3B+boundary%3D%22Apple-Mail%3D_9BF84D11-673B-4F5C-B5F7-46FA0E73983F%22%0ASubject%3A+Test%0ADate%3A+Thu%2C+27+Dec+2012+15%3A25%3A37+-0500%0AMessage-Id%3A+%3C24D8D853-1C75-4F64-ABA5-33A6C81471FA%40opennorth.ca%3E%0ATo%3A+foo%2Bbar%40govkit.org%0AMime-Version%3A+1.0+%28Apple+Message+framework+v1283%29%0AX-Mailer%3A+Apple+Mail+%282.1283%29%0A%0A%0A--Apple-Mail%3D_9BF84D11-673B-4F5C-B5F7-46FA0E73983F%0AContent-Transfer-Encoding%3A+7bit%0AContent-Type%3A+text%2Fplain%3B%0A++charset%3Dus-ascii%0A%0Abold+text%0A%0A%0A%3E+multiline%0A%3E+quoted%0A%3E+text%0A%0A--%0ASignature+block%0A--Apple-Mail%3D_9BF84D11-673B-4F5C-B5F7-46FA0E73983F%0AContent-Transfer-Encoding%3A+7bit%0AContent-Type%3A+text%2Fhtml%3B%0A++charset%3Dus-ascii%0A%0A%3Chtml%3E%3Chead%3E%3C%2Fhead%3E%3Cbody+style%3D%22word-wrap%3A+break-word%3B+-webkit-nbsp-mode%3A+space%3B+-webkit-line-break%3A+after-white-space%3B+%22%3E%3Cdiv%3E%3Cb%3Ebold+text%3C%2Fb%3E%3C%2Fdiv%3E%3Cdiv%3E%3Cbr%3E%3C%2Fdiv%3E%3Cdiv%3E%3Cblockquote+type%3D%22cite%22%3E%3C%2Fblockquote%3E%3C%2Fdiv%3E%3Cdiv%3E%3Cblockquote+type%3D%22cite%22%3Emultiline%3C%2Fblockquote%3E%3C%2Fdiv%3E%3Cblockquote+type%3D%22cite%22%3E%3Cdiv%3Equoted%3C%2Fdiv%3E%3Cdiv%3Etext%3C%2Fdiv%3E%3C%2Fblockquote%3E%3Cbr%3E%3Cdiv%3E--%3C%2Fdiv%3E%3Cdiv%3ESignature+block%3C%2Fdiv%3E%3C%2Fbody%3E%3C%2Fhtml%3E%0A--Apple-Mail%3D_9BF84D11-673B-4F5C-B5F7-46FA0E73983F--%0A
4
+ message=Return-Path%3A+%3Cjames%40opennorth.ca%3E%0AReceived%3A+from+%5B192.168.0.104%5D+%28%5B69.165.204.186%5D%29%0A++++++++by+mx.google.com+with+ESMTPS+id+ez8sm24876706igb.17.2012.12.27.12.25.27%0A++++++++%28version%3DTLSv1%2FSSLv3+cipher%3DOTHER%29%3B%0A++++++++Thu%2C+27+Dec+2012+12%3A25%3A28+-0800+%28PST%29%0AFrom%3A+James+McKinney+%3Cjames%40opennorth.ca%3E%0AContent-Type%3A+multipart%2Falternative%3B+boundary%3D%22Apple-Mail%3D_9BF84D11-673B-4F5C-B5F7-46FA0E73983F%22%0ASubject%3A+Test%0ADate%3A+Thu%2C+27+Dec+2012+15%3A25%3A37+-0500%0AMessage-Id%3A+%3C24D8D853-1C75-4F64-ABA5-33A6C81471FA%40opennorth.ca%3E%0ATo%3A+foo%2Bbar%40govkit.org%0AMime-Version%3A+1.0+%28Apple+Message+framework+v1283%29%0AX-Mailer%3A+Apple+Mail+%282.1283%29%0A%0A%0A--Apple-Mail%3D_9BF84D11-673B-4F5C-B5F7-46FA0E73983F%0AContent-Transfer-Encoding%3A+7bit%0AContent-Type%3A+text%2Fplain%3B%0A++charset%3Dus-ascii%0A%0Abold+text%0A%0A%0A%3E+multiline%0A%3E+quoted%0A%3E+text%0A%0A--%0ASignature+block%0A--Apple-Mail%3D_9BF84D11-673B-4F5C-B5F7-46FA0E73983F%0AContent-Transfer-Encoding%3A+7bit%0AContent-Type%3A+text%2Fhtml%3B%0A++charset%3Dus-ascii%0A%0A%3Chtml%3E%3Chead%3E%3C%2Fhead%3E%3Cbody+style%3D%22word-wrap%3A+break-word%3B+-webkit-nbsp-mode%3A+space%3B+-webkit-line-break%3A+after-white-space%3B+%22%3E%3Cdiv%3E%3Cb%3Ebold+text%3C%2Fb%3E%3C%2Fdiv%3E%3Cdiv%3E%3Cbr%3E%3C%2Fdiv%3E%3Cdiv%3E%3Cblockquote+type%3D%22cite%22%3E%3C%2Fblockquote%3E%3C%2Fdiv%3E%3Cdiv%3E%3Cblockquote+type%3D%22cite%22%3Emultiline%3C%2Fblockquote%3E%3C%2Fdiv%3E%3Cblockquote+type%3D%22cite%22%3E%3Cdiv%3Equoted%3C%2Fdiv%3E%3Cdiv%3Etext%3C%2Fdiv%3E%3C%2Fblockquote%3E%3Cbr%3E%3Cdiv%3E--%3C%2Fdiv%3E%3Cdiv%3ESignature+block%3C%2Fdiv%3E%3C%2Fbody%3E%3C%2Fhtml%3E%0A--Apple-Mail%3D_9BF84D11-673B-4F5C-B5F7-46FA0E73983F--%0A&timestamp=1366071615&token=5o56tmpwd3dnwthehwclemd-i-7u2gv9vb3u745ywj67d0mc87&signature=bc2ab6c1080d52f2a06928b93f21e86c2d28c548e2ef64354f8ba1a95bb53cd6
@@ -0,0 +1,45 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Mail::Message do
4
+ # @see https://github.com/mikel/mail/blob/master/spec/mail/message_spec.rb#L491
5
+ describe 'setting headers' do
6
+ it 'should accept them in block form' do
7
+ message = Mail.new do
8
+ tag 'foo'
9
+ end
10
+ message.tag.should == 'foo'
11
+ end
12
+
13
+ it 'should accept them in assignment form' do
14
+ message = Mail.new
15
+ message.tag = 'foo'
16
+ message.tag.should == 'foo'
17
+ end
18
+
19
+ it 'should accept them in key, value form as symbols' do
20
+ message = Mail.new
21
+ message[:tag] = 'foo'
22
+ message.tag.should == 'foo'
23
+ end
24
+
25
+ it 'should accept them in key, value form as strings' do
26
+ message = Mail.new
27
+ message['tag'] = 'foo'
28
+ message.tag.should == 'foo'
29
+ end
30
+
31
+ it 'should accept them as a hash with symbols' do
32
+ message = Mail.new({
33
+ :tag => 'foo',
34
+ })
35
+ message.tag.should == 'foo'
36
+ end
37
+
38
+ it 'should accept them as a hash with strings' do
39
+ message = Mail.new({
40
+ 'tag' => 'foo',
41
+ })
42
+ message.tag.should == 'foo'
43
+ end
44
+ end
45
+ end
@@ -1,5 +1,4 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
- require 'multi_mail/mailgun/message'
3
2
 
4
3
  describe MultiMail::Message::Mailgun do
5
4
  let :message do
@@ -121,6 +120,19 @@ describe MultiMail::Message::Mailgun do
121
120
  MultiMail::Message::Mailgun.new
122
121
  end
123
122
 
123
+ let :message_with_one_tag do
124
+ MultiMail::Message::Mailgun.new do
125
+ tag 'foo'
126
+ end
127
+ end
128
+
129
+ let :message_with_many_tags do
130
+ MultiMail::Message::Mailgun.new do
131
+ tag 'foo'
132
+ tag 'bar'
133
+ end
134
+ end
135
+
124
136
  describe '#mailgun_attachments' do
125
137
  it 'should return the attachments' do
126
138
  attachments = message.mailgun_attachments
@@ -196,13 +208,13 @@ describe MultiMail::Message::Mailgun do
196
208
  it 'should return the message as Mailgun parameters' do
197
209
  hash = message.to_mailgun_hash
198
210
 
199
- hash[:from].should == [%("John Doe" <foo@example.com>)]
200
- hash[:to].should == [%("Jane Doe" <bar@example.com>), '<baz@example.com>']
201
- hash[:cc].should == ['cc@example.com']
202
- hash[:bcc].should == ['bcc@example.com']
203
- hash[:subject].should == ['test']
204
- hash[:text].should == ['hello']
205
- hash[:html].should == ['<p>hello</p>']
211
+ hash[:from].should == [%("John Doe" <foo@example.com>)]
212
+ hash[:to].should == [%("Jane Doe" <bar@example.com>), '<baz@example.com>']
213
+ hash[:cc].should == ['cc@example.com']
214
+ hash[:bcc].should == ['bcc@example.com']
215
+ hash[:subject].should == ['test']
216
+ hash[:text].should == ['hello']
217
+ hash[:html].should == ['<p>hello</p>']
206
218
  hash[:'h:Reply-To'].should == ['noreply@example.com']
207
219
 
208
220
  Time.parse(hash[:'h:Date'][0]).should be_within(1).of(Time.at(946702800))
@@ -225,6 +237,12 @@ describe MultiMail::Message::Mailgun do
225
237
  hash.size.should == 16
226
238
  end
227
239
 
240
+ it 'should return the recipients without names' do
241
+ hash = message_without_names.to_mailgun_hash
242
+ hash[:from].should == ['foo@example.com']
243
+ hash[:to].should == ['bar@example.com', 'baz@example.com']
244
+ end
245
+
228
246
  it 'should convert the message without a text body' do
229
247
  message_without_text_body.to_mailgun_hash.should == {
230
248
  :from => ['foo@example.com'],
@@ -247,5 +265,17 @@ describe MultiMail::Message::Mailgun do
247
265
  it 'should convert an empty message' do
248
266
  empty_message.to_mailgun_hash.should == {}
249
267
  end
268
+
269
+ it 'should convert the message with one tag' do
270
+ message_with_one_tag.to_mailgun_hash.should == {
271
+ :'o:tag' => ['foo'],
272
+ }
273
+ end
274
+
275
+ it 'should convert the message with many tags' do
276
+ message_with_many_tags.to_mailgun_hash.should == {
277
+ :'o:tag' => ['foo', 'bar'],
278
+ }
279
+ end
250
280
  end
251
281
  end
@@ -2,141 +2,135 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
  require 'multi_mail/mailgun/receiver'
3
3
 
4
4
  describe MultiMail::Receiver::Mailgun do
5
- context 'after initialization' do
6
- context 'with invalid HTTP POST format' do
7
- let :service do
8
- MultiMail::Receiver.new({
9
- :provider => :mailgun,
10
- :mailgun_api_key => 'foo',
11
- :http_post_format => 'invalid',
12
- })
13
- end
5
+ context 'with invalid HTTP POST format' do
6
+ let :service do
7
+ MultiMail::Receiver.new({
8
+ :provider => :mailgun,
9
+ :mailgun_api_key => 'foo',
10
+ :http_post_format => 'invalid',
11
+ })
12
+ end
14
13
 
15
- describe '#transform' do
16
- it 'should raise an error if :http_post_format is invalid' do
17
- expect{ service.transform({}) }.to raise_error(ArgumentError)
18
- end
14
+ describe '#transform' do
15
+ it 'should raise an error if :http_post_format is invalid' do
16
+ expect{ service.transform({}) }.to raise_error(ArgumentError)
19
17
  end
20
18
  end
19
+ end
20
+
21
+ context 'without optional arguments' do
22
+ let :service do
23
+ MultiMail::Receiver.new(:provider => :mailgun)
24
+ end
25
+
26
+ def params(fixture)
27
+ MultiMail::Receiver::Mailgun.parse(response('mailgun/parsed', fixture))
28
+ end
21
29
 
22
- context 'without optional arguments' do
23
- let :service do
24
- MultiMail::Receiver.new(:provider => :mailgun)
30
+ describe '#valid?' do
31
+ it 'should return true if the response is valid' do
32
+ service.valid?(params('valid')).should == true
25
33
  end
26
34
 
27
- def params(fixture)
28
- MultiMail::Receiver::Mailgun.parse(response('mailgun/parsed', fixture))
35
+ it 'should return true if the response is invalid' do
36
+ service.valid?(params('invalid')).should == true
29
37
  end
30
38
 
31
- describe '#valid?' do
32
- it 'should return true if the response is valid' do
33
- service.valid?(params('valid')).should == true
34
- end
39
+ it 'should return true if parameters are missing' do
40
+ service.valid?(params('missing')).should == true
41
+ end
42
+ end
43
+ end
35
44
 
36
- it 'should return true if the response is invalid' do
37
- service.valid?(params('invalid')).should == true
38
- end
45
+ [false, true].each do |action_dispatch|
46
+ let :action_dispatch do
47
+ action_dispatch
48
+ end
39
49
 
40
- it 'should return true if parameters are missing' do
41
- service.valid?(params('missing')).should == true
50
+ ['parsed', 'raw', '', nil].each do |http_post_format|
51
+ context "with #{http_post_format.inspect} format and #{action_dispatch ? 'ActionDispatch' : 'Rack'}" do
52
+ let :actual_http_post_format do
53
+ http_post_format.to_s.empty? ? 'parsed' : http_post_format
42
54
  end
43
- end
44
- end
45
55
 
46
- [false, true].each do |action_dispatch|
47
- let :action_dispatch do
48
- action_dispatch
49
- end
56
+ let :service do
57
+ MultiMail::Receiver.new({
58
+ :provider => :mailgun,
59
+ :mailgun_api_key => 'foo',
60
+ :http_post_format => http_post_format,
61
+ })
62
+ end
50
63
 
51
- ['parsed', 'raw', '', nil].each do |http_post_format|
52
- context "with #{http_post_format.inspect} format and #{action_dispatch ? 'ActionDispatch' : 'Rack'}" do
53
- let :http_post_format do
54
- http_post_format
55
- end
64
+ def params(fixture)
65
+ MultiMail::Receiver::Mailgun.parse(response("mailgun/#{actual_http_post_format}", fixture, action_dispatch))
66
+ end
56
67
 
57
- let :actual_http_post_format do
58
- http_post_format.to_s.empty? ? 'parsed' : http_post_format
68
+ describe '#valid?' do
69
+ it 'should return true if the response is valid' do
70
+ service.valid?(params('valid')).should == true
59
71
  end
60
72
 
61
- let :service do
62
- MultiMail::Receiver.new({
63
- :provider => :mailgun,
64
- :mailgun_api_key => 'foo',
65
- :http_post_format => http_post_format,
66
- })
73
+ it 'should return false if the response is invalid' do
74
+ service.valid?(params('invalid')).should == false
67
75
  end
68
76
 
69
- def params(fixture)
70
- MultiMail::Receiver::Mailgun.parse(response("mailgun/#{actual_http_post_format}", fixture, action_dispatch))
77
+ it 'should raise an error if parameters are missing' do
78
+ expect{ service.valid?(params('missing')) }.to raise_error(IndexError)
71
79
  end
80
+ end
72
81
 
73
- describe '#valid?' do
74
- it 'should return true if the response is valid' do
75
- service.valid?(params('valid')).should == true
76
- end
77
-
78
- it 'should return false if the response is invalid' do
79
- service.valid?(params('invalid')).should == false
80
- end
81
-
82
- it 'should raise an error if parameters are missing' do
83
- expect{ service.valid?(params('missing')) }.to raise_error(IndexError)
82
+ describe '#transform' do
83
+ it 'should return a mail message' do
84
+ messages = service.transform(params('valid'))
85
+ messages.size.should == 1
86
+ message = messages[0]
87
+
88
+ # Headers
89
+ message.date.should == DateTime.parse('Mon, 15 Apr 2013 20:20:12 -04:00')
90
+ message.from.should == ['james@opennorth.ca']
91
+ message.to.should == ['foo+bar@multimail.mailgun.org']
92
+ message.subject.should == 'Test'
93
+
94
+ # Body
95
+ message.multipart?.should == true
96
+ message.parts.size.should == 4
97
+ text_part = message.parts.find{|part| part.content_type == 'text/plain'}
98
+ html_part = message.parts.find{|part| part.content_type == 'text/html; charset=UTF-8'}
99
+ text_part.body.decoded.should == "bold text\n\n\n\nsome more bold text\n\n\n\nsome italic text\n\n> multiline\n> quoted\n> text\n\n\n--\nSignature block"
100
+ html_part.body.decoded.should == %(<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><b>bold text</b><div><br></div><div></div></body></html><html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><head></head><br><div></div><div><br></div><div><b>some more bold text</b></div><div><b><br></b></div><div><b></b></div></body></html><html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><b></b></div><div><b><span class="Apple-style-span" style="font-weight: normal; "><br></span></b></div><div><b><span class="Apple-style-span" style="font-weight: normal; "><i>some italic text</i></span></b></div><div><b><span class="Apple-style-span" style="font-weight: normal; "><br></span></b></div><div><blockquote type="cite">multiline</blockquote><blockquote type="cite">quoted</blockquote><blockquote type="cite">text</blockquote></div><div><br></div><div>--</div><div>Signature block</div></body></html>)
101
+
102
+ # Attachments
103
+ attachment0 = message.attachments.find{|attachment| attachment.filename == 'foo.txt'}
104
+ attachment1 = message.attachments.find{|attachment| attachment.filename == 'bar.txt'}
105
+ attachment0.read.should == "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n"
106
+ attachment1.read.should == "Nam accumsan euismod eros et rhoncus.\n"
107
+
108
+ # Extra Mailgun parameters
109
+ # @note Due to a Mailgun bug, `stripped-text` contains "some italic
110
+ # text" but `stripped-html` doesn't. `stripped-signature` and
111
+ # `stripped-text` use CRLF line endings.
112
+ if actual_http_post_format == 'raw'
113
+ message['stripped-text'].should be_nil
114
+ message['stripped-signature'].should be_nil
115
+ message['stripped-html'].should be_nil
116
+ else
117
+ message['stripped-text'].value.should == "bold text\r\n\r\n\r\n\r\nsome more bold text\r\n\r\n\r\n\r\nsome italic text"
118
+ message['stripped-signature'].value.should == "--\r\nSignature block"
119
+ message['stripped-html'].value.should == '<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><b>bold text</b><div><br></div><div></div></body><html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div></div><div><br></div><div><b>some more bold text</b></div><div><b><br></b></div><div><b></b></div></body></html><html><head></head></html></html>'
84
120
  end
85
121
  end
122
+ end
86
123
 
87
- describe '#transform' do
88
- it 'should return a mail message' do
89
- messages = service.transform(params('valid'))
90
- messages.size.should == 1
91
- message = messages[0]
92
-
93
- # Headers
94
- message.date.should == DateTime.parse('Mon, 15 Apr 2013 20:20:12 -04:00')
95
- message.from.should == ['james@opennorth.ca']
96
- message.to.should == ['foo+bar@multimail.mailgun.org']
97
- message.subject.should == 'Test'
98
-
99
- # Body
100
- message.multipart?.should == true
101
- message.parts.size.should == 4
102
- text_part = message.parts.find{|part| part.content_type == 'text/plain'}
103
- html_part = message.parts.find{|part| part.content_type == 'text/html; charset=UTF-8'}
104
- text_part.body.decoded.should == "bold text\n\n\n\nsome more bold text\n\n\n\nsome italic text\n\n> multiline\n> quoted\n> text\n\n\n--\nSignature block"
105
- html_part.body.decoded.should == %(<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><b>bold text</b><div><br></div><div></div></body></html><html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><head></head><br><div></div><div><br></div><div><b>some more bold text</b></div><div><b><br></b></div><div><b></b></div></body></html><html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><b></b></div><div><b><span class="Apple-style-span" style="font-weight: normal; "><br></span></b></div><div><b><span class="Apple-style-span" style="font-weight: normal; "><i>some italic text</i></span></b></div><div><b><span class="Apple-style-span" style="font-weight: normal; "><br></span></b></div><div><blockquote type="cite">multiline</blockquote><blockquote type="cite">quoted</blockquote><blockquote type="cite">text</blockquote></div><div><br></div><div>--</div><div>Signature block</div></body></html>)
106
-
107
- # Attachments
108
- attachment0 = message.attachments.find{|attachment| attachment.filename == 'foo.txt'}
109
- attachment1 = message.attachments.find{|attachment| attachment.filename == 'bar.txt'}
110
- attachment0.read.should == "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n"
111
- attachment1.read.should == "Nam accumsan euismod eros et rhoncus.\n"
112
-
113
- # Extra Mailgun parameters
114
- # @note Due to a Mailgun bug, `stripped-text` contains "some italic
115
- # text" but `stripped-html` doesn't. `stripped-signature` and
116
- # `stripped-text` use CRLF line endings.
117
- if actual_http_post_format == 'raw'
118
- message['stripped-text'].should be_nil
119
- message['stripped-signature'].should be_nil
120
- message['stripped-html'].should be_nil
121
- else
122
- message['stripped-text'].value.should == "bold text\r\n\r\n\r\n\r\nsome more bold text\r\n\r\n\r\n\r\nsome italic text"
123
- message['stripped-signature'].value.should == "--\r\nSignature block"
124
- message['stripped-html'].value.should == '<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><b>bold text</b><div><br></div><div></div></body><html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div></div><div><br></div><div><b>some more bold text</b></div><div><b><br></b></div><div><b></b></div></body></html><html><head></head></html></html>'
125
- end
126
- end
124
+ describe '#spam?' do
125
+ it 'should return true if the response is spam' do
126
+ # The raw MIME HTTP POST format doesn't perform spam filtering.
127
+ message = service.transform(params('spam'))[0]
128
+ service.spam?(message).should == (actual_http_post_format != 'raw')
127
129
  end
128
130
 
129
- describe '#spam?' do
130
- it 'should return true if the response is spam' do
131
- # The raw MIME HTTP POST format doesn't perform spam filtering.
132
- message = service.transform(params('spam'))[0]
133
- service.spam?(message).should == (actual_http_post_format != 'raw')
134
- end
135
-
136
- it 'should return false if the response is ham' do
137
- message = service.transform(params('valid'))[0]
138
- service.spam?(message).should == false
139
- end
131
+ it 'should return false if the response is ham' do
132
+ message = service.transform(params('valid'))[0]
133
+ service.spam?(message).should == false
140
134
  end
141
135
  end
142
136
  end
@@ -1,5 +1,4 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
- require 'multi_mail/mailgun/sender'
3
2
 
4
3
  describe MultiMail::Sender::Mailgun do
5
4
  let :message do
@@ -52,38 +51,41 @@ describe MultiMail::Sender::Mailgun do
52
51
  it 'should raise an error if :api_key is missing' do
53
52
  expect{
54
53
  message.delivery_method MultiMail::Sender::Mailgun, :domain => 'xxx'
55
- message.deliver # request not sent
56
54
  }.to raise_error(ArgumentError, "Missing required arguments: api_key")
57
55
  end
58
56
 
59
57
  it 'should raise an error if :domain is missing' do
60
58
  expect{
61
59
  message.delivery_method MultiMail::Sender::Mailgun, :api_key => 'xxx'
62
- message.deliver # request not sent
63
60
  }.to raise_error(ArgumentError, "Missing required arguments: domain")
64
61
  end
65
62
 
66
63
  it 'should raise an error if :api_key is nil' do
67
64
  expect{
68
65
  message.delivery_method MultiMail::Sender::Mailgun, :api_key => nil, :domain => 'xxx'
69
- message.deliver # request not sent
70
66
  }.to raise_error(ArgumentError, "Missing required arguments: api_key")
71
67
  end
72
68
 
73
69
  it 'should raise an error if :domain is nil' do
74
70
  expect{
75
71
  message.delivery_method MultiMail::Sender::Mailgun, :api_key => 'xxx', :domain => nil
76
- message.deliver # request not sent
77
72
  }.to raise_error(ArgumentError, "Missing required arguments: domain")
78
73
  end
79
74
 
80
- it 'should raise an error if :domain or :api_key are invalid' do
75
+ it 'should raise an error if :api_key is invalid' do
81
76
  expect{
82
- message.delivery_method MultiMail::Sender::Mailgun, :api_key => 'xxx', :domain => 'xxx'
77
+ message.delivery_method MultiMail::Sender::Mailgun, :api_key => 'xxx', :domain => 'multimail.mailgun.org'
83
78
  message.deliver
84
79
  }.to raise_error(MultiMail::InvalidAPIKey)
85
80
  end
86
81
 
82
+ it 'should raise an error if :domain is invalid' do
83
+ expect{
84
+ message.delivery_method MultiMail::Sender::Mailgun, :api_key => ENV['MAILGUN_API_KEY'], :domain => 'xxx'
85
+ message.deliver
86
+ }.to raise_error(MultiMail::InvalidRequest, "Domain not found: xxx")
87
+ end
88
+
87
89
  it 'should assign custom settings' do
88
90
  sender = MultiMail::Sender::Mailgun.new(:api_key => 'xxx', :domain => 'xxx')
89
91
 
@@ -168,6 +170,10 @@ describe MultiMail::Sender::Mailgun do
168
170
  expect{message_without_to.deliver!}.to raise_error(MultiMail::MissingRecipients, "'to' parameter is missing")
169
171
  end
170
172
 
173
+ it 'should send a message without a subject' do
174
+ expect{message_without_subject.deliver!}.to_not raise_error
175
+ end
176
+
171
177
  it 'should not send a message without a body' do
172
178
  expect{message_without_body.deliver!}.to raise_error(MultiMail::MissingBody, "Need at least one of 'text' or 'html' parameters specified")
173
179
  end