actionmailer 0.9.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionmailer might be problematic. Click here for more details.
- data/CHANGELOG +51 -2
- data/README +5 -6
- data/lib/action_mailer.rb +10 -3
- data/lib/action_mailer/adv_attr_accessor.rb +56 -0
- data/lib/action_mailer/base.rb +244 -120
- data/lib/action_mailer/helpers.rb +115 -0
- data/lib/action_mailer/part.rb +76 -0
- data/lib/action_mailer/part_container.rb +25 -0
- data/lib/action_mailer/quoting.rb +99 -0
- data/lib/action_mailer/utils.rb +8 -0
- data/lib/action_mailer/vendor/tmail/attachments.rb +6 -5
- data/lib/action_mailer/vendor/tmail/encode.rb +1 -0
- data/lib/action_mailer/vendor/tmail/facade.rb +2 -1
- data/lib/action_mailer/vendor/tmail/mail.rb +4 -0
- data/lib/action_mailer/vendor/tmail/net.rb +1 -1
- data/lib/action_mailer/vendor/tmail/quoting.rb +103 -80
- data/lib/action_mailer/vendor/tmail/scanner_r.rb +2 -2
- data/lib/action_mailer/vendor/tmail/utils.rb +9 -5
- data/rakefile +4 -4
- data/test/fixtures/helper_mailer/use_helper.rhtml +1 -0
- data/test/fixtures/helper_mailer/use_helper_method.rhtml +1 -0
- data/test/fixtures/helper_mailer/use_mail_helper.rhtml +5 -0
- data/test/fixtures/helper_mailer/use_test_helper.rhtml +1 -0
- data/test/fixtures/helpers/test_helper.rb +5 -0
- data/test/fixtures/raw_email +14 -0
- data/test/fixtures/raw_email10 +20 -0
- data/test/fixtures/raw_email11 +34 -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 +56 -0
- data/test/fixtures/raw_email8 +47 -0
- data/test/fixtures/raw_email9 +28 -0
- data/test/fixtures/test_mailer/implicitly_multipart_example.text.html.rhtml +10 -0
- data/test/fixtures/test_mailer/implicitly_multipart_example.text.plain.rhtml +2 -0
- data/test/fixtures/test_mailer/implicitly_multipart_example.text.yaml.rhtml +1 -0
- data/test/mail_helper_test.rb +97 -0
- data/test/mail_service_test.rb +391 -30
- metadata +32 -4
@@ -0,0 +1,56 @@
|
|
1
|
+
Mime-Version: 1.0 (Apple Message framework v730)
|
2
|
+
Content-Type: multipart/mixed; boundary=Apple-Mail-13-196941151
|
3
|
+
Message-Id: <9169D984-4E0B-45EF-82D4-8F5E53AD7012@example.com>
|
4
|
+
From: foo@example.com
|
5
|
+
Subject: testing
|
6
|
+
Date: Mon, 6 Jun 2005 22:21:22 +0200
|
7
|
+
To: blah@example.com
|
8
|
+
|
9
|
+
|
10
|
+
--Apple-Mail-13-196941151
|
11
|
+
Content-Type: multipart/mixed;
|
12
|
+
boundary=Apple-Mail-12-196940926
|
13
|
+
|
14
|
+
|
15
|
+
--Apple-Mail-12-196940926
|
16
|
+
Content-Transfer-Encoding: quoted-printable
|
17
|
+
Content-Type: text/plain;
|
18
|
+
charset=ISO-8859-1;
|
19
|
+
delsp=yes;
|
20
|
+
format=flowed
|
21
|
+
|
22
|
+
This is the first part.
|
23
|
+
|
24
|
+
--Apple-Mail-12-196940926
|
25
|
+
Content-Transfer-Encoding: base64
|
26
|
+
Content-Type: application/pdf;
|
27
|
+
x-unix-mode=0666;
|
28
|
+
name="test.pdf"
|
29
|
+
Content-Disposition: inline;
|
30
|
+
filename=test.pdf
|
31
|
+
|
32
|
+
YmxhaCBibGFoIGJsYWg=
|
33
|
+
|
34
|
+
--Apple-Mail-12-196940926
|
35
|
+
Content-Transfer-Encoding: 7bit
|
36
|
+
Content-Type: text/plain;
|
37
|
+
charset=US-ASCII;
|
38
|
+
format=flowed
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
--Apple-Mail-12-196940926--
|
43
|
+
|
44
|
+
--Apple-Mail-13-196941151
|
45
|
+
Content-Transfer-Encoding: base64
|
46
|
+
Content-Type: application/pkcs7-signature;
|
47
|
+
name=smime.p7s
|
48
|
+
Content-Disposition: attachment;
|
49
|
+
filename=smime.p7s
|
50
|
+
|
51
|
+
jamisSqGSIb3DQEHAqCAMIjamisxCzAJBgUrDgMCGgUAMIAGCSqGSjamisEHAQAAoIIFSjCCBUYw
|
52
|
+
ggQujamisQICBD++ukQwDQYJKojamisNAQEFBQAwMTELMAkGA1UEBhMCRjamisAKBgNVBAoTA1RE
|
53
|
+
QzEUMBIGjamisxMLVERDIE9DRVMgQ0jamisNMDQwMjI5MTE1OTAxWhcNMDYwMjamisIyOTAxWjCB
|
54
|
+
gDELMAkGA1UEjamisEsxKTAnBgNVBAoTIEjamisuIG9yZ2FuaXNhdG9yaXNrIHRpbjamisRuaW5=
|
55
|
+
|
56
|
+
--Apple-Mail-13-196941151--
|
@@ -0,0 +1,47 @@
|
|
1
|
+
From xxxxxxxxx.xxxxxxx@gmail.com Sun May 8 19:07:09 2005
|
2
|
+
Return-Path: <xxxxxxxxx.xxxxxxx@gmail.com>
|
3
|
+
Message-ID: <e85734b90505081209eaaa17b@mail.gmail.com>
|
4
|
+
Date: Sun, 8 May 2005 14:09:11 -0500
|
5
|
+
From: xxxxxxxxx xxxxxxx <xxxxxxxxx.xxxxxxx@gmail.com>
|
6
|
+
Reply-To: xxxxxxxxx xxxxxxx <xxxxxxxxx.xxxxxxx@gmail.com>
|
7
|
+
To: xxxxx xxxx <xxxxx@xxxxxxxxx.com>
|
8
|
+
Subject: Fwd: Signed email causes file attachments
|
9
|
+
In-Reply-To: <F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@mac.com>
|
10
|
+
Mime-Version: 1.0
|
11
|
+
Content-Type: multipart/mixed;
|
12
|
+
boundary="----=_Part_5028_7368284.1115579351471"
|
13
|
+
References: <F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@mac.com>
|
14
|
+
|
15
|
+
------=_Part_5028_7368284.1115579351471
|
16
|
+
Content-Type: text/plain; charset=ISO-8859-1
|
17
|
+
Content-Transfer-Encoding: quoted-printable
|
18
|
+
Content-Disposition: inline
|
19
|
+
|
20
|
+
We should not include these files or vcards as attachments.
|
21
|
+
|
22
|
+
---------- Forwarded message ----------
|
23
|
+
From: xxxxx xxxxxx <xxxxxxxx@xxx.com>
|
24
|
+
Date: May 8, 2005 1:17 PM
|
25
|
+
Subject: Signed email causes file attachments
|
26
|
+
To: xxxxxxx@xxxxxxxxxx.com
|
27
|
+
|
28
|
+
|
29
|
+
Hi,
|
30
|
+
|
31
|
+
Test attachments oddly encoded with japanese charset.
|
32
|
+
|
33
|
+
|
34
|
+
------=_Part_5028_7368284.1115579351471
|
35
|
+
Content-Type: application/octet-stream; name*=iso-2022-jp'ja'01%20Quien%20Te%20Dij%8aat.%20Pitbull.mp3
|
36
|
+
Content-Transfer-Encoding: base64
|
37
|
+
Content-Disposition: attachment
|
38
|
+
|
39
|
+
MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAAoIIGFDCCAs0w
|
40
|
+
ggI2oAMCAQICAw5c+TANBgkqhkiG9w0BAQQFADBiMQswCQYDVQQGEwJaQTElMCMGA1UEChMcVGhh
|
41
|
+
d3RlIENvbnN1bHRpbmcgKFB0eSkgTHRkLjEsMCoGA1UEAxMjVGhhd3RlIFBlcnNvbmFsIEZyZWVt
|
42
|
+
YWlsIElzc3VpbmcgQ0EwHhcNMDUwMzI5MDkzOTEwWhcNMDYwMzI5MDkzOTEwWjBCMR8wHQYDVQQD
|
43
|
+
ExZUaGF3dGUgRnJlZW1haWwgTWVtYmVyMR8wHQYJKoZIhvcNAQkBFhBzbWhhdW5jaEBtYWMuY29t
|
44
|
+
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAn90dPsYS3LjfMY211OSYrDQLzwNYPlAL
|
45
|
+
7+/0XA+kdy8/rRnyEHFGwhNCDmg0B6pxC7z3xxJD/8GfCd+IYUUNUQV5m9MkxfP9pTVXZVIYLaBw
|
46
|
+
------=_Part_5028_7368284.1115579351471--
|
47
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
Received: from xxx.xxx.xxx ([xxx.xxx.xxx.xxx] verified)
|
2
|
+
by xxx.com (CommuniGate Pro SMTP 4.2.8)
|
3
|
+
with SMTP id 2532598 for xxx@xxx.com; Wed, 23 Feb 2005 17:51:49 -0500
|
4
|
+
Received-SPF: softfail
|
5
|
+
receiver=xxx.com; client-ip=xxx.xxx.xxx.xxx; envelope-from=xxx@xxx.xxx
|
6
|
+
quite Delivered-To: xxx@xxx.xxx
|
7
|
+
Received: by xxx.xxx.xxx (Wostfix, from userid xxx)
|
8
|
+
id 0F87F333; Wed, 23 Feb 2005 16:16:17 -0600
|
9
|
+
Date: Wed, 23 Feb 2005 18:20:17 -0400
|
10
|
+
From: "xxx xxx" <xxx@xxx.xxx>
|
11
|
+
Message-ID: <4D6AA7EB.6490534@xxx.xxx>
|
12
|
+
To: xxx@xxx.com
|
13
|
+
Subject: Stop adware/spyware once and for all.
|
14
|
+
X-Scanned-By: MIMEDefang 2.11 (www dot roaringpenguin dot com slash mimedefang)
|
15
|
+
|
16
|
+
You are infected with:
|
17
|
+
Ad Ware and Spy Ware
|
18
|
+
|
19
|
+
Get your free scan and removal download now,
|
20
|
+
before it gets any worse.
|
21
|
+
|
22
|
+
http://xxx.xxx.info?aid=3D13&?stat=3D4327kdzt
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
no more? (you will still be infected)
|
28
|
+
http://xxx.xxx.info/discon/?xxx@xxx.com
|
@@ -0,0 +1 @@
|
|
1
|
+
yaml to: <%= @recipient %>
|
@@ -0,0 +1,97 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + "/../lib/")
|
2
|
+
$:.unshift File.dirname(__FILE__) + "/fixtures/helpers"
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require 'action_mailer'
|
6
|
+
|
7
|
+
module MailerHelper
|
8
|
+
def person_name
|
9
|
+
"Mr. Joe Person"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class HelperMailer < ActionMailer::Base
|
14
|
+
helper MailerHelper
|
15
|
+
helper :test
|
16
|
+
|
17
|
+
def use_helper(recipient)
|
18
|
+
recipients recipient
|
19
|
+
subject "using helpers"
|
20
|
+
from "tester@example.com"
|
21
|
+
end
|
22
|
+
|
23
|
+
def use_test_helper(recipient)
|
24
|
+
recipients recipient
|
25
|
+
subject "using helpers"
|
26
|
+
from "tester@example.com"
|
27
|
+
self.body = { :text => "emphasize me!" }
|
28
|
+
end
|
29
|
+
|
30
|
+
def use_mail_helper(recipient)
|
31
|
+
recipients recipient
|
32
|
+
subject "using mailing helpers"
|
33
|
+
from "tester@example.com"
|
34
|
+
self.body = { :text =>
|
35
|
+
"But soft! What light through yonder window breaks? It is the east, " +
|
36
|
+
"and Juliet is the sun. Arise, fair sun, and kill the envious moon, " +
|
37
|
+
"which is sick and pale with grief that thou, her maid, art far more " +
|
38
|
+
"fair than she. Be not her maid, for she is envious! Her vestal " +
|
39
|
+
"livery is but sick and green, and none but fools do wear it. Cast " +
|
40
|
+
"it off!"
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
def use_helper_method(recipient)
|
45
|
+
recipients recipient
|
46
|
+
subject "using helpers"
|
47
|
+
from "tester@example.com"
|
48
|
+
self.body = { :text => "emphasize me!" }
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def name_of_the_mailer_class
|
54
|
+
self.class.name
|
55
|
+
end
|
56
|
+
helper_method :name_of_the_mailer_class
|
57
|
+
end
|
58
|
+
|
59
|
+
HelperMailer.template_root = File.dirname(__FILE__) + "/fixtures"
|
60
|
+
|
61
|
+
class MailerHelperTest < Test::Unit::TestCase
|
62
|
+
def new_mail( charset="utf-8" )
|
63
|
+
mail = TMail::Mail.new
|
64
|
+
mail.set_content_type "text", "plain", { "charset" => charset } if charset
|
65
|
+
mail
|
66
|
+
end
|
67
|
+
|
68
|
+
def setup
|
69
|
+
ActionMailer::Base.delivery_method = :test
|
70
|
+
ActionMailer::Base.perform_deliveries = true
|
71
|
+
ActionMailer::Base.deliveries = []
|
72
|
+
|
73
|
+
@recipient = 'test@localhost'
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_use_helper
|
77
|
+
mail = HelperMailer.create_use_helper(@recipient)
|
78
|
+
assert_match %r{Mr. Joe Person}, mail.encoded
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_use_test_helper
|
82
|
+
mail = HelperMailer.create_use_test_helper(@recipient)
|
83
|
+
assert_match %r{<em><strong><small>emphasize me!}, mail.encoded
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_use_helper_method
|
87
|
+
mail = HelperMailer.create_use_helper_method(@recipient)
|
88
|
+
assert_match %r{HelperMailer}, mail.encoded
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_use_mail_helper
|
92
|
+
mail = HelperMailer.create_use_mail_helper(@recipient)
|
93
|
+
assert_match %r{ But soft!}, mail.encoded
|
94
|
+
assert_match %r{east, and\n Juliet}, mail.encoded
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
data/test/mail_service_test.rb
CHANGED
@@ -3,6 +3,26 @@ $:.unshift(File.dirname(__FILE__) + "/../lib/")
|
|
3
3
|
require 'test/unit'
|
4
4
|
require 'action_mailer'
|
5
5
|
|
6
|
+
class MockSMTP
|
7
|
+
def self.deliveries
|
8
|
+
@@deliveries
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@@deliveries = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def sendmail(mail, from, to)
|
16
|
+
@@deliveries << [mail, from, to]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class Net::SMTP
|
21
|
+
def self.start(*args)
|
22
|
+
yield MockSMTP.new
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
6
26
|
class TestMailer < ActionMailer::Base
|
7
27
|
|
8
28
|
def signed_up(recipient)
|
@@ -14,21 +34,21 @@ class TestMailer < ActionMailer::Base
|
|
14
34
|
end
|
15
35
|
|
16
36
|
def cancelled_account(recipient)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
37
|
+
self.recipients = recipient
|
38
|
+
self.subject = "[Cancelled] Goodbye #{recipient}"
|
39
|
+
self.from = "system@loudthinking.com"
|
40
|
+
self.sent_on = Time.local(2004, 12, 12)
|
41
|
+
self.body = "Goodbye, Mr. #{recipient}"
|
22
42
|
end
|
23
43
|
|
24
44
|
def cc_bcc(recipient)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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."
|
32
52
|
end
|
33
53
|
|
34
54
|
def iso_charset(recipient)
|
@@ -73,14 +93,114 @@ class TestMailer < ActionMailer::Base
|
|
73
93
|
@body = "åœö blah"
|
74
94
|
@charset = "utf-8"
|
75
95
|
end
|
96
|
+
|
97
|
+
def explicitly_multipart_example(recipient, ct=nil)
|
98
|
+
recipients recipient
|
99
|
+
subject "multipart example"
|
100
|
+
from "test@example.com"
|
101
|
+
sent_on Time.local(2004, 12, 12)
|
102
|
+
body "plain text default"
|
103
|
+
content_type ct if ct
|
104
|
+
|
105
|
+
part "text/html" do |p|
|
106
|
+
p.charset = "iso-8859-1"
|
107
|
+
p.body = "blah"
|
108
|
+
end
|
109
|
+
|
110
|
+
attachment :content_type => "image/jpeg", :filename => "foo.jpg",
|
111
|
+
:body => "123456789"
|
112
|
+
end
|
113
|
+
|
114
|
+
def implicitly_multipart_example(recipient, order = nil)
|
115
|
+
@recipients = recipient
|
116
|
+
@subject = "multipart example"
|
117
|
+
@from = "test@example.com"
|
118
|
+
@sent_on = Time.local 2004, 12, 12
|
119
|
+
@body = { "recipient" => recipient }
|
120
|
+
@implicit_parts_order = order unless order.nil?
|
121
|
+
end
|
122
|
+
|
123
|
+
def html_mail(recipient)
|
124
|
+
recipients recipient
|
125
|
+
subject "html mail"
|
126
|
+
from "test@example.com"
|
127
|
+
body "<em>Emphasize</em> <strong>this</strong>"
|
128
|
+
content_type "text/html"
|
129
|
+
end
|
130
|
+
|
131
|
+
def custom_template(recipient)
|
132
|
+
recipients recipient
|
133
|
+
subject "[Signed up] Welcome #{recipient}"
|
134
|
+
from "system@loudthinking.com"
|
135
|
+
sent_on Time.local(2004, 12, 12)
|
136
|
+
template "signed_up"
|
137
|
+
|
138
|
+
body["recipient"] = recipient
|
139
|
+
end
|
140
|
+
|
141
|
+
def various_newlines(recipient)
|
142
|
+
recipients recipient
|
143
|
+
subject "various newlines"
|
144
|
+
from "test@example.com"
|
145
|
+
body "line #1\nline #2\rline #3\r\nline #4\r\r" +
|
146
|
+
"line #5\n\nline#6\r\n\r\nline #7"
|
147
|
+
end
|
148
|
+
|
149
|
+
def various_newlines_multipart(recipient)
|
150
|
+
recipients recipient
|
151
|
+
subject "various newlines multipart"
|
152
|
+
from "test@example.com"
|
153
|
+
content_type "multipart/alternative"
|
154
|
+
part :content_type => "text/plain", :body => "line #1\nline #2\rline #3\r\nline #4\r\r"
|
155
|
+
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"
|
156
|
+
end
|
157
|
+
|
158
|
+
def nested_multipart(recipient)
|
159
|
+
recipients recipient
|
160
|
+
subject "nested multipart"
|
161
|
+
from "test@example.com"
|
162
|
+
content_type "multipart/mixed"
|
163
|
+
part :content_type => "multipart/alternative", :content_disposition => "inline" do |p|
|
164
|
+
p.part :content_type => "text/plain", :body => "test text\nline #2"
|
165
|
+
p.part :content_type => "text/html", :body => "<b>test</b> HTML<br/>\nline #2"
|
166
|
+
end
|
167
|
+
attachment :content_type => "application/octet-stream",:filename => "test.txt", :body => "test abcdefghijklmnopqstuvwxyz"
|
168
|
+
end
|
169
|
+
|
170
|
+
def unnamed_attachment(recipient)
|
171
|
+
recipients recipient
|
172
|
+
subject "nested multipart"
|
173
|
+
from "test@example.com"
|
174
|
+
content_type "multipart/mixed"
|
175
|
+
part :content_type => "text/plain", :body => "hullo"
|
176
|
+
attachment :content_type => "application/octet-stream", :body => "test abcdefghijklmnopqstuvwxyz"
|
177
|
+
end
|
178
|
+
|
179
|
+
def headers_with_nonalpha_chars(recipient)
|
180
|
+
recipients recipient
|
181
|
+
subject "nonalpha chars"
|
182
|
+
from "One: Two <test@example.com>"
|
183
|
+
cc "Three: Four <test@example.com>"
|
184
|
+
bcc "Five: Six <test@example.com>"
|
185
|
+
body "testing"
|
186
|
+
end
|
187
|
+
|
188
|
+
class <<self
|
189
|
+
attr_accessor :received_body
|
190
|
+
end
|
191
|
+
|
192
|
+
def receive(mail)
|
193
|
+
self.class.received_body = mail.body
|
194
|
+
end
|
76
195
|
end
|
77
196
|
|
78
197
|
TestMailer.template_root = File.dirname(__FILE__) + "/fixtures"
|
79
198
|
|
80
199
|
class ActionMailerTest < Test::Unit::TestCase
|
200
|
+
include ActionMailer::Quoting
|
81
201
|
|
82
202
|
def encode( text, charset="utf-8" )
|
83
|
-
|
203
|
+
quoted_printable( text, charset )
|
84
204
|
end
|
85
205
|
|
86
206
|
def new_mail( charset="utf-8" )
|
@@ -99,6 +219,19 @@ class ActionMailerTest < Test::Unit::TestCase
|
|
99
219
|
@recipient = 'test@localhost'
|
100
220
|
end
|
101
221
|
|
222
|
+
def test_nested_parts
|
223
|
+
created = nil
|
224
|
+
assert_nothing_raised { created = TestMailer.create_nested_multipart(@recipient)}
|
225
|
+
assert_equal 2,created.parts.size
|
226
|
+
assert_equal 2,created.parts.first.parts.size
|
227
|
+
|
228
|
+
assert_equal "multipart/mixed", created.content_type
|
229
|
+
assert_equal "multipart/alternative", created.parts.first.content_type
|
230
|
+
assert_equal "text/plain", created.parts.first.parts.first.content_type
|
231
|
+
assert_equal "text/html", created.parts.first.parts[1].content_type
|
232
|
+
assert_equal "application/octet-stream", created.parts[1].content_type
|
233
|
+
end
|
234
|
+
|
102
235
|
def test_signed_up
|
103
236
|
expected = new_mail
|
104
237
|
expected.to = @recipient
|
@@ -117,6 +250,20 @@ class ActionMailerTest < Test::Unit::TestCase
|
|
117
250
|
assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
|
118
251
|
end
|
119
252
|
|
253
|
+
def test_custom_template
|
254
|
+
expected = new_mail
|
255
|
+
expected.to = @recipient
|
256
|
+
expected.subject = "[Signed up] Welcome #{@recipient}"
|
257
|
+
expected.body = "Hello there, \n\nMr. #{@recipient}"
|
258
|
+
expected.from = "system@loudthinking.com"
|
259
|
+
expected.date = Time.local(2004, 12, 12)
|
260
|
+
|
261
|
+
created = nil
|
262
|
+
assert_nothing_raised { created = TestMailer.create_custom_template(@recipient) }
|
263
|
+
assert_not_nil created
|
264
|
+
assert_equal expected.encoded, created.encoded
|
265
|
+
end
|
266
|
+
|
120
267
|
def test_cancelled_account
|
121
268
|
expected = new_mail
|
122
269
|
expected.to = @recipient
|
@@ -232,32 +379,84 @@ class ActionMailerTest < Test::Unit::TestCase
|
|
232
379
|
assert_equal 1, ActionMailer::Base.deliveries.size
|
233
380
|
end
|
234
381
|
|
235
|
-
def
|
382
|
+
def test_unquote_quoted_printable_subject
|
236
383
|
msg = <<EOF
|
237
384
|
From: me@example.com
|
238
385
|
Subject: =?utf-8?Q?testing_testing_=D6=A4?=
|
239
386
|
Content-Type: text/plain; charset=iso-8859-1
|
240
387
|
|
241
|
-
|
242
|
-
2 + 2 =3D 4
|
388
|
+
The body
|
243
389
|
EOF
|
244
390
|
mail = TMail::Mail.parse(msg)
|
245
391
|
assert_equal "testing testing \326\244", mail.subject
|
246
392
|
assert_equal "=?utf-8?Q?testing_testing_=D6=A4?=", mail.quoted_subject
|
247
|
-
|
248
|
-
|
393
|
+
end
|
394
|
+
|
395
|
+
def test_unquote_7bit_subject
|
396
|
+
msg = <<EOF
|
397
|
+
From: me@example.com
|
398
|
+
Subject: this == working?
|
399
|
+
Content-Type: text/plain; charset=iso-8859-1
|
400
|
+
|
401
|
+
The body
|
402
|
+
EOF
|
403
|
+
mail = TMail::Mail.parse(msg)
|
404
|
+
assert_equal "this == working?", mail.subject
|
405
|
+
assert_equal "this == working?", mail.quoted_subject
|
406
|
+
end
|
407
|
+
|
408
|
+
def test_unquote_7bit_body
|
409
|
+
msg = <<EOF
|
410
|
+
From: me@example.com
|
411
|
+
Subject: subject
|
412
|
+
Content-Type: text/plain; charset=iso-8859-1
|
413
|
+
Content-Transfer-Encoding: 7bit
|
414
|
+
|
415
|
+
The=3Dbody
|
416
|
+
EOF
|
417
|
+
mail = TMail::Mail.parse(msg)
|
418
|
+
assert_equal "The=3Dbody", mail.body.strip
|
419
|
+
assert_equal "The=3Dbody", mail.quoted_body.strip
|
420
|
+
end
|
421
|
+
|
422
|
+
def test_unquote_quoted_printable_body
|
423
|
+
msg = <<EOF
|
424
|
+
From: me@example.com
|
425
|
+
Subject: subject
|
426
|
+
Content-Type: text/plain; charset=iso-8859-1
|
427
|
+
Content-Transfer-Encoding: quoted-printable
|
428
|
+
|
429
|
+
The=3Dbody
|
430
|
+
EOF
|
431
|
+
mail = TMail::Mail.parse(msg)
|
432
|
+
assert_equal "The=body", mail.body.strip
|
433
|
+
assert_equal "The=3Dbody", mail.quoted_body.strip
|
434
|
+
end
|
435
|
+
|
436
|
+
def test_unquote_base64_body
|
437
|
+
msg = <<EOF
|
438
|
+
From: me@example.com
|
439
|
+
Subject: subject
|
440
|
+
Content-Type: text/plain; charset=iso-8859-1
|
441
|
+
Content-Transfer-Encoding: base64
|
442
|
+
|
443
|
+
VGhlIGJvZHk=
|
444
|
+
EOF
|
445
|
+
mail = TMail::Mail.parse(msg)
|
446
|
+
assert_equal "The body", mail.body.strip
|
447
|
+
assert_equal "VGhlIGJvZHk=", mail.quoted_body.strip
|
249
448
|
end
|
250
449
|
|
251
450
|
def test_extended_headers
|
252
451
|
@recipient = "Grytøyr <test@localhost>"
|
253
452
|
|
254
453
|
expected = new_mail "iso-8859-1"
|
255
|
-
expected.to =
|
454
|
+
expected.to = quote_address_if_necessary @recipient, "iso-8859-1"
|
256
455
|
expected.subject = "testing extended headers"
|
257
456
|
expected.body = "Nothing to see here."
|
258
|
-
expected.from =
|
259
|
-
expected.cc =
|
260
|
-
expected.bcc =
|
457
|
+
expected.from = quote_address_if_necessary "Grytøyr <stian1@example.net>", "iso-8859-1"
|
458
|
+
expected.cc = quote_address_if_necessary "Grytøyr <stian2@example.net>", "iso-8859-1"
|
459
|
+
expected.bcc = quote_address_if_necessary "Grytøyr <stian3@example.net>", "iso-8859-1"
|
261
460
|
expected.date = Time.local 2004, 12, 12
|
262
461
|
|
263
462
|
created = nil
|
@@ -279,12 +478,12 @@ EOF
|
|
279
478
|
def test_utf8_body_is_not_quoted
|
280
479
|
@recipient = "Foo áëô îü <extended@example.net>"
|
281
480
|
expected = new_mail "utf-8"
|
282
|
-
expected.to =
|
481
|
+
expected.to = quote_address_if_necessary @recipient, "utf-8"
|
283
482
|
expected.subject = "testing utf-8 body"
|
284
483
|
expected.body = "åœö blah"
|
285
|
-
expected.from =
|
286
|
-
expected.cc =
|
287
|
-
expected.bcc =
|
484
|
+
expected.from = quote_address_if_necessary @recipient, "utf-8"
|
485
|
+
expected.cc = quote_address_if_necessary @recipient, "utf-8"
|
486
|
+
expected.bcc = quote_address_if_necessary @recipient, "utf-8"
|
288
487
|
expected.date = Time.local 2004, 12, 12
|
289
488
|
|
290
489
|
created = TestMailer.create_utf8_body @recipient
|
@@ -294,12 +493,12 @@ EOF
|
|
294
493
|
def test_multiple_utf8_recipients
|
295
494
|
@recipient = ["\"Foo áëô îü\" <extended@example.net>", "\"Example Recipient\" <me@example.com>"]
|
296
495
|
expected = new_mail "utf-8"
|
297
|
-
expected.to =
|
496
|
+
expected.to = quote_address_if_necessary @recipient, "utf-8"
|
298
497
|
expected.subject = "testing utf-8 body"
|
299
498
|
expected.body = "åœö blah"
|
300
|
-
expected.from =
|
301
|
-
expected.cc =
|
302
|
-
expected.bcc =
|
499
|
+
expected.from = quote_address_if_necessary @recipient.first, "utf-8"
|
500
|
+
expected.cc = quote_address_if_necessary @recipient, "utf-8"
|
501
|
+
expected.bcc = quote_address_if_necessary @recipient, "utf-8"
|
303
502
|
expected.date = Time.local 2004, 12, 12
|
304
503
|
|
305
504
|
created = TestMailer.create_utf8_body @recipient
|
@@ -307,5 +506,167 @@ EOF
|
|
307
506
|
assert_match(/\nTo: =\?utf-8\?Q\?Foo_.*?\?= <extended@example.net>, Example Recipient <me/, created.encoded)
|
308
507
|
end
|
309
508
|
|
509
|
+
def test_receive_decodes_base64_encoded_mail
|
510
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email")
|
511
|
+
TestMailer.receive(fixture)
|
512
|
+
assert_match(/Jamis/, TestMailer.received_body)
|
513
|
+
end
|
514
|
+
|
515
|
+
def test_receive_attachments
|
516
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email2")
|
517
|
+
mail = TMail::Mail.parse(fixture)
|
518
|
+
attachment = mail.attachments.last
|
519
|
+
assert_equal "smime.p7s", attachment.original_filename
|
520
|
+
assert_equal "application/pkcs7-signature", attachment.content_type
|
521
|
+
end
|
522
|
+
|
523
|
+
def test_decode_attachment_without_charset
|
524
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email3")
|
525
|
+
mail = TMail::Mail.parse(fixture)
|
526
|
+
attachment = mail.attachments.last
|
527
|
+
assert_equal 1026, attachment.read.length
|
528
|
+
end
|
529
|
+
|
530
|
+
def test_decode_part_without_content_type
|
531
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email4")
|
532
|
+
mail = TMail::Mail.parse(fixture)
|
533
|
+
assert_nothing_raised { mail.body }
|
534
|
+
end
|
535
|
+
|
536
|
+
def test_decode_message_without_content_type
|
537
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email5")
|
538
|
+
mail = TMail::Mail.parse(fixture)
|
539
|
+
assert_nothing_raised { mail.body }
|
540
|
+
end
|
541
|
+
|
542
|
+
def test_decode_message_with_incorrect_charset
|
543
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email6")
|
544
|
+
mail = TMail::Mail.parse(fixture)
|
545
|
+
assert_nothing_raised { mail.body }
|
546
|
+
end
|
547
|
+
|
548
|
+
def test_explicitly_multipart_messages
|
549
|
+
mail = TestMailer.create_explicitly_multipart_example(@recipient)
|
550
|
+
assert_equal 3, mail.parts.length
|
551
|
+
assert_nil mail.content_type
|
552
|
+
assert_equal "text/plain", mail.parts[0].content_type
|
553
|
+
|
554
|
+
assert_equal "text/html", mail.parts[1].content_type
|
555
|
+
assert_equal "iso-8859-1", mail.parts[1].sub_header("content-type", "charset")
|
556
|
+
assert_equal "inline", mail.parts[1].content_disposition
|
557
|
+
|
558
|
+
assert_equal "image/jpeg", mail.parts[2].content_type
|
559
|
+
assert_equal "attachment", mail.parts[2].content_disposition
|
560
|
+
assert_equal "foo.jpg", mail.parts[2].sub_header("content-disposition", "filename")
|
561
|
+
assert_equal "foo.jpg", mail.parts[2].sub_header("content-type", "name")
|
562
|
+
assert_nil mail.parts[2].sub_header("content-type", "charset")
|
563
|
+
end
|
564
|
+
|
565
|
+
def test_explicitly_multipart_with_content_type
|
566
|
+
mail = TestMailer.create_explicitly_multipart_example(@recipient,
|
567
|
+
"multipart/alternative")
|
568
|
+
assert_equal 3, mail.parts.length
|
569
|
+
assert_equal "multipart/alternative", mail.content_type
|
570
|
+
end
|
571
|
+
|
572
|
+
def test_explicitly_multipart_with_invalid_content_type
|
573
|
+
mail = TestMailer.create_explicitly_multipart_example(@recipient, "text/xml")
|
574
|
+
assert_equal 3, mail.parts.length
|
575
|
+
assert_nil mail.content_type
|
576
|
+
end
|
577
|
+
|
578
|
+
def test_implicitly_multipart_messages
|
579
|
+
mail = TestMailer.create_implicitly_multipart_example(@recipient)
|
580
|
+
assert_equal 3, mail.parts.length
|
581
|
+
assert_equal "multipart/alternative", mail.content_type
|
582
|
+
assert_equal "text/yaml", mail.parts[0].content_type
|
583
|
+
assert_equal "utf-8", mail.parts[0].sub_header("content-type", "charset")
|
584
|
+
assert_equal "text/plain", mail.parts[1].content_type
|
585
|
+
assert_equal "utf-8", mail.parts[1].sub_header("content-type", "charset")
|
586
|
+
assert_equal "text/html", mail.parts[2].content_type
|
587
|
+
assert_equal "utf-8", mail.parts[2].sub_header("content-type", "charset")
|
588
|
+
end
|
589
|
+
|
590
|
+
def test_implicitly_multipart_messages_with_custom_order
|
591
|
+
mail = TestMailer.create_implicitly_multipart_example(@recipient, ["text/yaml", "text/plain"])
|
592
|
+
assert_equal 3, mail.parts.length
|
593
|
+
assert_equal "text/html", mail.parts[0].content_type
|
594
|
+
assert_equal "text/plain", mail.parts[1].content_type
|
595
|
+
assert_equal "text/yaml", mail.parts[2].content_type
|
596
|
+
end
|
597
|
+
|
598
|
+
def test_html_mail
|
599
|
+
mail = TestMailer.create_html_mail(@recipient)
|
600
|
+
assert_equal "text/html", mail.content_type
|
601
|
+
end
|
602
|
+
|
603
|
+
def test_various_newlines
|
604
|
+
mail = TestMailer.create_various_newlines(@recipient)
|
605
|
+
assert_equal("line #1\nline #2\nline #3\nline #4\n\n" +
|
606
|
+
"line #5\n\nline#6\n\nline #7", mail.body)
|
607
|
+
end
|
608
|
+
|
609
|
+
def test_various_newlines_multipart
|
610
|
+
mail = TestMailer.create_various_newlines_multipart(@recipient)
|
611
|
+
assert_equal "line #1\nline #2\nline #3\nline #4\n\n", mail.parts[0].body
|
612
|
+
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
|
613
|
+
end
|
614
|
+
|
615
|
+
def test_headers_removed_on_smtp_delivery
|
616
|
+
ActionMailer::Base.delivery_method = :smtp
|
617
|
+
TestMailer.deliver_cc_bcc(@recipient)
|
618
|
+
assert MockSMTP.deliveries[0][2].include?("root@loudthinking.com")
|
619
|
+
assert MockSMTP.deliveries[0][2].include?("nobody@loudthinking.com")
|
620
|
+
assert MockSMTP.deliveries[0][2].include?(@recipient)
|
621
|
+
assert_match %r{^Cc: nobody@loudthinking.com}, MockSMTP.deliveries[0][0]
|
622
|
+
assert_match %r{^To: #{@recipient}}, MockSMTP.deliveries[0][0]
|
623
|
+
assert_no_match %r{^Bcc: root@loudthinking.com}, MockSMTP.deliveries[0][0]
|
624
|
+
end
|
625
|
+
|
626
|
+
def test_recursive_multipart_processing
|
627
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email7")
|
628
|
+
mail = TMail::Mail.parse(fixture)
|
629
|
+
assert_equal "This is the first part.\n\nAttachment: test.pdf\n\n\nAttachment: smime.p7s\n", mail.body
|
630
|
+
end
|
631
|
+
|
632
|
+
def test_decode_encoded_attachment_filename
|
633
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email8")
|
634
|
+
mail = TMail::Mail.parse(fixture)
|
635
|
+
attachment = mail.attachments.last
|
636
|
+
assert_equal "01QuienTeDijat.Pitbull.mp3", attachment.original_filename
|
637
|
+
end
|
638
|
+
|
639
|
+
def test_wrong_mail_header
|
640
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email9")
|
641
|
+
assert_raise(TMail::SyntaxError) { TMail::Mail.parse(fixture) }
|
642
|
+
end
|
643
|
+
|
644
|
+
def test_decode_message_with_unknown_charset
|
645
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email10")
|
646
|
+
mail = TMail::Mail.parse(fixture)
|
647
|
+
assert_nothing_raised { mail.body }
|
648
|
+
end
|
649
|
+
|
650
|
+
def test_decode_message_with_unquoted_atchar_in_header
|
651
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email11")
|
652
|
+
mail = TMail::Mail.parse(fixture)
|
653
|
+
assert_not_nil mail.from
|
654
|
+
end
|
655
|
+
|
656
|
+
def test_empty_header_values_omitted
|
657
|
+
result = TestMailer.create_unnamed_attachment(@recipient).encoded
|
658
|
+
assert_match %r{Content-Type: application/octet-stream[^;]}, result
|
659
|
+
assert_match %r{Content-Disposition: attachment[^;]}, result
|
660
|
+
end
|
661
|
+
|
662
|
+
def test_headers_with_nonalpha_chars
|
663
|
+
mail = TestMailer.create_headers_with_nonalpha_chars(@recipient)
|
664
|
+
assert !mail.from_addrs.empty?
|
665
|
+
assert !mail.cc_addrs.empty?
|
666
|
+
assert !mail.bcc_addrs.empty?
|
667
|
+
assert_match(/:/, mail.from_addrs.to_s)
|
668
|
+
assert_match(/:/, mail.cc_addrs.to_s)
|
669
|
+
assert_match(/:/, mail.bcc_addrs.to_s)
|
670
|
+
end
|
310
671
|
end
|
311
672
|
|