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
@@ -1,5 +1,4 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
- require 'multi_mail/mandrill/message'
3
2
 
4
3
  describe MultiMail::Message::Mandrill do
5
4
  let :message do
@@ -121,6 +120,19 @@ describe MultiMail::Message::Mandrill do
121
120
  MultiMail::Message::Mandrill.new
122
121
  end
123
122
 
123
+ let :message_with_one_tag do
124
+ MultiMail::Message::Mandrill.new do
125
+ tag 'foo'
126
+ end
127
+ end
128
+
129
+ let :message_with_many_tags do
130
+ MultiMail::Message::Mandrill.new do
131
+ tag 'foo'
132
+ tag 'bar'
133
+ end
134
+ end
135
+
124
136
  describe '#mandrill_to' do
125
137
  it 'should return the recipients with names' do
126
138
  message.mandrill_to.should == [
@@ -301,5 +313,17 @@ describe MultiMail::Message::Mandrill do
301
313
  it 'should convert an empty message' do
302
314
  empty_message.to_mandrill_hash.should == {}
303
315
  end
316
+
317
+ it 'should convert the message with one tag' do
318
+ message_with_one_tag.to_mandrill_hash.should == {
319
+ :tags => ['foo'],
320
+ }
321
+ end
322
+
323
+ it 'should convert the message with many tags' do
324
+ message_with_many_tags.to_mandrill_hash.should == {
325
+ :tags => ['foo', 'bar'],
326
+ }
327
+ end
304
328
  end
305
329
  end
@@ -2,106 +2,104 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
  require 'multi_mail/mandrill/receiver'
3
3
 
4
4
  describe MultiMail::Receiver::Mandrill do
5
- context 'after initialization' do
6
- def params(fixture)
7
- MultiMail::Receiver::Mandrill.parse(response('mandrill', fixture))
5
+ def params(fixture)
6
+ MultiMail::Receiver::Mandrill.parse(response('mandrill', fixture))
7
+ end
8
+
9
+ context 'without optional arguments' do
10
+ let :service do
11
+ MultiMail::Receiver.new(:provider => :mandrill)
8
12
  end
9
13
 
10
- context 'without optional arguments' do
11
- let :service do
12
- MultiMail::Receiver.new(:provider => :mandrill)
14
+ describe '#valid?' do
15
+ it 'should return true if the response is valid' do
16
+ service.valid?(params('valid')).should == true
13
17
  end
14
18
 
15
- describe '#valid?' do
16
- it 'should return true if the response is valid' do
17
- service.valid?(params('valid')).should == true
18
- end
19
-
20
- it 'should return true if the response is invalid' do
21
- service.valid?(params('invalid')).should == true
22
- end
19
+ it 'should return true if the response is invalid' do
20
+ service.valid?(params('invalid')).should == true
21
+ end
23
22
 
24
- it 'should return true if parameters are missing' do
25
- service.valid?(params('missing')).should == true
26
- end
23
+ it 'should return true if parameters are missing' do
24
+ service.valid?(params('missing')).should == true
27
25
  end
28
26
  end
27
+ end
28
+
29
+ context 'with optional arguments' do
30
+ let :service do
31
+ MultiMail::Receiver.new({
32
+ :provider => :mandrill,
33
+ :mandrill_webhook_key => 'rth_rywL9CWIIZBuwPQIWw',
34
+ :mandrill_webhook_url => 'http://rackbin.herokuapp.com/',
35
+ })
36
+ end
29
37
 
30
- context 'with optional arguments' do
31
- let :service do
32
- MultiMail::Receiver.new({
33
- :provider => :mandrill,
34
- :mandrill_webhook_key => 'rth_rywL9CWIIZBuwPQIWw',
35
- :mandrill_webhook_url => 'http://rackbin.herokuapp.com/',
36
- })
38
+ describe '#valid?' do
39
+ it 'should return true if the response is valid' do
40
+ service.valid?(params('valid')).should == true
37
41
  end
38
42
 
39
- describe '#valid?' do
40
- it 'should return true if the response is valid' do
41
- service.valid?(params('valid')).should == true
42
- end
43
+ it 'should return false if the response is invalid' do
44
+ service.valid?(params('invalid')).should == false
45
+ end
43
46
 
44
- it 'should return false if the response is invalid' do
45
- service.valid?(params('invalid')).should == false
46
- end
47
+ it 'should raise an error if parameters are missing' do
48
+ expect{ service.valid?(params('missing')) }.to raise_error(IndexError)
49
+ end
50
+ end
47
51
 
48
- it 'should raise an error if parameters are missing' do
49
- expect{ service.valid?(params('missing')) }.to raise_error(IndexError)
50
- end
52
+ describe '#transform' do
53
+ it 'should return a mail message' do
54
+ messages = service.transform(params('valid'))
55
+ messages.size.should == 1
56
+ message = messages[0]
57
+
58
+ # Headers
59
+ message.date.should == DateTime.parse('Mon, 29 May 2013 16:51:45 -04:00')
60
+ message.from.should == ['james@opennorth.ca']
61
+ message.to.should == ['foo+bar@govkit.org']
62
+ message.subject.should == 'Test'
63
+
64
+ # Body
65
+ message.multipart?.should == true
66
+ message.parts.size.should == 4
67
+ message.parts[0].content_type.should == 'text/plain'
68
+ message.parts[1].content_type.should == 'text/html; charset=UTF-8'
69
+ # @note Mandrill adds a newline at the end of each part.
70
+ message.parts[0].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\n"
71
+ message.parts[1].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>)
72
+
73
+ # Attachments
74
+ attachment0 = message.attachments.find{|attachment| attachment.filename == 'foo.txt'}
75
+ attachment1 = message.attachments.find{|attachment| attachment.filename == 'bar.txt'}
76
+ attachment0.read.should == "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n\n"
77
+ attachment1.read.should == "Nam accumsan euismod eros et rhoncus.\n\n"
78
+
79
+ # Extra Mandrill parameters
80
+ message['ts'].value.should == '1369860716'
81
+ message['email'].value.should == 'foo+bar@govkit.org'
82
+ message['dkim-signed'].value.should == 'false'
83
+ message['dkim-valid'].value.should == 'false'
84
+ message['spam_report-score'].value.should == '-0.7'
85
+ message['spf-result'].value.should == 'pass'
51
86
  end
