actionmailer_csi 2.3.5.p6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +370 -0
- data/MIT-LICENSE +21 -0
- data/README +149 -0
- data/Rakefile +99 -0
- data/install.rb +30 -0
- data/lib/action_mailer/adv_attr_accessor.rb +30 -0
- data/lib/action_mailer/base.rb +706 -0
- data/lib/action_mailer/helpers.rb +113 -0
- data/lib/action_mailer/mail_helper.rb +17 -0
- data/lib/action_mailer/part.rb +107 -0
- data/lib/action_mailer/part_container.rb +55 -0
- data/lib/action_mailer/quoting.rb +61 -0
- data/lib/action_mailer/test_case.rb +64 -0
- data/lib/action_mailer/test_helper.rb +68 -0
- data/lib/action_mailer/utils.rb +7 -0
- data/lib/action_mailer/vendor/text-format-0.6.3/text/format.rb +1466 -0
- data/lib/action_mailer/vendor/text_format.rb +10 -0
- data/lib/action_mailer/vendor/tmail-1.2.3/tmail/address.rb +426 -0
- data/lib/action_mailer/vendor/tmail-1.2.3/tmail/attachments.rb +46 -0
- data/lib/action_mailer/vendor/tmail-1.2.3/tmail/base64.rb +46 -0
- data/lib/action_mailer/vendor/tmail-1.2.3/tmail/compat.rb +41 -0
- data/lib/action_mailer/vendor/tmail-1.2.3/tmail/config.rb +67 -0
- data/lib/action_mailer/vendor/tmail-1.2.3/tmail/core_extensions.rb +63 -0
- data/lib/action_mailer/vendor/tmail-1.2.3/tmail/encode.rb +581 -0
- data/lib/action_mailer/vendor/tmail-1.2.3/tmail/header.rb +960 -0
- data/lib/action_mailer/vendor/tmail-1.2.3/tmail/index.rb +9 -0
- data/lib/action_mailer/vendor/tmail-1.2.3/tmail/interface.rb +1130 -0
- data/lib/action_mailer/vendor/tmail-1.2.3/tmail/loader.rb +3 -0
- data/lib/action_mailer/vendor/tmail-1.2.3/tmail/mail.rb +578 -0
- data/lib/action_mailer/vendor/tmail-1.2.3/tmail/mailbox.rb +495 -0
- data/lib/action_mailer/vendor/tmail-1.2.3/tmail/main.rb +6 -0
- data/lib/action_mailer/vendor/tmail-1.2.3/tmail/mbox.rb +3 -0
- data/lib/action_mailer/vendor/tmail-1.2.3/tmail/net.rb +248 -0
- data/lib/action_mailer/vendor/tmail-1.2.3/tmail/obsolete.rb +132 -0
- data/lib/action_mailer/vendor/tmail-1.2.3/tmail/parser.rb +1478 -0
- data/lib/action_mailer/vendor/tmail-1.2.3/tmail/port.rb +379 -0
- data/lib/action_mailer/vendor/tmail-1.2.3/tmail/quoting.rb +118 -0
- data/lib/action_mailer/vendor/tmail-1.2.3/tmail/require_arch.rb +58 -0
- data/lib/action_mailer/vendor/tmail-1.2.3/tmail/scanner.rb +49 -0
- data/lib/action_mailer/vendor/tmail-1.2.3/tmail/scanner_r.rb +261 -0
- data/lib/action_mailer/vendor/tmail-1.2.3/tmail/stringio.rb +280 -0
- data/lib/action_mailer/vendor/tmail-1.2.3/tmail/utils.rb +337 -0
- data/lib/action_mailer/vendor/tmail-1.2.3/tmail/version.rb +39 -0
- data/lib/action_mailer/vendor/tmail-1.2.3/tmail.rb +5 -0
- data/lib/action_mailer/vendor/tmail.rb +17 -0
- data/lib/action_mailer/version.rb +9 -0
- data/lib/action_mailer.rb +62 -0
- data/lib/actionmailer.rb +2 -0
- data/test/abstract_unit.rb +62 -0
- data/test/asset_host_test.rb +54 -0
- data/test/delivery_method_test.rb +51 -0
- data/test/fixtures/asset_host_mailer/email_with_asset.html.erb +1 -0
- data/test/fixtures/auto_layout_mailer/hello.html.erb +1 -0
- data/test/fixtures/auto_layout_mailer/multipart.text.html.erb +1 -0
- data/test/fixtures/auto_layout_mailer/multipart.text.plain.erb +1 -0
- data/test/fixtures/explicit_layout_mailer/logout.html.erb +1 -0
- data/test/fixtures/explicit_layout_mailer/signup.html.erb +1 -0
- data/test/fixtures/first_mailer/share.erb +1 -0
- data/test/fixtures/helper_mailer/use_example_helper.erb +1 -0
- data/test/fixtures/helper_mailer/use_helper.erb +1 -0
- data/test/fixtures/helper_mailer/use_helper_method.erb +1 -0
- data/test/fixtures/helper_mailer/use_mail_helper.erb +5 -0
- data/test/fixtures/helpers/example_helper.rb +5 -0
- data/test/fixtures/layouts/auto_layout_mailer.html.erb +1 -0
- data/test/fixtures/layouts/auto_layout_mailer.text.erb +1 -0
- data/test/fixtures/layouts/spam.html.erb +1 -0
- data/test/fixtures/path.with.dots/funky_path_mailer/multipart_with_template_path_with_dots.erb +1 -0
- data/test/fixtures/raw_email +14 -0
- data/test/fixtures/raw_email10 +20 -0
- data/test/fixtures/raw_email12 +32 -0
- data/test/fixtures/raw_email13 +29 -0
- data/test/fixtures/raw_email2 +114 -0
- data/test/fixtures/raw_email3 +70 -0
- data/test/fixtures/raw_email4 +59 -0
- data/test/fixtures/raw_email5 +19 -0
- data/test/fixtures/raw_email6 +20 -0
- data/test/fixtures/raw_email7 +66 -0
- data/test/fixtures/raw_email8 +47 -0
- data/test/fixtures/raw_email9 +28 -0
- data/test/fixtures/raw_email_quoted_with_0d0a +14 -0
- data/test/fixtures/raw_email_with_invalid_characters_in_content_type +104 -0
- data/test/fixtures/raw_email_with_nested_attachment +100 -0
- data/test/fixtures/raw_email_with_partially_quoted_subject +14 -0
- data/test/fixtures/second_mailer/share.erb +1 -0
- data/test/fixtures/templates/signed_up.erb +3 -0
- data/test/fixtures/test_mailer/_subtemplate.text.plain.erb +1 -0
- data/test/fixtures/test_mailer/body_ivar.erb +2 -0
- data/test/fixtures/test_mailer/custom_templating_extension.text.html.haml +6 -0
- data/test/fixtures/test_mailer/custom_templating_extension.text.plain.haml +6 -0
- data/test/fixtures/test_mailer/implicitly_multipart_example.ignored.erb +1 -0
- data/test/fixtures/test_mailer/implicitly_multipart_example.rhtml.bak +1 -0
- data/test/fixtures/test_mailer/implicitly_multipart_example.text.html.erb +10 -0
- data/test/fixtures/test_mailer/implicitly_multipart_example.text.html.erb~ +10 -0
- data/test/fixtures/test_mailer/implicitly_multipart_example.text.plain.erb +2 -0
- data/test/fixtures/test_mailer/implicitly_multipart_example.text.yaml.erb +1 -0
- data/test/fixtures/test_mailer/included_subtemplate.text.plain.erb +1 -0
- data/test/fixtures/test_mailer/rxml_template.builder +2 -0
- data/test/fixtures/test_mailer/rxml_template.rxml +2 -0
- data/test/fixtures/test_mailer/signed_up.html.erb +3 -0
- data/test/fixtures/test_mailer/signed_up_with_url.erb +5 -0
- data/test/mail_helper_test.rb +95 -0
- data/test/mail_layout_test.rb +123 -0
- data/test/mail_render_test.rb +116 -0
- data/test/mail_service_test.rb +1081 -0
- data/test/quoting_test.rb +99 -0
- data/test/test_helper_test.rb +129 -0
- data/test/tmail_test.rb +22 -0
- data/test/url_test.rb +76 -0
- metadata +195 -0
@@ -0,0 +1,1081 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'abstract_unit'
|
3
|
+
|
4
|
+
class FunkyPathMailer < ActionMailer::Base
|
5
|
+
self.template_root = "#{File.dirname(__FILE__)}/fixtures/path.with.dots"
|
6
|
+
|
7
|
+
def multipart_with_template_path_with_dots(recipient)
|
8
|
+
recipients recipient
|
9
|
+
subject "Have a lovely picture"
|
10
|
+
from "Chad Fowler <chad@chadfowler.com>"
|
11
|
+
attachment :content_type => "image/jpeg",
|
12
|
+
:body => "not really a jpeg, we're only testing, after all"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class TestMailer < ActionMailer::Base
|
17
|
+
def signed_up(recipient)
|
18
|
+
@recipients = recipient
|
19
|
+
@subject = "[Signed up] Welcome #{recipient}"
|
20
|
+
@from = "system@loudthinking.com"
|
21
|
+
@body["recipient"] = recipient
|
22
|
+
end
|
23
|
+
|
24
|
+
def cancelled_account(recipient)
|
25
|
+
self.recipients = recipient
|
26
|
+
self.subject = "[Cancelled] Goodbye #{recipient}"
|
27
|
+
self.from = "system@loudthinking.com"
|
28
|
+
self.sent_on = Time.local(2004, 12, 12)
|
29
|
+
self.body = "Goodbye, Mr. #{recipient}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def cc_bcc(recipient)
|
33
|
+
recipients recipient
|
34
|
+
subject "testing bcc/cc"
|
35
|
+
from "system@loudthinking.com"
|
36
|
+
sent_on Time.local(2004, 12, 12)
|
37
|
+
cc "nobody@loudthinking.com"
|
38
|
+
bcc "root@loudthinking.com"
|
39
|
+
body "Nothing to see here."
|
40
|
+
end
|
41
|
+
|
42
|
+
def different_reply_to(recipient)
|
43
|
+
recipients recipient
|
44
|
+
subject "testing reply_to"
|
45
|
+
from "system@loudthinking.com"
|
46
|
+
sent_on Time.local(2008, 5, 23)
|
47
|
+
reply_to "atraver@gmail.com"
|
48
|
+
body "Nothing to see here."
|
49
|
+
end
|
50
|
+
|
51
|
+
def iso_charset(recipient)
|
52
|
+
@recipients = recipient
|
53
|
+
@subject = "testing isø charsets"
|
54
|
+
@from = "system@loudthinking.com"
|
55
|
+
@sent_on = Time.local 2004, 12, 12
|
56
|
+
@cc = "nobody@loudthinking.com"
|
57
|
+
@bcc = "root@loudthinking.com"
|
58
|
+
@body = "Nothing to see here."
|
59
|
+
@charset = "iso-8859-1"
|
60
|
+
end
|
61
|
+
|
62
|
+
def unencoded_subject(recipient)
|
63
|
+
@recipients = recipient
|
64
|
+
@subject = "testing unencoded subject"
|
65
|
+
@from = "system@loudthinking.com"
|
66
|
+
@sent_on = Time.local 2004, 12, 12
|
67
|
+
@cc = "nobody@loudthinking.com"
|
68
|
+
@bcc = "root@loudthinking.com"
|
69
|
+
@body = "Nothing to see here."
|
70
|
+
end
|
71
|
+
|
72
|
+
def extended_headers(recipient)
|
73
|
+
@recipients = recipient
|
74
|
+
@subject = "testing extended headers"
|
75
|
+
@from = "Grytøyr <stian1@example.net>"
|
76
|
+
@sent_on = Time.local 2004, 12, 12
|
77
|
+
@cc = "Grytøyr <stian2@example.net>"
|
78
|
+
@bcc = "Grytøyr <stian3@example.net>"
|
79
|
+
@body = "Nothing to see here."
|
80
|
+
@charset = "iso-8859-1"
|
81
|
+
end
|
82
|
+
|
83
|
+
def utf8_body(recipient)
|
84
|
+
@recipients = recipient
|
85
|
+
@subject = "testing utf-8 body"
|
86
|
+
@from = "Foo áëô îü <extended@example.net>"
|
87
|
+
@sent_on = Time.local 2004, 12, 12
|
88
|
+
@cc = "Foo áëô îü <extended@example.net>"
|
89
|
+
@bcc = "Foo áëô îü <extended@example.net>"
|
90
|
+
@body = "åœö blah"
|
91
|
+
@charset = "utf-8"
|
92
|
+
end
|
93
|
+
|
94
|
+
def multipart_with_mime_version(recipient)
|
95
|
+
recipients recipient
|
96
|
+
subject "multipart with mime_version"
|
97
|
+
from "test@example.com"
|
98
|
+
sent_on Time.local(2004, 12, 12)
|
99
|
+
mime_version "1.1"
|
100
|
+
content_type "multipart/alternative"
|
101
|
+
|
102
|
+
part "text/plain" do |p|
|
103
|
+
p.body = "blah"
|
104
|
+
end
|
105
|
+
|
106
|
+
part "text/html" do |p|
|
107
|
+
p.body = "<b>blah</b>"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def multipart_with_utf8_subject(recipient)
|
112
|
+
recipients recipient
|
113
|
+
subject "Foo áëô îü"
|
114
|
+
from "test@example.com"
|
115
|
+
charset "utf-8"
|
116
|
+
|
117
|
+
part "text/plain" do |p|
|
118
|
+
p.body = "blah"
|
119
|
+
end
|
120
|
+
|
121
|
+
part "text/html" do |p|
|
122
|
+
p.body = "<b>blah</b>"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def explicitly_multipart_example(recipient, ct=nil)
|
127
|
+
recipients recipient
|
128
|
+
subject "multipart example"
|
129
|
+
from "test@example.com"
|
130
|
+
sent_on Time.local(2004, 12, 12)
|
131
|
+
body "plain text default"
|
132
|
+
content_type ct if ct
|
133
|
+
|
134
|
+
part "text/html" do |p|
|
135
|
+
p.charset = "iso-8859-1"
|
136
|
+
p.body = "blah"
|
137
|
+
end
|
138
|
+
|
139
|
+
attachment :content_type => "image/jpeg", :filename => "foo.jpg",
|
140
|
+
:body => "123456789"
|
141
|
+
end
|
142
|
+
|
143
|
+
def implicitly_multipart_example(recipient, cs = nil, order = nil)
|
144
|
+
@recipients = recipient
|
145
|
+
@subject = "multipart example"
|
146
|
+
@from = "test@example.com"
|
147
|
+
@sent_on = Time.local 2004, 12, 12
|
148
|
+
@body = { "recipient" => recipient }
|
149
|
+
@charset = cs if cs
|
150
|
+
@implicit_parts_order = order if order
|
151
|
+
end
|
152
|
+
|
153
|
+
def implicitly_multipart_with_utf8
|
154
|
+
recipients "no.one@nowhere.test"
|
155
|
+
subject "Foo áëô îü"
|
156
|
+
from "some.one@somewhere.test"
|
157
|
+
template "implicitly_multipart_example"
|
158
|
+
body ({ "recipient" => "no.one@nowhere.test" })
|
159
|
+
end
|
160
|
+
|
161
|
+
def html_mail(recipient)
|
162
|
+
recipients recipient
|
163
|
+
subject "html mail"
|
164
|
+
from "test@example.com"
|
165
|
+
body "<em>Emphasize</em> <strong>this</strong>"
|
166
|
+
content_type "text/html"
|
167
|
+
end
|
168
|
+
|
169
|
+
def html_mail_with_underscores(recipient)
|
170
|
+
subject "html mail with underscores"
|
171
|
+
body %{<a href="http://google.com" target="_blank">_Google</a>}
|
172
|
+
end
|
173
|
+
|
174
|
+
def custom_template(recipient)
|
175
|
+
recipients recipient
|
176
|
+
subject "[Signed up] Welcome #{recipient}"
|
177
|
+
from "system@loudthinking.com"
|
178
|
+
sent_on Time.local(2004, 12, 12)
|
179
|
+
template "signed_up"
|
180
|
+
|
181
|
+
body["recipient"] = recipient
|
182
|
+
end
|
183
|
+
|
184
|
+
def custom_templating_extension(recipient)
|
185
|
+
recipients recipient
|
186
|
+
subject "[Signed up] Welcome #{recipient}"
|
187
|
+
from "system@loudthinking.com"
|
188
|
+
sent_on Time.local(2004, 12, 12)
|
189
|
+
|
190
|
+
body["recipient"] = recipient
|
191
|
+
end
|
192
|
+
|
193
|
+
def various_newlines(recipient)
|
194
|
+
recipients recipient
|
195
|
+
subject "various newlines"
|
196
|
+
from "test@example.com"
|
197
|
+
body "line #1\nline #2\rline #3\r\nline #4\r\r" +
|
198
|
+
"line #5\n\nline#6\r\n\r\nline #7"
|
199
|
+
end
|
200
|
+
|
201
|
+
def various_newlines_multipart(recipient)
|
202
|
+
recipients recipient
|
203
|
+
subject "various newlines multipart"
|
204
|
+
from "test@example.com"
|
205
|
+
content_type "multipart/alternative"
|
206
|
+
part :content_type => "text/plain", :body => "line #1\nline #2\rline #3\r\nline #4\r\r"
|
207
|
+
part :content_type => "text/html", :body => "<p>line #1</p>\n<p>line #2</p>\r<p>line #3</p>\r\n<p>line #4</p>\r\r"
|
208
|
+
end
|
209
|
+
|
210
|
+
def nested_multipart(recipient)
|
211
|
+
recipients recipient
|
212
|
+
subject "nested multipart"
|
213
|
+
from "test@example.com"
|
214
|
+
content_type "multipart/mixed"
|
215
|
+
part :content_type => "multipart/alternative", :content_disposition => "inline", :headers => { "foo" => "bar" } do |p|
|
216
|
+
p.part :content_type => "text/plain", :body => "test text\nline #2"
|
217
|
+
p.part :content_type => "text/html", :body => "<b>test</b> HTML<br/>\nline #2"
|
218
|
+
end
|
219
|
+
attachment :content_type => "application/octet-stream",:filename => "test.txt", :body => "test abcdefghijklmnopqstuvwxyz"
|
220
|
+
end
|
221
|
+
|
222
|
+
def nested_multipart_with_body(recipient)
|
223
|
+
recipients recipient
|
224
|
+
subject "nested multipart with body"
|
225
|
+
from "test@example.com"
|
226
|
+
content_type "multipart/mixed"
|
227
|
+
part :content_type => "multipart/alternative", :content_disposition => "inline", :body => "Nothing to see here." do |p|
|
228
|
+
p.part :content_type => "text/html", :body => "<b>test</b> HTML<br/>"
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
def attachment_with_custom_header(recipient)
|
233
|
+
recipients recipient
|
234
|
+
subject "custom header in attachment"
|
235
|
+
from "test@example.com"
|
236
|
+
content_type "multipart/related"
|
237
|
+
part :content_type => "text/html", :body => 'yo'
|
238
|
+
attachment :content_type => "image/jpeg",:filename => "test.jpeg", :body => "i am not a real picture", :headers => { 'Content-ID' => '<test@test.com>' }
|
239
|
+
end
|
240
|
+
|
241
|
+
def unnamed_attachment(recipient)
|
242
|
+
recipients recipient
|
243
|
+
subject "nested multipart"
|
244
|
+
from "test@example.com"
|
245
|
+
content_type "multipart/mixed"
|
246
|
+
part :content_type => "text/plain", :body => "hullo"
|
247
|
+
attachment :content_type => "application/octet-stream", :body => "test abcdefghijklmnopqstuvwxyz"
|
248
|
+
end
|
249
|
+
|
250
|
+
def headers_with_nonalpha_chars(recipient)
|
251
|
+
recipients recipient
|
252
|
+
subject "nonalpha chars"
|
253
|
+
from "One: Two <test@example.com>"
|
254
|
+
cc "Three: Four <test@example.com>"
|
255
|
+
bcc "Five: Six <test@example.com>"
|
256
|
+
body "testing"
|
257
|
+
end
|
258
|
+
|
259
|
+
def custom_content_type_attributes
|
260
|
+
recipients "no.one@nowhere.test"
|
261
|
+
subject "custom content types"
|
262
|
+
from "some.one@somewhere.test"
|
263
|
+
content_type "text/plain; format=flowed"
|
264
|
+
body "testing"
|
265
|
+
end
|
266
|
+
|
267
|
+
def return_path
|
268
|
+
recipients "no.one@nowhere.test"
|
269
|
+
subject "return path test"
|
270
|
+
from "some.one@somewhere.test"
|
271
|
+
body "testing"
|
272
|
+
headers "return-path" => "another@somewhere.test"
|
273
|
+
end
|
274
|
+
|
275
|
+
def body_ivar(recipient)
|
276
|
+
recipients recipient
|
277
|
+
subject "Body as a local variable"
|
278
|
+
from "test@example.com"
|
279
|
+
body :body => "foo", :bar => "baz"
|
280
|
+
end
|
281
|
+
|
282
|
+
class <<self
|
283
|
+
attr_accessor :received_body
|
284
|
+
end
|
285
|
+
|
286
|
+
def receive(mail)
|
287
|
+
self.class.received_body = mail.body
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
class ActionMailerTest < Test::Unit::TestCase
|
292
|
+
include ActionMailer::Quoting
|
293
|
+
|
294
|
+
def encode( text, charset="utf-8" )
|
295
|
+
quoted_printable( text, charset )
|
296
|
+
end
|
297
|
+
|
298
|
+
def new_mail( charset="utf-8" )
|
299
|
+
mail = TMail::Mail.new
|
300
|
+
mail.mime_version = "1.0"
|
301
|
+
if charset
|
302
|
+
mail.set_content_type "text", "plain", { "charset" => charset }
|
303
|
+
end
|
304
|
+
mail
|
305
|
+
end
|
306
|
+
|
307
|
+
# Replacing logger work around for mocha bug. Should be fixed in mocha 0.3.3
|
308
|
+
def setup
|
309
|
+
set_delivery_method :test
|
310
|
+
ActionMailer::Base.perform_deliveries = true
|
311
|
+
ActionMailer::Base.raise_delivery_errors = true
|
312
|
+
ActionMailer::Base.deliveries = []
|
313
|
+
|
314
|
+
@original_logger = TestMailer.logger
|
315
|
+
@recipient = 'test@localhost'
|
316
|
+
end
|
317
|
+
|
318
|
+
def teardown
|
319
|
+
TestMailer.logger = @original_logger
|
320
|
+
restore_delivery_method
|
321
|
+
end
|
322
|
+
|
323
|
+
def test_nested_parts
|
324
|
+
created = nil
|
325
|
+
assert_nothing_raised { created = TestMailer.create_nested_multipart(@recipient)}
|
326
|
+
assert_equal 2,created.parts.size
|
327
|
+
assert_equal 2,created.parts.first.parts.size
|
328
|
+
|
329
|
+
assert_equal "multipart/mixed", created.content_type
|
330
|
+
assert_equal "multipart/alternative", created.parts.first.content_type
|
331
|
+
assert_equal "bar", created.parts.first.header['foo'].to_s
|
332
|
+
assert_nil created.parts.first.charset
|
333
|
+
assert_equal "text/plain", created.parts.first.parts.first.content_type
|
334
|
+
assert_equal "text/html", created.parts.first.parts[1].content_type
|
335
|
+
assert_equal "application/octet-stream", created.parts[1].content_type
|
336
|
+
end
|
337
|
+
|
338
|
+
def test_nested_parts_with_body
|
339
|
+
created = nil
|
340
|
+
assert_nothing_raised { created = TestMailer.create_nested_multipart_with_body(@recipient)}
|
341
|
+
assert_equal 1,created.parts.size
|
342
|
+
assert_equal 2,created.parts.first.parts.size
|
343
|
+
|
344
|
+
assert_equal "multipart/mixed", created.content_type
|
345
|
+
assert_equal "multipart/alternative", created.parts.first.content_type
|
346
|
+
assert_equal "Nothing to see here.", created.parts.first.parts.first.body
|
347
|
+
assert_equal "text/plain", created.parts.first.parts.first.content_type
|
348
|
+
assert_equal "text/html", created.parts.first.parts[1].content_type
|
349
|
+
end
|
350
|
+
|
351
|
+
def test_attachment_with_custom_header
|
352
|
+
created = nil
|
353
|
+
assert_nothing_raised { created = TestMailer.create_attachment_with_custom_header(@recipient)}
|
354
|
+
assert_equal "<test@test.com>", created.parts[1].header['content-id'].to_s
|
355
|
+
end
|
356
|
+
|
357
|
+
def test_signed_up
|
358
|
+
Time.stubs(:now => Time.now)
|
359
|
+
|
360
|
+
expected = new_mail
|
361
|
+
expected.to = @recipient
|
362
|
+
expected.subject = "[Signed up] Welcome #{@recipient}"
|
363
|
+
expected.body = "Hello there, \n\nMr. #{@recipient}"
|
364
|
+
expected.from = "system@loudthinking.com"
|
365
|
+
expected.date = Time.now
|
366
|
+
|
367
|
+
created = nil
|
368
|
+
assert_nothing_raised { created = TestMailer.create_signed_up(@recipient) }
|
369
|
+
assert_not_nil created
|
370
|
+
assert_equal expected.encoded, created.encoded
|
371
|
+
|
372
|
+
assert_nothing_raised { TestMailer.deliver_signed_up(@recipient) }
|
373
|
+
assert_not_nil ActionMailer::Base.deliveries.first
|
374
|
+
assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
|
375
|
+
end
|
376
|
+
|
377
|
+
def test_custom_template
|
378
|
+
expected = new_mail
|
379
|
+
expected.to = @recipient
|
380
|
+
expected.subject = "[Signed up] Welcome #{@recipient}"
|
381
|
+
expected.body = "Hello there, \n\nMr. #{@recipient}"
|
382
|
+
expected.from = "system@loudthinking.com"
|
383
|
+
expected.date = Time.local(2004, 12, 12)
|
384
|
+
|
385
|
+
created = nil
|
386
|
+
assert_nothing_raised { created = TestMailer.create_custom_template(@recipient) }
|
387
|
+
assert_not_nil created
|
388
|
+
assert_equal expected.encoded, created.encoded
|
389
|
+
end
|
390
|
+
|
391
|
+
def test_custom_templating_extension
|
392
|
+
assert ActionView::Template.template_handler_extensions.include?("haml"), "haml extension was not registered"
|
393
|
+
|
394
|
+
# N.b., custom_templating_extension.text.plain.haml is expected to be in fixtures/test_mailer directory
|
395
|
+
expected = new_mail
|
396
|
+
expected.to = @recipient
|
397
|
+
expected.subject = "[Signed up] Welcome #{@recipient}"
|
398
|
+
expected.body = "Hello there, \n\nMr. #{@recipient}"
|
399
|
+
expected.from = "system@loudthinking.com"
|
400
|
+
expected.date = Time.local(2004, 12, 12)
|
401
|
+
|
402
|
+
# Stub the render method so no alternative renderers need be present.
|
403
|
+
ActionView::Base.any_instance.stubs(:render).returns("Hello there, \n\nMr. #{@recipient}")
|
404
|
+
|
405
|
+
# Now that the template is registered, there should be one part. The text/plain part.
|
406
|
+
created = nil
|
407
|
+
assert_nothing_raised { created = TestMailer.create_custom_templating_extension(@recipient) }
|
408
|
+
assert_not_nil created
|
409
|
+
assert_equal 2, created.parts.length
|
410
|
+
assert_equal 'text/plain', created.parts[0].content_type
|
411
|
+
assert_equal 'text/html', created.parts[1].content_type
|
412
|
+
end
|
413
|
+
|
414
|
+
def test_cancelled_account
|
415
|
+
expected = new_mail
|
416
|
+
expected.to = @recipient
|
417
|
+
expected.subject = "[Cancelled] Goodbye #{@recipient}"
|
418
|
+
expected.body = "Goodbye, Mr. #{@recipient}"
|
419
|
+
expected.from = "system@loudthinking.com"
|
420
|
+
expected.date = Time.local(2004, 12, 12)
|
421
|
+
|
422
|
+
created = nil
|
423
|
+
assert_nothing_raised { created = TestMailer.create_cancelled_account(@recipient) }
|
424
|
+
assert_not_nil created
|
425
|
+
assert_equal expected.encoded, created.encoded
|
426
|
+
|
427
|
+
assert_nothing_raised { TestMailer.deliver_cancelled_account(@recipient) }
|
428
|
+
assert_not_nil ActionMailer::Base.deliveries.first
|
429
|
+
assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
|
430
|
+
end
|
431
|
+
|
432
|
+
def test_cc_bcc
|
433
|
+
expected = new_mail
|
434
|
+
expected.to = @recipient
|
435
|
+
expected.subject = "testing bcc/cc"
|
436
|
+
expected.body = "Nothing to see here."
|
437
|
+
expected.from = "system@loudthinking.com"
|
438
|
+
expected.cc = "nobody@loudthinking.com"
|
439
|
+
expected.bcc = "root@loudthinking.com"
|
440
|
+
expected.date = Time.local 2004, 12, 12
|
441
|
+
|
442
|
+
created = nil
|
443
|
+
assert_nothing_raised do
|
444
|
+
created = TestMailer.create_cc_bcc @recipient
|
445
|
+
end
|
446
|
+
assert_not_nil created
|
447
|
+
assert_equal expected.encoded, created.encoded
|
448
|
+
|
449
|
+
assert_nothing_raised do
|
450
|
+
TestMailer.deliver_cc_bcc @recipient
|
451
|
+
end
|
452
|
+
|
453
|
+
assert_not_nil ActionMailer::Base.deliveries.first
|
454
|
+
assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
|
455
|
+
end
|
456
|
+
|
457
|
+
def test_reply_to
|
458
|
+
expected = new_mail
|
459
|
+
|
460
|
+
expected.to = @recipient
|
461
|
+
expected.subject = "testing reply_to"
|
462
|
+
expected.body = "Nothing to see here."
|
463
|
+
expected.from = "system@loudthinking.com"
|
464
|
+
expected.reply_to = "atraver@gmail.com"
|
465
|
+
expected.date = Time.local 2008, 5, 23
|
466
|
+
|
467
|
+
created = nil
|
468
|
+
assert_nothing_raised do
|
469
|
+
created = TestMailer.create_different_reply_to @recipient
|
470
|
+
end
|
471
|
+
assert_not_nil created
|
472
|
+
assert_equal expected.encoded, created.encoded
|
473
|
+
|
474
|
+
assert_nothing_raised do
|
475
|
+
TestMailer.deliver_different_reply_to @recipient
|
476
|
+
end
|
477
|
+
|
478
|
+
assert_not_nil ActionMailer::Base.deliveries.first
|
479
|
+
assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
|
480
|
+
end
|
481
|
+
|
482
|
+
def test_iso_charset
|
483
|
+
expected = new_mail( "iso-8859-1" )
|
484
|
+
expected.to = @recipient
|
485
|
+
expected.subject = encode "testing isø charsets", "iso-8859-1"
|
486
|
+
expected.body = "Nothing to see here."
|
487
|
+
expected.from = "system@loudthinking.com"
|
488
|
+
expected.cc = "nobody@loudthinking.com"
|
489
|
+
expected.bcc = "root@loudthinking.com"
|
490
|
+
expected.date = Time.local 2004, 12, 12
|
491
|
+
|
492
|
+
created = nil
|
493
|
+
assert_nothing_raised do
|
494
|
+
created = TestMailer.create_iso_charset @recipient
|
495
|
+
end
|
496
|
+
assert_not_nil created
|
497
|
+
assert_equal expected.encoded, created.encoded
|
498
|
+
|
499
|
+
assert_nothing_raised do
|
500
|
+
TestMailer.deliver_iso_charset @recipient
|
501
|
+
end
|
502
|
+
|
503
|
+
assert_not_nil ActionMailer::Base.deliveries.first
|
504
|
+
assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
|
505
|
+
end
|
506
|
+
|
507
|
+
def test_unencoded_subject
|
508
|
+
expected = new_mail
|
509
|
+
expected.to = @recipient
|
510
|
+
expected.subject = "testing unencoded subject"
|
511
|
+
expected.body = "Nothing to see here."
|
512
|
+
expected.from = "system@loudthinking.com"
|
513
|
+
expected.cc = "nobody@loudthinking.com"
|
514
|
+
expected.bcc = "root@loudthinking.com"
|
515
|
+
expected.date = Time.local 2004, 12, 12
|
516
|
+
|
517
|
+
created = nil
|
518
|
+
assert_nothing_raised do
|
519
|
+
created = TestMailer.create_unencoded_subject @recipient
|
520
|
+
end
|
521
|
+
assert_not_nil created
|
522
|
+
assert_equal expected.encoded, created.encoded
|
523
|
+
|
524
|
+
assert_nothing_raised do
|
525
|
+
TestMailer.deliver_unencoded_subject @recipient
|
526
|
+
end
|
527
|
+
|
528
|
+
assert_not_nil ActionMailer::Base.deliveries.first
|
529
|
+
assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
|
530
|
+
end
|
531
|
+
|
532
|
+
def test_instances_are_nil
|
533
|
+
assert_nil ActionMailer::Base.new
|
534
|
+
assert_nil TestMailer.new
|
535
|
+
end
|
536
|
+
|
537
|
+
def test_deliveries_array
|
538
|
+
assert_not_nil ActionMailer::Base.deliveries
|
539
|
+
assert_equal 0, ActionMailer::Base.deliveries.size
|
540
|
+
TestMailer.deliver_signed_up(@recipient)
|
541
|
+
assert_equal 1, ActionMailer::Base.deliveries.size
|
542
|
+
assert_not_nil ActionMailer::Base.deliveries.first
|
543
|
+
end
|
544
|
+
|
545
|
+
def test_perform_deliveries_flag
|
546
|
+
ActionMailer::Base.perform_deliveries = false
|
547
|
+
TestMailer.deliver_signed_up(@recipient)
|
548
|
+
assert_equal 0, ActionMailer::Base.deliveries.size
|
549
|
+
ActionMailer::Base.perform_deliveries = true
|
550
|
+
TestMailer.deliver_signed_up(@recipient)
|
551
|
+
assert_equal 1, ActionMailer::Base.deliveries.size
|
552
|
+
end
|
553
|
+
|
554
|
+
def test_doesnt_raise_errors_when_raise_delivery_errors_is_false
|
555
|
+
ActionMailer::Base.raise_delivery_errors = false
|
556
|
+
TestMailer.any_instance.expects(:perform_delivery_test).raises(Exception)
|
557
|
+
assert_nothing_raised { TestMailer.deliver_signed_up(@recipient) }
|
558
|
+
end
|
559
|
+
|
560
|
+
def test_performs_delivery_via_sendmail
|
561
|
+
sm = mock()
|
562
|
+
sm.expects(:print).with(anything)
|
563
|
+
sm.expects(:flush)
|
564
|
+
IO.expects(:popen).once.with('/usr/sbin/sendmail -i -t', 'w+').yields(sm)
|
565
|
+
ActionMailer::Base.delivery_method = :sendmail
|
566
|
+
TestMailer.deliver_signed_up(@recipient)
|
567
|
+
end
|
568
|
+
|
569
|
+
def test_delivery_logs_sent_mail
|
570
|
+
mail = TestMailer.create_signed_up(@recipient)
|
571
|
+
logger = mock()
|
572
|
+
logger.expects(:info).with("Sent mail to #{@recipient}")
|
573
|
+
logger.expects(:debug).with() do |logged_text|
|
574
|
+
logged_text =~ /\[Signed up\] Welcome/
|
575
|
+
end
|
576
|
+
TestMailer.logger = logger
|
577
|
+
TestMailer.deliver_signed_up(@recipient)
|
578
|
+
end
|
579
|
+
|
580
|
+
def test_unquote_quoted_printable_subject
|
581
|
+
msg = <<EOF
|
582
|
+
From: me@example.com
|
583
|
+
Subject: =?utf-8?Q?testing_testing_=D6=A4?=
|
584
|
+
Content-Type: text/plain; charset=iso-8859-1
|
585
|
+
|
586
|
+
The body
|
587
|
+
EOF
|
588
|
+
mail = TMail::Mail.parse(msg)
|
589
|
+
assert_equal "testing testing \326\244", mail.subject
|
590
|
+
assert_equal "=?utf-8?Q?testing_testing_=D6=A4?=", mail.quoted_subject
|
591
|
+
end
|
592
|
+
|
593
|
+
def test_unquote_7bit_subject
|
594
|
+
msg = <<EOF
|
595
|
+
From: me@example.com
|
596
|
+
Subject: this == working?
|
597
|
+
Content-Type: text/plain; charset=iso-8859-1
|
598
|
+
|
599
|
+
The body
|
600
|
+
EOF
|
601
|
+
mail = TMail::Mail.parse(msg)
|
602
|
+
assert_equal "this == working?", mail.subject
|
603
|
+
assert_equal "this == working?", mail.quoted_subject
|
604
|
+
end
|
605
|
+
|
606
|
+
def test_unquote_7bit_body
|
607
|
+
msg = <<EOF
|
608
|
+
From: me@example.com
|
609
|
+
Subject: subject
|
610
|
+
Content-Type: text/plain; charset=iso-8859-1
|
611
|
+
Content-Transfer-Encoding: 7bit
|
612
|
+
|
613
|
+
The=3Dbody
|
614
|
+
EOF
|
615
|
+
mail = TMail::Mail.parse(msg)
|
616
|
+
assert_equal "The=3Dbody", mail.body.strip
|
617
|
+
assert_equal "The=3Dbody", mail.quoted_body.strip
|
618
|
+
end
|
619
|
+
|
620
|
+
def test_unquote_quoted_printable_body
|
621
|
+
msg = <<EOF
|
622
|
+
From: me@example.com
|
623
|
+
Subject: subject
|
624
|
+
Content-Type: text/plain; charset=iso-8859-1
|
625
|
+
Content-Transfer-Encoding: quoted-printable
|
626
|
+
|
627
|
+
The=3Dbody
|
628
|
+
EOF
|
629
|
+
mail = TMail::Mail.parse(msg)
|
630
|
+
assert_equal "The=body", mail.body.strip
|
631
|
+
assert_equal "The=3Dbody", mail.quoted_body.strip
|
632
|
+
end
|
633
|
+
|
634
|
+
def test_unquote_base64_body
|
635
|
+
msg = <<EOF
|
636
|
+
From: me@example.com
|
637
|
+
Subject: subject
|
638
|
+
Content-Type: text/plain; charset=iso-8859-1
|
639
|
+
Content-Transfer-Encoding: base64
|
640
|
+
|
641
|
+
VGhlIGJvZHk=
|
642
|
+
EOF
|
643
|
+
mail = TMail::Mail.parse(msg)
|
644
|
+
assert_equal "The body", mail.body.strip
|
645
|
+
assert_equal "VGhlIGJvZHk=", mail.quoted_body.strip
|
646
|
+
end
|
647
|
+
|
648
|
+
def test_extended_headers
|
649
|
+
@recipient = "Grytøyr <test@localhost>"
|
650
|
+
|
651
|
+
expected = new_mail "iso-8859-1"
|
652
|
+
expected.to = quote_address_if_necessary @recipient, "iso-8859-1"
|
653
|
+
expected.subject = "testing extended headers"
|
654
|
+
expected.body = "Nothing to see here."
|
655
|
+
expected.from = quote_address_if_necessary "Grytøyr <stian1@example.net>", "iso-8859-1"
|
656
|
+
expected.cc = quote_address_if_necessary "Grytøyr <stian2@example.net>", "iso-8859-1"
|
657
|
+
expected.bcc = quote_address_if_necessary "Grytøyr <stian3@example.net>", "iso-8859-1"
|
658
|
+
expected.date = Time.local 2004, 12, 12
|
659
|
+
|
660
|
+
created = nil
|
661
|
+
assert_nothing_raised do
|
662
|
+
created = TestMailer.create_extended_headers @recipient
|
663
|
+
end
|
664
|
+
|
665
|
+
assert_not_nil created
|
666
|
+
assert_equal expected.encoded, created.encoded
|
667
|
+
|
668
|
+
assert_nothing_raised do
|
669
|
+
TestMailer.deliver_extended_headers @recipient
|
670
|
+
end
|
671
|
+
|
672
|
+
assert_not_nil ActionMailer::Base.deliveries.first
|
673
|
+
assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
|
674
|
+
end
|
675
|
+
|
676
|
+
def test_utf8_body_is_not_quoted
|
677
|
+
@recipient = "Foo áëô îü <extended@example.net>"
|
678
|
+
expected = new_mail "utf-8"
|
679
|
+
expected.to = quote_address_if_necessary @recipient, "utf-8"
|
680
|
+
expected.subject = "testing utf-8 body"
|
681
|
+
expected.body = "åœö blah"
|
682
|
+
expected.from = quote_address_if_necessary @recipient, "utf-8"
|
683
|
+
expected.cc = quote_address_if_necessary @recipient, "utf-8"
|
684
|
+
expected.bcc = quote_address_if_necessary @recipient, "utf-8"
|
685
|
+
expected.date = Time.local 2004, 12, 12
|
686
|
+
|
687
|
+
created = TestMailer.create_utf8_body @recipient
|
688
|
+
assert_match(/åœö blah/, created.encoded)
|
689
|
+
end
|
690
|
+
|
691
|
+
def test_multiple_utf8_recipients
|
692
|
+
@recipient = ["\"Foo áëô îü\" <extended@example.net>", "\"Example Recipient\" <me@example.com>"]
|
693
|
+
expected = new_mail "utf-8"
|
694
|
+
expected.to = quote_address_if_necessary @recipient, "utf-8"
|
695
|
+
expected.subject = "testing utf-8 body"
|
696
|
+
expected.body = "åœö blah"
|
697
|
+
expected.from = quote_address_if_necessary @recipient.first, "utf-8"
|
698
|
+
expected.cc = quote_address_if_necessary @recipient, "utf-8"
|
699
|
+
expected.bcc = quote_address_if_necessary @recipient, "utf-8"
|
700
|
+
expected.date = Time.local 2004, 12, 12
|
701
|
+
|
702
|
+
created = TestMailer.create_utf8_body @recipient
|
703
|
+
assert_match(/\nFrom: =\?utf-8\?Q\?Foo_.*?\?= <extended@example.net>\r/, created.encoded)
|
704
|
+
assert_match(/\nTo: =\?utf-8\?Q\?Foo_.*?\?= <extended@example.net>, Example Recipient <me/, created.encoded)
|
705
|
+
end
|
706
|
+
|
707
|
+
def test_receive_decodes_base64_encoded_mail
|
708
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email")
|
709
|
+
TestMailer.receive(fixture)
|
710
|
+
assert_match(/Jamis/, TestMailer.received_body)
|
711
|
+
end
|
712
|
+
|
713
|
+
def test_receive_attachments
|
714
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email2")
|
715
|
+
mail = TMail::Mail.parse(fixture)
|
716
|
+
attachment = mail.attachments.last
|
717
|
+
assert_equal "smime.p7s", attachment.original_filename
|
718
|
+
assert_equal "application/pkcs7-signature", attachment.content_type
|
719
|
+
end
|
720
|
+
|
721
|
+
def test_decode_attachment_without_charset
|
722
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email3")
|
723
|
+
mail = TMail::Mail.parse(fixture)
|
724
|
+
attachment = mail.attachments.last
|
725
|
+
assert_equal 1026, attachment.read.length
|
726
|
+
end
|
727
|
+
|
728
|
+
def test_attachment_using_content_location
|
729
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email12")
|
730
|
+
mail = TMail::Mail.parse(fixture)
|
731
|
+
assert_equal 1, mail.attachments.length
|
732
|
+
assert_equal "Photo25.jpg", mail.attachments.first.original_filename
|
733
|
+
end
|
734
|
+
|
735
|
+
def test_attachment_with_text_type
|
736
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email13")
|
737
|
+
mail = TMail::Mail.parse(fixture)
|
738
|
+
assert mail.has_attachments?
|
739
|
+
assert_equal 1, mail.attachments.length
|
740
|
+
assert_equal "hello.rb", mail.attachments.first.original_filename
|
741
|
+
end
|
742
|
+
|
743
|
+
def test_decode_part_without_content_type
|
744
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email4")
|
745
|
+
mail = TMail::Mail.parse(fixture)
|
746
|
+
assert_nothing_raised { mail.body }
|
747
|
+
end
|
748
|
+
|
749
|
+
def test_decode_message_without_content_type
|
750
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email5")
|
751
|
+
mail = TMail::Mail.parse(fixture)
|
752
|
+
assert_nothing_raised { mail.body }
|
753
|
+
end
|
754
|
+
|
755
|
+
def test_decode_message_with_incorrect_charset
|
756
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email6")
|
757
|
+
mail = TMail::Mail.parse(fixture)
|
758
|
+
assert_nothing_raised { mail.body }
|
759
|
+
end
|
760
|
+
|
761
|
+
def test_multipart_with_mime_version
|
762
|
+
mail = TestMailer.create_multipart_with_mime_version(@recipient)
|
763
|
+
assert_equal "1.1", mail.mime_version
|
764
|
+
end
|
765
|
+
|
766
|
+
def test_multipart_with_utf8_subject
|
767
|
+
mail = TestMailer.create_multipart_with_utf8_subject(@recipient)
|
768
|
+
assert_match(/\nSubject: =\?utf-8\?Q\?Foo_.*?\?=/, mail.encoded)
|
769
|
+
end
|
770
|
+
|
771
|
+
def test_implicitly_multipart_with_utf8
|
772
|
+
mail = TestMailer.create_implicitly_multipart_with_utf8
|
773
|
+
assert_match(/\nSubject: =\?utf-8\?Q\?Foo_.*?\?=/, mail.encoded)
|
774
|
+
end
|
775
|
+
|
776
|
+
def test_explicitly_multipart_messages
|
777
|
+
mail = TestMailer.create_explicitly_multipart_example(@recipient)
|
778
|
+
assert_equal 3, mail.parts.length
|
779
|
+
assert_nil mail.content_type
|
780
|
+
assert_equal "text/plain", mail.parts[0].content_type
|
781
|
+
|
782
|
+
assert_equal "text/html", mail.parts[1].content_type
|
783
|
+
assert_equal "iso-8859-1", mail.parts[1].sub_header("content-type", "charset")
|
784
|
+
assert_equal "inline", mail.parts[1].content_disposition
|
785
|
+
|
786
|
+
assert_equal "image/jpeg", mail.parts[2].content_type
|
787
|
+
assert_equal "attachment", mail.parts[2].content_disposition
|
788
|
+
assert_equal "foo.jpg", mail.parts[2].sub_header("content-disposition", "filename")
|
789
|
+
assert_equal "foo.jpg", mail.parts[2].sub_header("content-type", "name")
|
790
|
+
assert_nil mail.parts[2].sub_header("content-type", "charset")
|
791
|
+
end
|
792
|
+
|
793
|
+
def test_explicitly_multipart_with_content_type
|
794
|
+
mail = TestMailer.create_explicitly_multipart_example(@recipient, "multipart/alternative")
|
795
|
+
assert_equal 3, mail.parts.length
|
796
|
+
assert_equal "multipart/alternative", mail.content_type
|
797
|
+
end
|
798
|
+
|
799
|
+
def test_explicitly_multipart_with_invalid_content_type
|
800
|
+
mail = TestMailer.create_explicitly_multipart_example(@recipient, "text/xml")
|
801
|
+
assert_equal 3, mail.parts.length
|
802
|
+
assert_nil mail.content_type
|
803
|
+
end
|
804
|
+
|
805
|
+
def test_implicitly_multipart_messages
|
806
|
+
assert ActionView::Template.template_handler_extensions.include?("bak"), "bak extension was not registered"
|
807
|
+
|
808
|
+
mail = TestMailer.create_implicitly_multipart_example(@recipient)
|
809
|
+
assert_equal 3, mail.parts.length
|
810
|
+
assert_equal "1.0", mail.mime_version
|
811
|
+
assert_equal "multipart/alternative", mail.content_type
|
812
|
+
assert_equal "text/yaml", mail.parts[0].content_type
|
813
|
+
assert_equal "utf-8", mail.parts[0].sub_header("content-type", "charset")
|
814
|
+
assert_equal "text/plain", mail.parts[1].content_type
|
815
|
+
assert_equal "utf-8", mail.parts[1].sub_header("content-type", "charset")
|
816
|
+
assert_equal "text/html", mail.parts[2].content_type
|
817
|
+
assert_equal "utf-8", mail.parts[2].sub_header("content-type", "charset")
|
818
|
+
end
|
819
|
+
|
820
|
+
def test_implicitly_multipart_messages_with_custom_order
|
821
|
+
assert ActionView::Template.template_handler_extensions.include?("bak"), "bak extension was not registered"
|
822
|
+
|
823
|
+
mail = TestMailer.create_implicitly_multipart_example(@recipient, nil, ["text/yaml", "text/plain"])
|
824
|
+
assert_equal 3, mail.parts.length
|
825
|
+
assert_equal "text/html", mail.parts[0].content_type
|
826
|
+
assert_equal "text/plain", mail.parts[1].content_type
|
827
|
+
assert_equal "text/yaml", mail.parts[2].content_type
|
828
|
+
end
|
829
|
+
|
830
|
+
def test_implicitly_multipart_messages_with_charset
|
831
|
+
mail = TestMailer.create_implicitly_multipart_example(@recipient, 'iso-8859-1')
|
832
|
+
|
833
|
+
assert_equal "multipart/alternative", mail.header['content-type'].body
|
834
|
+
|
835
|
+
assert_equal 'iso-8859-1', mail.parts[0].sub_header("content-type", "charset")
|
836
|
+
assert_equal 'iso-8859-1', mail.parts[1].sub_header("content-type", "charset")
|
837
|
+
assert_equal 'iso-8859-1', mail.parts[2].sub_header("content-type", "charset")
|
838
|
+
end
|
839
|
+
|
840
|
+
def test_html_mail
|
841
|
+
mail = TestMailer.create_html_mail(@recipient)
|
842
|
+
assert_equal "text/html", mail.content_type
|
843
|
+
end
|
844
|
+
|
845
|
+
def test_html_mail_with_underscores
|
846
|
+
mail = TestMailer.create_html_mail_with_underscores(@recipient)
|
847
|
+
assert_equal %{<a href="http://google.com" target="_blank">_Google</a>}, mail.body
|
848
|
+
end
|
849
|
+
|
850
|
+
def test_various_newlines
|
851
|
+
mail = TestMailer.create_various_newlines(@recipient)
|
852
|
+
assert_equal("line #1\nline #2\nline #3\nline #4\n\n" +
|
853
|
+
"line #5\n\nline#6\n\nline #7", mail.body)
|
854
|
+
end
|
855
|
+
|
856
|
+
def test_various_newlines_multipart
|
857
|
+
mail = TestMailer.create_various_newlines_multipart(@recipient)
|
858
|
+
assert_equal "line #1\nline #2\nline #3\nline #4\n\n", mail.parts[0].body
|
859
|
+
assert_equal "<p>line #1</p>\n<p>line #2</p>\n<p>line #3</p>\n<p>line #4</p>\n\n", mail.parts[1].body
|
860
|
+
end
|
861
|
+
|
862
|
+
def test_headers_removed_on_smtp_delivery
|
863
|
+
ActionMailer::Base.delivery_method = :smtp
|
864
|
+
TestMailer.deliver_cc_bcc(@recipient)
|
865
|
+
assert MockSMTP.deliveries[0][2].include?("root@loudthinking.com")
|
866
|
+
assert MockSMTP.deliveries[0][2].include?("nobody@loudthinking.com")
|
867
|
+
assert MockSMTP.deliveries[0][2].include?(@recipient)
|
868
|
+
assert_match %r{^Cc: nobody@loudthinking.com}, MockSMTP.deliveries[0][0]
|
869
|
+
assert_match %r{^To: #{@recipient}}, MockSMTP.deliveries[0][0]
|
870
|
+
assert_no_match %r{^Bcc: root@loudthinking.com}, MockSMTP.deliveries[0][0]
|
871
|
+
end
|
872
|
+
|
873
|
+
def test_recursive_multipart_processing
|
874
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email7")
|
875
|
+
mail = TMail::Mail.parse(fixture)
|
876
|
+
assert_equal "This is the first part.\n\nAttachment: test.rb\nAttachment: test.pdf\n\n\nAttachment: smime.p7s\n", mail.body
|
877
|
+
end
|
878
|
+
|
879
|
+
def test_decode_encoded_attachment_filename
|
880
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email8")
|
881
|
+
mail = TMail::Mail.parse(fixture)
|
882
|
+
attachment = mail.attachments.last
|
883
|
+
|
884
|
+
expected = "01 Quien Te Dij\212at. Pitbull.mp3"
|
885
|
+
expected.force_encoding(Encoding::ASCII_8BIT) if expected.respond_to?(:force_encoding)
|
886
|
+
|
887
|
+
assert_equal expected, attachment.original_filename
|
888
|
+
end
|
889
|
+
|
890
|
+
def test_wrong_mail_header
|
891
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email9")
|
892
|
+
assert_raise(TMail::SyntaxError) { TMail::Mail.parse(fixture) }
|
893
|
+
end
|
894
|
+
|
895
|
+
def test_decode_message_with_unknown_charset
|
896
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email10")
|
897
|
+
mail = TMail::Mail.parse(fixture)
|
898
|
+
assert_nothing_raised { mail.body }
|
899
|
+
end
|
900
|
+
|
901
|
+
def test_empty_header_values_omitted
|
902
|
+
result = TestMailer.create_unnamed_attachment(@recipient).encoded
|
903
|
+
assert_match %r{Content-Type: application/octet-stream[^;]}, result
|
904
|
+
assert_match %r{Content-Disposition: attachment[^;]}, result
|
905
|
+
end
|
906
|
+
|
907
|
+
def test_headers_with_nonalpha_chars
|
908
|
+
mail = TestMailer.create_headers_with_nonalpha_chars(@recipient)
|
909
|
+
assert !mail.from_addrs.empty?
|
910
|
+
assert !mail.cc_addrs.empty?
|
911
|
+
assert !mail.bcc_addrs.empty?
|
912
|
+
assert_match(/:/, mail.from_addrs.to_s)
|
913
|
+
assert_match(/:/, mail.cc_addrs.to_s)
|
914
|
+
assert_match(/:/, mail.bcc_addrs.to_s)
|
915
|
+
end
|
916
|
+
|
917
|
+
def test_deliver_with_mail_object
|
918
|
+
mail = TestMailer.create_headers_with_nonalpha_chars(@recipient)
|
919
|
+
assert_nothing_raised { TestMailer.deliver(mail) }
|
920
|
+
assert_equal 1, TestMailer.deliveries.length
|
921
|
+
end
|
922
|
+
|
923
|
+
def test_multipart_with_template_path_with_dots
|
924
|
+
mail = FunkyPathMailer.create_multipart_with_template_path_with_dots(@recipient)
|
925
|
+
assert_equal 2, mail.parts.length
|
926
|
+
assert_equal 'text/plain', mail.parts[0].content_type
|
927
|
+
assert_equal 'utf-8', mail.parts[0].charset
|
928
|
+
end
|
929
|
+
|
930
|
+
def test_custom_content_type_attributes
|
931
|
+
mail = TestMailer.create_custom_content_type_attributes
|
932
|
+
assert_match %r{format=flowed}, mail['content-type'].to_s
|
933
|
+
assert_match %r{charset=utf-8}, mail['content-type'].to_s
|
934
|
+
end
|
935
|
+
|
936
|
+
def test_return_path_with_create
|
937
|
+
mail = TestMailer.create_return_path
|
938
|
+
assert_equal "<another@somewhere.test>", mail['return-path'].to_s
|
939
|
+
end
|
940
|
+
|
941
|
+
def test_return_path_with_deliver
|
942
|
+
ActionMailer::Base.delivery_method = :smtp
|
943
|
+
TestMailer.deliver_return_path
|
944
|
+
assert_match %r{^Return-Path: <another@somewhere.test>}, MockSMTP.deliveries[0][0]
|
945
|
+
assert_equal "another@somewhere.test", MockSMTP.deliveries[0][1].to_s
|
946
|
+
end
|
947
|
+
|
948
|
+
def test_body_is_stored_as_an_ivar
|
949
|
+
mail = TestMailer.create_body_ivar(@recipient)
|
950
|
+
assert_equal "body: foo\nbar: baz", mail.body
|
951
|
+
end
|
952
|
+
|
953
|
+
def test_starttls_is_enabled_if_supported
|
954
|
+
ActionMailer::Base.smtp_settings[:enable_starttls_auto] = true
|
955
|
+
MockSMTP.any_instance.expects(:respond_to?).with(:enable_starttls_auto).returns(true)
|
956
|
+
MockSMTP.any_instance.expects(:enable_starttls_auto)
|
957
|
+
ActionMailer::Base.delivery_method = :smtp
|
958
|
+
TestMailer.deliver_signed_up(@recipient)
|
959
|
+
end
|
960
|
+
|
961
|
+
def test_starttls_is_disabled_if_not_supported
|
962
|
+
ActionMailer::Base.smtp_settings[:enable_starttls_auto] = true
|
963
|
+
MockSMTP.any_instance.expects(:respond_to?).with(:enable_starttls_auto).returns(false)
|
964
|
+
MockSMTP.any_instance.expects(:enable_starttls_auto).never
|
965
|
+
ActionMailer::Base.delivery_method = :smtp
|
966
|
+
TestMailer.deliver_signed_up(@recipient)
|
967
|
+
end
|
968
|
+
|
969
|
+
def test_starttls_is_not_enabled
|
970
|
+
ActionMailer::Base.smtp_settings[:enable_starttls_auto] = false
|
971
|
+
MockSMTP.any_instance.expects(:respond_to?).never
|
972
|
+
MockSMTP.any_instance.expects(:enable_starttls_auto).never
|
973
|
+
ActionMailer::Base.delivery_method = :smtp
|
974
|
+
TestMailer.deliver_signed_up(@recipient)
|
975
|
+
ensure
|
976
|
+
ActionMailer::Base.smtp_settings[:enable_starttls_auto] = true
|
977
|
+
end
|
978
|
+
end
|
979
|
+
|
980
|
+
class InheritableTemplateRootTest < Test::Unit::TestCase
|
981
|
+
def test_attr
|
982
|
+
expected = "#{File.dirname(__FILE__)}/fixtures/path.with.dots"
|
983
|
+
assert_equal expected, FunkyPathMailer.template_root.to_s
|
984
|
+
|
985
|
+
sub = Class.new(FunkyPathMailer)
|
986
|
+
sub.template_root = 'test/path'
|
987
|
+
|
988
|
+
assert_equal 'test/path', sub.template_root.to_s
|
989
|
+
assert_equal expected, FunkyPathMailer.template_root.to_s
|
990
|
+
end
|
991
|
+
end
|
992
|
+
|
993
|
+
class MethodNamingTest < Test::Unit::TestCase
|
994
|
+
class TestMailer < ActionMailer::Base
|
995
|
+
def send
|
996
|
+
body 'foo'
|
997
|
+
end
|
998
|
+
end
|
999
|
+
|
1000
|
+
def setup
|
1001
|
+
set_delivery_method :test
|
1002
|
+
ActionMailer::Base.perform_deliveries = true
|
1003
|
+
ActionMailer::Base.deliveries = []
|
1004
|
+
end
|
1005
|
+
|
1006
|
+
def teardown
|
1007
|
+
restore_delivery_method
|
1008
|
+
end
|
1009
|
+
|
1010
|
+
def test_send_method
|
1011
|
+
assert_nothing_raised do
|
1012
|
+
assert_emails 1 do
|
1013
|
+
TestMailer.deliver_send
|
1014
|
+
end
|
1015
|
+
end
|
1016
|
+
end
|
1017
|
+
end
|
1018
|
+
|
1019
|
+
class RespondToTest < Test::Unit::TestCase
|
1020
|
+
class RespondToMailer < ActionMailer::Base; end
|
1021
|
+
|
1022
|
+
def setup
|
1023
|
+
set_delivery_method :test
|
1024
|
+
end
|
1025
|
+
|
1026
|
+
def teardown
|
1027
|
+
restore_delivery_method
|
1028
|
+
end
|
1029
|
+
|
1030
|
+
def test_should_respond_to_new
|
1031
|
+
assert RespondToMailer.respond_to?(:new)
|
1032
|
+
end
|
1033
|
+
|
1034
|
+
def test_should_respond_to_create_with_template_suffix
|
1035
|
+
assert RespondToMailer.respond_to?(:create_any_old_template)
|
1036
|
+
end
|
1037
|
+
|
1038
|
+
def test_should_respond_to_deliver_with_template_suffix
|
1039
|
+
assert RespondToMailer.respond_to?(:deliver_any_old_template)
|
1040
|
+
end
|
1041
|
+
|
1042
|
+
def test_should_not_respond_to_new_with_template_suffix
|
1043
|
+
assert !RespondToMailer.respond_to?(:new_any_old_template)
|
1044
|
+
end
|
1045
|
+
|
1046
|
+
def test_should_not_respond_to_create_with_template_suffix_unless_it_is_separated_by_an_underscore
|
1047
|
+
assert !RespondToMailer.respond_to?(:createany_old_template)
|
1048
|
+
end
|
1049
|
+
|
1050
|
+
def test_should_not_respond_to_deliver_with_template_suffix_unless_it_is_separated_by_an_underscore
|
1051
|
+
assert !RespondToMailer.respond_to?(:deliverany_old_template)
|
1052
|
+
end
|
1053
|
+
|
1054
|
+
def test_should_not_respond_to_create_with_template_suffix_if_it_begins_with_a_uppercase_letter
|
1055
|
+
assert !RespondToMailer.respond_to?(:create_Any_old_template)
|
1056
|
+
end
|
1057
|
+
|
1058
|
+
def test_should_not_respond_to_deliver_with_template_suffix_if_it_begins_with_a_uppercase_letter
|
1059
|
+
assert !RespondToMailer.respond_to?(:deliver_Any_old_template)
|
1060
|
+
end
|
1061
|
+
|
1062
|
+
def test_should_not_respond_to_create_with_template_suffix_if_it_begins_with_a_digit
|
1063
|
+
assert !RespondToMailer.respond_to?(:create_1_template)
|
1064
|
+
end
|
1065
|
+
|
1066
|
+
def test_should_not_respond_to_deliver_with_template_suffix_if_it_begins_with_a_digit
|
1067
|
+
assert !RespondToMailer.respond_to?(:deliver_1_template)
|
1068
|
+
end
|
1069
|
+
|
1070
|
+
def test_should_not_respond_to_method_where_deliver_is_not_a_suffix
|
1071
|
+
assert !RespondToMailer.respond_to?(:foo_deliver_template)
|
1072
|
+
end
|
1073
|
+
|
1074
|
+
def test_should_still_raise_exception_with_expected_message_when_calling_an_undefined_method
|
1075
|
+
error = assert_raise NoMethodError do
|
1076
|
+
RespondToMailer.not_a_method
|
1077
|
+
end
|
1078
|
+
|
1079
|
+
assert_match /undefined method.*not_a_method/, error.message
|
1080
|
+
end
|
1081
|
+
end
|