actionmailer-rack-upgrade 2.3.14.1

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