52
87
 
53
- describe '#transform' do
54
- it 'should return a mail message' do
55
- messages = service.transform(params('valid'))
56
- messages.size.should == 1
57
- message = messages[0]
58
-
59
- # Headers
60
- message.date.should == DateTime.parse('Mon, 29 May 2013 16:51:45 -04:00')
61
- message.from.should == ['james@opennorth.ca']
62
- message.to.should == ['foo+bar@govkit.org']
63
- message.subject.should == 'Test'
64
-
65
- # Body
66
- message.multipart?.should == true
67
- message.parts.size.should == 4
68
- message.parts[0].content_type.should == 'text/plain'
69
- message.parts[1].content_type.should == 'text/html; charset=UTF-8'
70
- # @note Mandrill adds a newline at the end of each part.
71
- message.parts[0].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\n"
72
- message.parts[1].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>)
73
-
74
- # Attachments
75
- attachment0 = message.attachments.find{|attachment| attachment.filename == 'foo.txt'}
76
- attachment1 = message.attachments.find{|attachment| attachment.filename == 'bar.txt'}
77
- attachment0.read.should == "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n\n"
78
- attachment1.read.should == "Nam accumsan euismod eros et rhoncus.\n\n"
79
-
80
- # Extra Mandrill parameters
81
- message['ts'].value.should == '1369860716'
82
- message['email'].value.should == 'foo+bar@govkit.org'
83
- message['dkim-signed'].value.should == 'false'
84
- message['dkim-valid'].value.should == 'false'
85
- message['spam_report-score'].value.should == '-0.7'
86
- message['spf-result'].value.should == 'pass'
87
- end
88
-
89
- it 'should return multiple messages if there are multiple events' do
90
- messages = service.transform(params('multiple'))
91
- messages.size.should == 2
92
- end
88
+ it 'should return multiple messages if there are multiple events' do
89
+ messages = service.transform(params('multiple'))
90
+ messages.size.should == 2
93
91
  end
