-
Notifications
You must be signed in to change notification settings - Fork 70
/
mail_message_converter_spec.rb
277 lines (240 loc) · 8.19 KB
/
mail_message_converter_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# encoding: utf-8
require 'spec_helper'
describe Postmark::MailMessageConverter do
subject { Postmark::MailMessageConverter }
let(:mail_message) do
Mail.new do
from "sheldon@bigbangtheory.com"
to "lenard@bigbangtheory.com"
subject "Hello!"
body "Hello Sheldon!"
end
end
let(:mail_html_message) do
Mail.new do
from "sheldon@bigbangtheory.com"
to "lenard@bigbangtheory.com"
subject "Hello!"
content_type 'text/html; charset=UTF-8'
body "<b>Hello Sheldon!</b>"
end
end
let(:mail_message_with_tracking) do
Mail.new do
from "sheldon@bigbangtheory.com"
to "lenard@bigbangtheory.com"
subject "Hello!"
content_type 'text/html; charset=UTF-8'
body "<b>Hello Sheldon!</b>"
track_opens true
end
end
let(:mail_message_with_tracking_set_variable) do
mail = mail_html_message
mail.track_opens=true
mail
end
let(:mail_message_with_tracking_disabled_set_variable) do
mail = mail_html_message
mail.track_opens=true
mail
end
let(:mail_message_with_tracking_disabled) do
Mail.new do
from "sheldon@bigbangtheory.com"
to "lenard@bigbangtheory.com"
subject "Hello!"
content_type 'text/html; charset=UTF-8'
body "<b>Hello Sheldon!</b>"
track_opens false
end
end
let(:tagged_mail_message) do
Mail.new do
from "sheldon@bigbangtheory.com"
to "lenard@bigbangtheory.com"
subject "Hello!"
body "Hello Sheldon!"
tag "sheldon"
end
end
let(:mail_message_without_body) do
Mail.new do
from "sheldon@bigbangtheory.com"
to "lenard@bigbangtheory.com"
subject "Hello!"
end
end
let(:mail_multipart_message) do
Mail.new do
from "sheldon@bigbangtheory.com"
to "lenard@bigbangtheory.com"
subject "Hello!"
text_part do
body "Hello Sheldon!"
end
html_part do
body "<b>Hello Sheldon!</b>"
end
end
end
let(:mail_message_with_attachment) do
Mail.new do
from "sheldon@bigbangtheory.com"
to "lenard@bigbangtheory.com"
subject "Hello!"
body "Hello Sheldon!"
add_file empty_gif_path
end
end
let(:mail_message_with_named_addresses) do
Mail.new do
from "Sheldon <sheldon@bigbangtheory.com>"
to "\"Leonard Hofstadter\" <leonard@bigbangtheory.com>"
subject "Hello!"
body "Hello Sheldon!"
reply_to '"Penny The Neighbor" <penny@bigbangtheory.com>'
end
end
let(:mail_message_quoted_printable) do
Mail.new do
from "Sheldon <sheldon@bigbangtheory.com>"
to "\"Leonard Hofstadter\" <leonard@bigbangtheory.com>"
subject "Hello!"
content_type 'text/plain; charset=utf-8'
content_transfer_encoding 'quoted-printable'
body 'Он здесь бывал: еще не в галифе.'
reply_to '"Penny The Neighbor" <penny@bigbangtheory.com>'
end
end
let(:multipart_message_quoted_printable) do
Mail.new do
from "sheldon@bigbangtheory.com"
to "lenard@bigbangtheory.com"
subject "Hello!"
text_part do
content_type 'text/plain; charset=utf-8'
content_transfer_encoding 'quoted-printable'
body 'Загадочное послание.'
end
html_part do
content_type 'text/html; charset=utf-8'
content_transfer_encoding 'quoted-printable'
body '<b>Загадочное послание.</b>'
end
end
end
it 'converts plain text messages correctly' do
subject.new(mail_message).run.should == {
"From" => "sheldon@bigbangtheory.com",
"Subject" => "Hello!",
"TextBody" => "Hello Sheldon!",
"To" => "lenard@bigbangtheory.com"}
end
it 'converts tagged text messages correctly' do
subject.new(tagged_mail_message).run.should == {
"From" => "sheldon@bigbangtheory.com",
"Subject" => "Hello!",
"TextBody" => "Hello Sheldon!",
"Tag" => "sheldon",
"To"=>"lenard@bigbangtheory.com"}
end
it 'converts plain text messages without body correctly' do
subject.new(mail_message_without_body).run.should == {
"From" => "sheldon@bigbangtheory.com",
"Subject" => "Hello!",
"To" => "lenard@bigbangtheory.com"}
end
it 'converts html messages correctly' do
subject.new(mail_html_message).run.should == {
"From" => "sheldon@bigbangtheory.com",
"Subject" => "Hello!",
"HtmlBody" => "<b>Hello Sheldon!</b>",
"To" => "lenard@bigbangtheory.com"}
end
it 'converts multipart messages correctly' do
subject.new(mail_multipart_message).run.should == {
"From" => "sheldon@bigbangtheory.com",
"Subject" => "Hello!",
"HtmlBody" => "<b>Hello Sheldon!</b>",
"TextBody" => "Hello Sheldon!",
"To" => "lenard@bigbangtheory.com"}
end
it 'converts messages with attachments correctly' do
subject.new(mail_message_with_attachment).run.should == {
"From" => "sheldon@bigbangtheory.com",
"Subject" => "Hello!",
"Attachments" => [{"Name"=>"empty.gif",
"Content"=>encoded_empty_gif_data,
"ContentType"=>"image/gif"}],
"TextBody"=>"Hello Sheldon!",
"To"=>"lenard@bigbangtheory.com"}
end
it 'converts messages with named addresses correctly' do
subject.new(mail_message_with_named_addresses).run.should == {
"From" => "Sheldon <sheldon@bigbangtheory.com>",
"Subject" => "Hello!",
"TextBody" => "Hello Sheldon!",
"To" => "Leonard Hofstadter <leonard@bigbangtheory.com>",
"ReplyTo" => 'Penny The Neighbor <penny@bigbangtheory.com>'}
end
context 'recognizes open tracking' do
context 'setup inside of mail' do
it 'is enabled' do
subject.new(mail_message_with_tracking).run.should == {
"From" => "sheldon@bigbangtheory.com",
"Subject" => "Hello!",
"HtmlBody" => "<b>Hello Sheldon!</b>",
"To" => "lenard@bigbangtheory.com",
"TrackOpens" => true}
end
it 'is disabled' do
subject.new(mail_message_with_tracking_disabled).run.should == {
"From" => "sheldon@bigbangtheory.com",
"Subject" => "Hello!",
"HtmlBody" => "<b>Hello Sheldon!</b>",
"To" => "lenard@bigbangtheory.com",
"TrackOpens" => false}
end
end
context 'setup with tracking variable' do
it 'is enabled' do
subject.new(mail_message_with_tracking_set_variable).run.should == {
"From" => "sheldon@bigbangtheory.com",
"Subject" => "Hello!",
"HtmlBody" => "<b>Hello Sheldon!</b>",
"To" => "lenard@bigbangtheory.com",
"TrackOpens" => true}
end
it 'is disabled' do
subject.new(mail_message_with_tracking_disabled_set_variable).run.should == {
"From" => "sheldon@bigbangtheory.com",
"Subject" => "Hello!",
"HtmlBody" => "<b>Hello Sheldon!</b>",
"To" => "lenard@bigbangtheory.com",
"TrackOpens" => true}
end
end
end
it 'correctly decodes unicode in messages transfered as quoted-printable' do
subject.new(mail_message_quoted_printable).run.should \
include('TextBody' => 'Он здесь бывал: еще не в галифе.')
end
it 'correctly decodes unicode in multipart quoted-printable messages' do
subject.new(multipart_message_quoted_printable).run.should \
include('TextBody' => 'Загадочное послание.',
'HtmlBody' => '<b>Загадочное послание.</b>')
end
context 'when bcc is empty' do
it 'excludes bcc from message' do
mail_message.bcc = nil
mail_message.to_postmark_hash.keys.should_not include('Bcc')
end
end
context 'when cc is empty' do
it 'excludes cc from message' do
mail_message.cc = nil
mail_message.to_postmark_hash.keys.should_not include('Cc')
end
end
end