92
+ end
94
93
 
95
- describe '#spam?' do
96
- it 'should return true if the response is spam' do
97
- message = service.transform(params('spam'))[0]
98
- service.spam?(message).should == true
99
- end
94
+ describe '#spam?' do
95
+ it 'should return true if the response is spam' do
96
+ message = service.transform(params('spam'))[0]
97
+ service.spam?(message).should == true
98
+ end
100
99
 
101
- it 'should return false if the response is ham' do
102
- message = service.transform(params('valid'))[0]
103
- service.spam?(message).should == false
104
- end
100
+ it 'should return false if the response is ham' do
101
+ message = service.transform(params('valid'))[0]
102
+ service.spam?(message).should == false
105
103
  end
106
104
  end
107
105
  end
@@ -1,11 +1,10 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
- require 'multi_mail/mandrill/sender'
3
2
 
4
3
  describe MultiMail::Sender::Mandrill do
5
4
  let :message do
6
5
  Mail.new do
7
6
  from 'foo@example.com'
8
- to 'bar@example.com'
7
+ to 'bit-bucket@test.smtp.org'
9
8
  subject 'test'
10
9
  body 'hello'
11
10
  end
@@ -19,14 +18,12 @@ describe MultiMail::Sender::Mandrill do
19
18
  it 'should raise an error if :api_key is missing' do
20
19
  expect{
21
20
  message.delivery_method MultiMail::Sender::Mandrill
22
- message.deliver # request not sent
23
21
  }.to raise_error(ArgumentError, "Missing required arguments: api_key")
24
22
  end
25
23
 
26
24
  it 'should raise an error if :api_key is nil' do
27
25
  expect{
28
26
  message.delivery_method MultiMail::Sender::Mandrill, :api_key => nil
29
- message.deliver # request not sent
30
27
  }.to raise_error(ArgumentError, "Missing required arguments: api_key")
31
28
  end
32
29
 
@@ -37,6 +34,16 @@ describe MultiMail::Sender::Mandrill do
37
34
  }.to raise_error(MultiMail::InvalidAPIKey, 'Invalid API key')
38
35
  end
39
36
 
37
+ it 'should transform send_at to a string if it is not a string' do
38
+ sender = MultiMail::Sender::Mandrill.new(:api_user => '', :api_key => '', 'send_at' => Time.at(981203696))
39
+ sender.send_at.should == '2001-02-03 12:34:56'
40
+ end
41
+
42
+ it 'should not transform send_at to a string if it is a string' do
43
+ sender = MultiMail::Sender::Mandrill.new(:api_user => '', :api_key => '', 'send_at' => '2001-02-03 12:34:56')
44
+ sender.send_at.should == '2001-02-03 12:34:56'
45
+ end
46
+
40
47
  it 'should have default settings' do
41
48
  sender = MultiMail::Sender::Mandrill.new(:api_key => '')
42
49
 
@@ -126,8 +133,8 @@ describe MultiMail::Sender::Mandrill do
126
133
  result.size.should == 4
127
134
 
128
135
  result['reject_reason'].should == nil
129
- result['status'].should == "sent"
130
- result['email'].should == "bar@example.com"
136
+ result['status'].should == 'sent'
137
+ result['email'].should == 'bit-bucket@test.smtp.org'
131
138
  result['_id'].should match(/\A[0-9a-f]{32}\z/)
132
139
  end
133
140
 
@@ -65,7 +65,7 @@ describe MultiMail::Message::Base do
65
65
  end
66
66
  end
67
67
 
68
- describe '#text_part' do
68
+ describe '#body_text' do
69
69
  it 'should return the body if the message is text only' do
70
70
  text_message.body_text.should == 'hello'
71
71
  end
@@ -78,4 +78,36 @@ describe MultiMail::Message::Base do
78
78
  html_and_text_message.body_text.should == 'hello'
79
79
  end
80
80
  end
81
+
82
+ let :many_tags do
83
+ MultiMail::Message::Base.new do
84
+ tag 'foo'
85
+ tag 'bar'
86
+ end
87
+ end
88
+
89
+ let :one_tag do
90
+ MultiMail::Message::Base.new do
91
+ tag 'foo'
92
+ end
93
+ end
94
+
95
+ let :no_tag do
96
+ MultiMail::Message::Base.new do
97
+ end
98
+ end
99
+
100
+ describe '#tags' do
101
+ it 'should return a multi-value array if many tags are set' do
102
+ many_tags.tags.should == ['foo', 'bar']
103
+ end
104
+
105
+ it 'should return a single value array if one tag is set' do
106
+ one_tag.tags.should == ['foo']
107
+ end
108
+
109
+ it 'should return an empty array if no tags are set' do
110
+ no_tag.tags.should == []
111
+ end
112
+ end
81
113
  end
@@ -0,0 +1,292 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe MultiMail::Message::Postmark do
4
+ let :message do
5
+ headers = {
6
+ 'X-Autoreply' => true,
7
+ 'X-Precedence' => 'auto_reply',
8
+ 'X-Numeric' => 42,
9
+ 'Delivered-To' => 'Autoresponder',
10
+ }
11
+
12
+ MultiMail::Message::Postmark.new do
13
+ date Time.at(946702800)
14
+ headers headers
15
+ from %("John Doe" <foo@example.com>)
16
+ to [%("Jane Doe" <bar@example.com>), '<baz@example.com>']
17
+ cc 'cc@example.com'
18
+ bcc 'bcc@example.com'
19
+ reply_to 'noreply@example.com'
20
+ subject 'test'
21
+
22
+ text_part do
23
+ body 'hello'
24
+ end
25
+
26
+ html_part do
27
+ content_type 'text/html; charset=UTF-8'
28
+ body '<p>hello</p>'
29
+ end
30
+
31
+ add_file empty_gif_path
32
+ add_file :filename => 'foo.txt', :content => 'hello world'
33
+ end
34
+ end
35
+
36
+ let :message_without_names do
37
+ MultiMail::Message::Postmark.new do
38
+ from 'foo@example.com'
39
+ to ['bar@example.com', 'baz@example.com']
40
+ subject 'test'
41
+ body 'hello'
42
+ end
43
+ end
44
+
45
+ let :message_with_known_extension do
46
+ MultiMail::Message::Postmark.new do
47
+ from 'foo@example.com'
48
+ to 'bar@example.com'
49
+ subject 'test'
50
+ body 'hello'
51
+ add_file :filename => 'xxx.mov', :content => ''
52
+ end
53
+ end
54
+
55
+ let :message_with_unknown_extension do
56
+ MultiMail::Message::Postmark.new do
57
+ from 'foo@example.com'
58
+ to 'bar@example.com'
59
+ subject 'test'
60
+ body 'hello'
61
+ add_file :filename => 'xxx.xxx', :content => ''
62
+ end
63
+ end
64
+
65
+ let :message_without_extension do
66
+ MultiMail::Message::Postmark.new do
67
+ from 'foo@example.com'
68
+ to 'bar@example.com'
69
+ subject 'test'
70
+ body 'hello'
71
+ add_file :filename => 'xxx', :content => ''
72
+ end
73
+ end
74
+
75
+ let :message_with_empty_file do
76
+ MultiMail::Message::Postmark.new do
77
+ from 'foo@example.com'
78
+ to 'bar@example.com'
79
+ subject 'test'
80
+ body 'hello'
81
+ add_file :filename => '', :content => ''
82
+ end
83
+ end
84
+
85
+ let :message_with_empty_headers do
86
+ headers = {
87
+ 'X-Autoreply' => nil,
88
+ }
89
+
90
+ MultiMail::Message::Postmark.new do
91
+ headers headers
92
+ from 'foo@example.com'
93
+ to 'bar@example.com'
94
+ reply_to nil
95
+ subject 'test'
96
+ body 'hello'
97
+ end
98
+ end
99
+
100
+ let :message_without_html_body do
101
+ MultiMail::Message::Postmark.new do
102
+ from 'foo@example.com'
103
+ to 'bar@example.com'
104
+ subject 'test'
105
+ body 'hello'
106
+ end
107
+ end
108
+
109
+ let :message_without_text_body do
110
+ MultiMail::Message::Postmark.new do
111
+ from 'foo@example.com'
112
+ to 'bar@example.com'
113
+ subject 'test'
114
+ body '<p>hello</p>'
115
+ content_type 'text/html; charset=UTF-8'
116
+ end
117
+ end
118
+
119
+ let :empty_message do
120
+ MultiMail::Message::Postmark.new
121
+ end
122
+
123
+ let :message_with_one_tag do
124
+ MultiMail::Message::Postmark.new do
125
+ tag 'foo'
126
+ end
127
+ end
128
+
129
+ let :message_with_many_tags do
130
+ MultiMail::Message::Postmark.new do
131
+ tag 'foo'
132
+ tag 'bar'
133
+ end
134
+ end
135
+
136
+ describe '#postmark_headers' do
137
+ it 'should return the headers' do
138
+ headers = message.postmark_headers
139
+ [ {'Name' => 'X-Autoreply', 'Value' => 'true'},
140
+ {'Name' => 'X-Precedence', 'Value' => 'auto_reply'},
141
+ {'Name' => 'X-Numeric', 'Value' => '42'},
142
+ {'Name' => 'Delivered-To', 'Value' => 'Autoresponder'},
143
+ ].each do |header|
144
+ headers.should include(header)
145
+ end
146
+ end
147
+
148
+ it 'should return empty X-* headers' do
149
+ message_with_empty_headers.postmark_headers.should == [
150
+ {'Name' => 'X-Autoreply', 'Value' => ''},
151
+ ]
152
+ end
153
+
154
+ it 'should return an empty hash' do
155
+ empty_message.postmark_headers.should == []
156
+ end
157
+ end
158
+
159
+ describe '#postmark_attachments' do
160
+ it 'should return the attachments' do
161
+ message.postmark_attachments.should == [
162
+ {
163
+ 'ContentType' => 'image/gif; filename=empty.gif',
164
+ 'Name' => 'empty.gif',
165
+ 'Content' => "R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==\n",
166
+ 'ContentID' => 'empty.gif',
167
+ },
168
+ {
169
+ 'ContentType' => 'text/plain; filename=foo.txt',
170
+ 'Name' => 'foo.txt',
171
+ 'Content' => Base64.encode64('hello world'),
172
+ },
173
+ ]
174
+ end
175
+
176
+ it 'should return an attachment with an known extension' do
177
+ message_with_known_extension.postmark_attachments.should == [
178
+ {
179
+ 'ContentType' => 'video/quicktime; filename=xxx.mov',
180
+ 'Name' => 'xxx.mov',
181
+ 'Content' => '',
182
+ },
183
+ ]
184
+ end
185
+
186
+ it 'should return an attachment with an unknown extension' do
187
+ message_with_unknown_extension.postmark_attachments.should == [
188
+ {
189
+ 'ContentType' => 'text/plain',
190
+ 'Name' => 'xxx.xxx',
191
+ 'Content' => '',
192
+ },
193
+ ]
194
+ end
195
+
196
+ it 'should return an attachment without an extension' do
197
+ message_without_extension.postmark_attachments.should == [
198
+ {
199
+ 'ContentType' => 'text/plain',
200
+ 'Name' => 'xxx',
201
+ 'Content' => '',
202
+ },
203
+ ]
204
+ end
205
+
206
+ it 'should return an empty array if the attachment is blank' do
207
+ message_with_empty_file.postmark_attachments.should == []
208
+ end
209
+
210
+ it 'should return an empty array' do
211
+ empty_message.postmark_attachments.should == []
212
+ end
213
+ end
214
+
215
+ describe '#to_postmark_hash' do
216
+ it 'should return the message as Mandrill parameters' do
217
+ hash = message.to_postmark_hash
218
+ hash[:HtmlBody].should == '<p>hello</p>'
219
+ hash[:TextBody].should == 'hello'
220
+ hash[:Subject].should == 'test'
221
+ hash[:From].should == '"John Doe" <foo@example.com>'
222
+ hash[:To].should == '"Jane Doe" <bar@example.com>, <baz@example.com>'
223
+ hash[:Cc].should == "cc@example.com"
224
+ hash[:Bcc].should == "bcc@example.com"
225
+ hash[:ReplyTo].should == "noreply@example.com"
226
+ hash[:Attachments].should == [
227
+ {
228
+ 'ContentType' => 'image/gif; filename=empty.gif',
229
+ 'Name' => 'empty.gif',
230
+ 'Content' => "R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==\n",
231
+ 'ContentID' => 'empty.gif',
232
+ },
233
+ {
234
+ 'ContentType' => 'text/plain; filename=foo.txt',
235
+ 'Name' => 'foo.txt',
236
+ 'Content' => Base64.encode64('hello world'),
237
+ },
238
+ ]
239
+
240
+ [ {'Name' => 'X-Autoreply', 'Value' => 'true'},
241
+ {'Name' => 'X-Precedence', 'Value' => 'auto_reply'},
242
+ {'Name' => 'X-Numeric', 'Value' => '42'},
243
+ {'Name' => 'Delivered-To', 'Value' => 'Autoresponder'},
244
+ ].each do |header|
245
+ hash[:Headers].should include(header)
246
+ end
247
+ end
248
+
249
+ it 'should return the recipients without names' do
250
+ message_without_names.to_postmark_hash.should == {
251
+ :TextBody => 'hello',
252
+ :Subject => 'test',
253
+ :From => 'foo@example.com',
254
+ :To => 'bar@example.com, baz@example.com',
255
+ }
256
+ end
257
+
258
+ it 'should convert the message without a text body' do
259
+ message_without_text_body.to_postmark_hash.should == {
260
+ :HtmlBody => '<p>hello</p>',
261
+ :Subject => 'test',
262
+ :From => 'foo@example.com',
263
+ :To => 'bar@example.com',
264
+ }
265
+ end
266
+
267
+ it 'should convert the message without an HTML body' do
268
+ message_without_html_body.to_postmark_hash.should == {
269
+ :TextBody => 'hello',
270
+ :Subject => 'test',
271
+ :From => 'foo@example.com',
272
+ :To => 'bar@example.com',
273
+ }
274
+ end
275
+
276
+ it 'should convert an empty message' do
277
+ empty_message.to_postmark_hash.should == {}
278
+ end
279
+
280
+ it 'should convert the message with one tag' do
281
+ message_with_one_tag.to_postmark_hash.should == {
282
+ :Tag => 'foo',
283
+ }
284
+ end
285
+
286
+ it 'should convert the message with many tags' do
287
+ message_with_many_tags.to_postmark_hash.should == {
288
+ :Tag => 'foo',
289
+ }
290
+ end
291
+ end
292
+ end