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,337 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 1998-2003 Minero Aoki <aamine@loveruby.net>
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#
|
23
|
+
# Note: Originally licensed under LGPL v2+. Using MIT license for Rails
|
24
|
+
# with permission of Minero Aoki.
|
25
|
+
#++
|
26
|
+
|
27
|
+
# = TMail - The EMail Swiss Army Knife for Ruby
|
28
|
+
#
|
29
|
+
# The TMail library provides you with a very complete way to handle and manipulate EMails
|
30
|
+
# from within your Ruby programs.
|
31
|
+
#
|
32
|
+
# Used as the backbone for email handling by the Ruby on Rails and Nitro web frameworks as
|
33
|
+
# well as a bunch of other Ruby apps including the Ruby-Talk mailing list to newsgroup email
|
34
|
+
# gateway, it is a proven and reliable email handler that won't let you down.
|
35
|
+
#
|
36
|
+
# Originally created by Minero Aoki, TMail has been recently picked up by Mikel Lindsaar and
|
37
|
+
# is being actively maintained. Numerous backlogged bug fixes have been applied as well as
|
38
|
+
# Ruby 1.9 compatibility and a swath of documentation to boot.
|
39
|
+
#
|
40
|
+
# TMail allows you to treat an email totally as an object and allow you to get on with your
|
41
|
+
# own programming without having to worry about crafting the perfect email address validation
|
42
|
+
# parser, or assembling an email from all it's component parts.
|
43
|
+
#
|
44
|
+
# TMail handles the most complex part of the email - the header. It generates and parses
|
45
|
+
# headers and provides you with instant access to their innards through simple and logically
|
46
|
+
# named accessor and setter methods.
|
47
|
+
#
|
48
|
+
# TMail also provides a wrapper to Net/SMTP as well as Unix Mailbox handling methods to
|
49
|
+
# directly read emails from your unix mailbox, parse them and use them.
|
50
|
+
#
|
51
|
+
# Following is the comprehensive list of methods to access TMail::Mail objects. You can also
|
52
|
+
# check out TMail::Mail, TMail::Address and TMail::Headers for other lists.
|
53
|
+
module TMail
|
54
|
+
|
55
|
+
# Provides an exception to throw on errors in Syntax within TMail's parsers
|
56
|
+
class SyntaxError < StandardError; end
|
57
|
+
|
58
|
+
# Provides a new email boundary to separate parts of the email. This is a random
|
59
|
+
# string based off the current time, so should be fairly unique.
|
60
|
+
#
|
61
|
+
# For Example:
|
62
|
+
#
|
63
|
+
# TMail.new_boundary
|
64
|
+
# #=> "mimepart_47bf656968207_25a8fbb80114"
|
65
|
+
# TMail.new_boundary
|
66
|
+
# #=> "mimepart_47bf66051de4_25a8fbb80240"
|
67
|
+
def TMail.new_boundary
|
68
|
+
'mimepart_' + random_tag
|
69
|
+
end
|
70
|
+
|
71
|
+
# Provides a new email message ID. You can use this to generate unique email message
|
72
|
+
# id's for your email so you can track them.
|
73
|
+
#
|
74
|
+
# Optionally takes a fully qualified domain name (default to the current hostname
|
75
|
+
# returned by Socket.gethostname) that will be appended to the message ID.
|
76
|
+
#
|
77
|
+
# For Example:
|
78
|
+
#
|
79
|
+
# email.message_id = TMail.new_message_id
|
80
|
+
# #=> "<47bf66845380e_25a8fbb80332@baci.local.tmail>"
|
81
|
+
# email.to_s
|
82
|
+
# #=> "Message-Id: <47bf668b633f1_25a8fbb80475@baci.local.tmail>\n\n"
|
83
|
+
# email.message_id = TMail.new_message_id("lindsaar.net")
|
84
|
+
# #=> "<47bf668b633f1_25a8fbb80475@lindsaar.net.tmail>"
|
85
|
+
# email.to_s
|
86
|
+
# #=> "Message-Id: <47bf668b633f1_25a8fbb80475@lindsaar.net.tmail>\n\n"
|
87
|
+
def TMail.new_message_id( fqdn = nil )
|
88
|
+
fqdn ||= ::Socket.gethostname
|
89
|
+
"<#{random_tag()}@#{fqdn}.tmail>"
|
90
|
+
end
|
91
|
+
|
92
|
+
#:stopdoc:
|
93
|
+
def TMail.random_tag #:nodoc:
|
94
|
+
@uniq += 1
|
95
|
+
t = Time.now
|
96
|
+
sprintf('%x%x_%x%x%d%x',
|
97
|
+
t.to_i, t.tv_usec,
|
98
|
+
$$, Thread.current.object_id, @uniq, rand(255))
|
99
|
+
end
|
100
|
+
private_class_method :random_tag
|
101
|
+
|
102
|
+
@uniq = 0
|
103
|
+
|
104
|
+
#:startdoc:
|
105
|
+
|
106
|
+
# Text Utils provides a namespace to define TOKENs, ATOMs, PHRASEs and CONTROL characters that
|
107
|
+
# are OK per RFC 2822.
|
108
|
+
#
|
109
|
+
# It also provides methods you can call to determine if a string is safe
|
110
|
+
module TextUtils
|
111
|
+
|
112
|
+
aspecial = %Q|()<>[]:;.\\,"|
|
113
|
+
tspecial = %Q|()<>[];:\\,"/?=|
|
114
|
+
lwsp = %Q| \t\r\n|
|
115
|
+
control = %Q|\x00-\x1f\x7f-\xff|
|
116
|
+
|
117
|
+
CONTROL_CHAR = /[#{control}]/n
|
118
|
+
ATOM_UNSAFE = /[#{Regexp.quote aspecial}#{control}#{lwsp}]/n
|
119
|
+
PHRASE_UNSAFE = /[#{Regexp.quote aspecial}#{control}]/n
|
120
|
+
TOKEN_UNSAFE = /[#{Regexp.quote tspecial}#{control}#{lwsp}]/n
|
121
|
+
|
122
|
+
# Returns true if the string supplied is free from characters not allowed as an ATOM
|
123
|
+
def atom_safe?( str )
|
124
|
+
not ATOM_UNSAFE === str
|
125
|
+
end
|
126
|
+
|
127
|
+
# If the string supplied has ATOM unsafe characters in it, will return the string quoted
|
128
|
+
# in double quotes, otherwise returns the string unmodified
|
129
|
+
def quote_atom( str )
|
130
|
+
(ATOM_UNSAFE === str) ? dquote(str) : str
|
131
|
+
end
|
132
|
+
|
133
|
+
# If the string supplied has PHRASE unsafe characters in it, will return the string quoted
|
134
|
+
# in double quotes, otherwise returns the string unmodified
|
135
|
+
def quote_phrase( str )
|
136
|
+
(PHRASE_UNSAFE === str) ? dquote(str) : str
|
137
|
+
end
|
138
|
+
|
139
|
+
# Returns true if the string supplied is free from characters not allowed as a TOKEN
|
140
|
+
def token_safe?( str )
|
141
|
+
not TOKEN_UNSAFE === str
|
142
|
+
end
|
143
|
+
|
144
|
+
# If the string supplied has TOKEN unsafe characters in it, will return the string quoted
|
145
|
+
# in double quotes, otherwise returns the string unmodified
|
146
|
+
def quote_token( str )
|
147
|
+
(TOKEN_UNSAFE === str) ? dquote(str) : str
|
148
|
+
end
|
149
|
+
|
150
|
+
# Wraps supplied string in double quotes unless it is already wrapped
|
151
|
+
# Returns double quoted string
|
152
|
+
def dquote( str ) #:nodoc:
|
153
|
+
unless str =~ /^".*?"$/
|
154
|
+
'"' + str.gsub(/["\\]/n) {|s| '\\' + s } + '"'
|
155
|
+
else
|
156
|
+
str
|
157
|
+
end
|
158
|
+
end
|
159
|
+
private :dquote
|
160
|
+
|
161
|
+
# Unwraps supplied string from inside double quotes
|
162
|
+
# Returns unquoted string
|
163
|
+
def unquote( str )
|
164
|
+
str =~ /^"(.*?)"$/ ? $1 : str
|
165
|
+
end
|
166
|
+
|
167
|
+
# Provides a method to join a domain name by it's parts and also makes it
|
168
|
+
# ATOM safe by quoting it as needed
|
169
|
+
def join_domain( arr )
|
170
|
+
arr.map {|i|
|
171
|
+
if /\A\[.*\]\z/ === i
|
172
|
+
i
|
173
|
+
else
|
174
|
+
quote_atom(i)
|
175
|
+
end
|
176
|
+
}.join('.')
|
177
|
+
end
|
178
|
+
|
179
|
+
#:stopdoc:
|
180
|
+
ZONESTR_TABLE = {
|
181
|
+
'jst' => 9 * 60,
|
182
|
+
'eet' => 2 * 60,
|
183
|
+
'bst' => 1 * 60,
|
184
|
+
'met' => 1 * 60,
|
185
|
+
'gmt' => 0,
|
186
|
+
'utc' => 0,
|
187
|
+
'ut' => 0,
|
188
|
+
'nst' => -(3 * 60 + 30),
|
189
|
+
'ast' => -4 * 60,
|
190
|
+
'edt' => -4 * 60,
|
191
|
+
'est' => -5 * 60,
|
192
|
+
'cdt' => -5 * 60,
|
193
|
+
'cst' => -6 * 60,
|
194
|
+
'mdt' => -6 * 60,
|
195
|
+
'mst' => -7 * 60,
|
196
|
+
'pdt' => -7 * 60,
|
197
|
+
'pst' => -8 * 60,
|
198
|
+
'a' => -1 * 60,
|
199
|
+
'b' => -2 * 60,
|
200
|
+
'c' => -3 * 60,
|
201
|
+
'd' => -4 * 60,
|
202
|
+
'e' => -5 * 60,
|
203
|
+
'f' => -6 * 60,
|
204
|
+
'g' => -7 * 60,
|
205
|
+
'h' => -8 * 60,
|
206
|
+
'i' => -9 * 60,
|
207
|
+
# j not use
|
208
|
+
'k' => -10 * 60,
|
209
|
+
'l' => -11 * 60,
|
210
|
+
'm' => -12 * 60,
|
211
|
+
'n' => 1 * 60,
|
212
|
+
'o' => 2 * 60,
|
213
|
+
'p' => 3 * 60,
|
214
|
+
'q' => 4 * 60,
|
215
|
+
'r' => 5 * 60,
|
216
|
+
's' => 6 * 60,
|
217
|
+
't' => 7 * 60,
|
218
|
+
'u' => 8 * 60,
|
219
|
+
'v' => 9 * 60,
|
220
|
+
'w' => 10 * 60,
|
221
|
+
'x' => 11 * 60,
|
222
|
+
'y' => 12 * 60,
|
223
|
+
'z' => 0 * 60
|
224
|
+
}
|
225
|
+
#:startdoc:
|
226
|
+
|
227
|
+
# Takes a time zone string from an EMail and converts it to Unix Time (seconds)
|
228
|
+
def timezone_string_to_unixtime( str )
|
229
|
+
if m = /([\+\-])(\d\d?)(\d\d)/.match(str)
|
230
|
+
sec = (m[2].to_i * 60 + m[3].to_i) * 60
|
231
|
+
m[1] == '-' ? -sec : sec
|
232
|
+
else
|
233
|
+
min = ZONESTR_TABLE[str.downcase] or
|
234
|
+
raise SyntaxError, "wrong timezone format '#{str}'"
|
235
|
+
min * 60
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
#:stopdoc:
|
240
|
+
WDAY = %w( Sun Mon Tue Wed Thu Fri Sat TMailBUG )
|
241
|
+
MONTH = %w( TMailBUG Jan Feb Mar Apr May Jun
|
242
|
+
Jul Aug Sep Oct Nov Dec TMailBUG )
|
243
|
+
|
244
|
+
def time2str( tm )
|
245
|
+
# [ruby-list:7928]
|
246
|
+
gmt = Time.at(tm.to_i)
|
247
|
+
gmt.gmtime
|
248
|
+
offset = tm.to_i - Time.local(*gmt.to_a[0,6].reverse).to_i
|
249
|
+
|
250
|
+
# DO NOT USE strftime: setlocale() breaks it
|
251
|
+
sprintf '%s, %s %s %d %02d:%02d:%02d %+.2d%.2d',
|
252
|
+
WDAY[tm.wday], tm.mday, MONTH[tm.month],
|
253
|
+
tm.year, tm.hour, tm.min, tm.sec,
|
254
|
+
*(offset / 60).divmod(60)
|
255
|
+
end
|
256
|
+
|
257
|
+
|
258
|
+
MESSAGE_ID = /<[^\@>]+\@[^>\@]+>/
|
259
|
+
|
260
|
+
def message_id?( str )
|
261
|
+
MESSAGE_ID === str
|
262
|
+
end
|
263
|
+
|
264
|
+
|
265
|
+
MIME_ENCODED = /=\?[^\s?=]+\?[QB]\?[^\s?=]+\?=/i
|
266
|
+
|
267
|
+
def mime_encoded?( str )
|
268
|
+
MIME_ENCODED === str
|
269
|
+
end
|
270
|
+
|
271
|
+
|
272
|
+
def decode_params( hash )
|
273
|
+
new = Hash.new
|
274
|
+
encoded = nil
|
275
|
+
hash.each do |key, value|
|
276
|
+
if m = /\*(?:(\d+)\*)?\z/.match(key)
|
277
|
+
((encoded ||= {})[m.pre_match] ||= [])[(m[1] || 0).to_i] = value
|
278
|
+
else
|
279
|
+
new[key] = to_kcode(value)
|
280
|
+
end
|
281
|
+
end
|
282
|
+
if encoded
|
283
|
+
encoded.each do |key, strings|
|
284
|
+
new[key] = decode_RFC2231(strings.join(''))
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
new
|
289
|
+
end
|
290
|
+
|
291
|
+
NKF_FLAGS = {
|
292
|
+
'EUC' => '-e -m',
|
293
|
+
'SJIS' => '-s -m'
|
294
|
+
}
|
295
|
+
|
296
|
+
def to_kcode( str )
|
297
|
+
flag = NKF_FLAGS[TMail.KCODE] or return str
|
298
|
+
NKF.nkf(flag, str)
|
299
|
+
end
|
300
|
+
|
301
|
+
RFC2231_ENCODED = /\A(?:iso-2022-jp|euc-jp|shift_jis|us-ascii)?'[a-z]*'/in
|
302
|
+
|
303
|
+
def decode_RFC2231( str )
|
304
|
+
m = RFC2231_ENCODED.match(str) or return str
|
305
|
+
begin
|
306
|
+
to_kcode(m.post_match.gsub(/%[\da-f]{2}/in) {|s| s[1,2].hex.chr })
|
307
|
+
rescue
|
308
|
+
m.post_match.gsub(/%[\da-f]{2}/in, "")
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
def quote_boundary
|
313
|
+
# Make sure the Content-Type boundary= parameter is quoted if it contains illegal characters
|
314
|
+
# (to ensure any special characters in the boundary text are escaped from the parser
|
315
|
+
# (such as = in MS Outlook's boundary text))
|
316
|
+
if @body =~ /^(.*)boundary=(.*)$/m
|
317
|
+
preamble = $1
|
318
|
+
remainder = $2
|
319
|
+
if remainder =~ /;/
|
320
|
+
remainder =~ /^(.*?)(;.*)$/m
|
321
|
+
boundary_text = $1
|
322
|
+
post = $2.chomp
|
323
|
+
else
|
324
|
+
boundary_text = remainder.chomp
|
325
|
+
end
|
326
|
+
if boundary_text =~ /[\/\?\=]/
|
327
|
+
boundary_text = "\"#{boundary_text}\"" unless boundary_text =~ /^".*?"$/
|
328
|
+
@body = "#{preamble}boundary=#{boundary_text}#{post}"
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|
332
|
+
#:startdoc:
|
333
|
+
|
334
|
+
|
335
|
+
end
|
336
|
+
|
337
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#
|
2
|
+
# version.rb
|
3
|
+
#
|
4
|
+
#--
|
5
|
+
# Copyright (c) 1998-2003 Minero Aoki <aamine@loveruby.net>
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
8
|
+
# a copy of this software and associated documentation files (the
|
9
|
+
# "Software"), to deal in the Software without restriction, including
|
10
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
11
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
12
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
13
|
+
# the following conditions:
|
14
|
+
#
|
15
|
+
# The above copyright notice and this permission notice shall be
|
16
|
+
# included in all copies or substantial portions of the Software.
|
17
|
+
#
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
20
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
22
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
23
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
24
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
25
|
+
#
|
26
|
+
# Note: Originally licensed under LGPL v2+. Using MIT license for Rails
|
27
|
+
# with permission of Minero Aoki.
|
28
|
+
#++
|
29
|
+
|
30
|
+
#:stopdoc:
|
31
|
+
module TMail
|
32
|
+
module VERSION
|
33
|
+
MAJOR = 1
|
34
|
+
MINOR = 2
|
35
|
+
TINY = 3
|
36
|
+
|
37
|
+
STRING = [MAJOR, MINOR, TINY].join('.')
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Prefer gems to the bundled libs.
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
begin
|
5
|
+
gem 'tmail', '~> 1.2.3'
|
6
|
+
rescue Gem::LoadError
|
7
|
+
$:.unshift "#{File.dirname(__FILE__)}/tmail-1.2.3"
|
8
|
+
end
|
9
|
+
|
10
|
+
module TMail
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'tmail'
|
14
|
+
|
15
|
+
silence_warnings do
|
16
|
+
TMail::Encoder.const_set("MAX_LINE_LEN", 200)
|
17
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2004-2009 David Heinemeier Hansson
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
begin
|
25
|
+
require 'action_controller'
|
26
|
+
rescue LoadError
|
27
|
+
actionpack_path = "#{File.dirname(__FILE__)}/../../actionpack/lib"
|
28
|
+
if File.directory?(actionpack_path)
|
29
|
+
$:.unshift actionpack_path
|
30
|
+
require 'action_controller'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
require 'action_view'
|
35
|
+
|
36
|
+
module ActionMailer
|
37
|
+
def self.load_all!
|
38
|
+
[Base, Part, ::Text::Format, ::Net::SMTP]
|
39
|
+
end
|
40
|
+
|
41
|
+
autoload :AdvAttrAccessor, 'action_mailer/adv_attr_accessor'
|
42
|
+
autoload :Base, 'action_mailer/base'
|
43
|
+
autoload :Helpers, 'action_mailer/helpers'
|
44
|
+
autoload :Part, 'action_mailer/part'
|
45
|
+
autoload :PartContainer, 'action_mailer/part_container'
|
46
|
+
autoload :Quoting, 'action_mailer/quoting'
|
47
|
+
autoload :TestCase, 'action_mailer/test_case'
|
48
|
+
autoload :TestHelper, 'action_mailer/test_helper'
|
49
|
+
autoload :Utils, 'action_mailer/utils'
|
50
|
+
end
|
51
|
+
|
52
|
+
module Text
|
53
|
+
autoload :Format, 'action_mailer/vendor/text_format'
|
54
|
+
end
|
55
|
+
|
56
|
+
module Net
|
57
|
+
autoload :SMTP, 'net/smtp'
|
58
|
+
end
|
59
|
+
|
60
|
+
autoload :MailHelper, 'action_mailer/mail_helper'
|
61
|
+
|
62
|
+
require 'action_mailer/vendor/tmail'
|
data/lib/actionmailer.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
$:.unshift "#{File.dirname(__FILE__)}/../lib"
|
5
|
+
$:.unshift "#{File.dirname(__FILE__)}/../../activesupport/lib"
|
6
|
+
$:.unshift "#{File.dirname(__FILE__)}/../../actionpack/lib"
|
7
|
+
require 'action_mailer'
|
8
|
+
require 'action_mailer/test_case'
|
9
|
+
|
10
|
+
# Show backtraces for deprecated behavior for quicker cleanup.
|
11
|
+
ActiveSupport::Deprecation.debug = true
|
12
|
+
|
13
|
+
# Bogus template processors
|
14
|
+
ActionView::Template.register_template_handler :haml, lambda { |template| "Look its HAML!".inspect }
|
15
|
+
ActionView::Template.register_template_handler :bak, lambda { |template| "Lame backup".inspect }
|
16
|
+
|
17
|
+
$:.unshift "#{File.dirname(__FILE__)}/fixtures/helpers"
|
18
|
+
|
19
|
+
ActionView::Base.cache_template_loading = true
|
20
|
+
FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures')
|
21
|
+
ActionMailer::Base.template_root = FIXTURE_LOAD_PATH
|
22
|
+
|
23
|
+
class MockSMTP
|
24
|
+
def self.deliveries
|
25
|
+
@@deliveries
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize
|
29
|
+
@@deliveries = []
|
30
|
+
end
|
31
|
+
|
32
|
+
def sendmail(mail, from, to)
|
33
|
+
@@deliveries << [mail, from, to]
|
34
|
+
end
|
35
|
+
|
36
|
+
def start(*args)
|
37
|
+
yield self
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class Net::SMTP
|
42
|
+
def self.new(*args)
|
43
|
+
MockSMTP.new
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def uses_gem(gem_name, test_name, version = '> 0')
|
48
|
+
gem gem_name.to_s, version
|
49
|
+
require gem_name.to_s
|
50
|
+
yield
|
51
|
+
rescue LoadError
|
52
|
+
$stderr.puts "Skipping #{test_name} tests. `gem install #{gem_name}` and try again."
|
53
|
+
end
|
54
|
+
|
55
|
+
def set_delivery_method(delivery_method)
|
56
|
+
@old_delivery_method = ActionMailer::Base.delivery_method
|
57
|
+
ActionMailer::Base.delivery_method = delivery_method
|
58
|
+
end
|
59
|
+
|
60
|
+
def restore_delivery_method
|
61
|
+
ActionMailer::Base.delivery_method = @old_delivery_method
|
62
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
class AssetHostMailer < ActionMailer::Base
|
4
|
+
def email_with_asset(recipient)
|
5
|
+
recipients recipient
|
6
|
+
subject "testing email containing asset path while asset_host is set"
|
7
|
+
from "tester@example.com"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class AssetHostTest < Test::Unit::TestCase
|
12
|
+
def setup
|
13
|
+
set_delivery_method :test
|
14
|
+
ActionMailer::Base.perform_deliveries = true
|
15
|
+
ActionMailer::Base.deliveries = []
|
16
|
+
|
17
|
+
@recipient = 'test@localhost'
|
18
|
+
end
|
19
|
+
|
20
|
+
def teardown
|
21
|
+
restore_delivery_method
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_asset_host_as_string
|
25
|
+
ActionController::Base.asset_host = "http://www.example.com"
|
26
|
+
mail = AssetHostMailer.deliver_email_with_asset(@recipient)
|
27
|
+
assert_equal "<img alt=\"Somelogo\" src=\"http://www.example.com/images/somelogo.png\" />", mail.body.strip
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_asset_host_as_one_arguement_proc
|
31
|
+
ActionController::Base.asset_host = Proc.new { |source|
|
32
|
+
if source.starts_with?('/images')
|
33
|
+
"http://images.example.com"
|
34
|
+
else
|
35
|
+
"http://assets.example.com"
|
36
|
+
end
|
37
|
+
}
|
38
|
+
mail = AssetHostMailer.deliver_email_with_asset(@recipient)
|
39
|
+
assert_equal "<img alt=\"Somelogo\" src=\"http://images.example.com/images/somelogo.png\" />", mail.body.strip
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_asset_host_as_two_arguement_proc
|
43
|
+
ActionController::Base.asset_host = Proc.new {|source,request|
|
44
|
+
if request && request.ssl?
|
45
|
+
"https://www.example.com"
|
46
|
+
else
|
47
|
+
"http://www.example.com"
|
48
|
+
end
|
49
|
+
}
|
50
|
+
mail = nil
|
51
|
+
assert_nothing_raised { mail = AssetHostMailer.deliver_email_with_asset(@recipient) }
|
52
|
+
assert_equal "<img alt=\"Somelogo\" src=\"http://www.example.com/images/somelogo.png\" />", mail.body.strip
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
class DefaultDeliveryMethodMailer < ActionMailer::Base
|
4
|
+
end
|
5
|
+
|
6
|
+
class NonDefaultDeliveryMethodMailer < ActionMailer::Base
|
7
|
+
self.delivery_method = :sendmail
|
8
|
+
end
|
9
|
+
|
10
|
+
class ActionMailerBase_delivery_method_Test < Test::Unit::TestCase
|
11
|
+
def setup
|
12
|
+
set_delivery_method :smtp
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
restore_delivery_method
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_should_be_the_default_smtp
|
20
|
+
assert_equal :smtp, ActionMailer::Base.delivery_method
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class DefaultDeliveryMethodMailer_delivery_method_Test < Test::Unit::TestCase
|
25
|
+
def setup
|
26
|
+
set_delivery_method :smtp
|
27
|
+
end
|
28
|
+
|
29
|
+
def teardown
|
30
|
+
restore_delivery_method
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_should_be_the_default_smtp
|
34
|
+
assert_equal :smtp, DefaultDeliveryMethodMailer.delivery_method
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class NonDefaultDeliveryMethodMailer_delivery_method_Test < Test::Unit::TestCase
|
39
|
+
def setup
|
40
|
+
set_delivery_method :smtp
|
41
|
+
end
|
42
|
+
|
43
|
+
def teardown
|
44
|
+
restore_delivery_method
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_should_be_the_set_delivery_method
|
48
|
+
assert_equal :sendmail, NonDefaultDeliveryMethodMailer.delivery_method
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= image_tag "somelogo.png" %>
|
@@ -0,0 +1 @@
|
|
1
|
+
Inside
|
@@ -0,0 +1 @@
|
|
1
|
+
text/html multipart
|
@@ -0,0 +1 @@
|
|
1
|
+
text/plain multipart
|
@@ -0,0 +1 @@
|
|
1
|
+
You logged out
|
@@ -0,0 +1 @@
|
|
1
|
+
We do not spam
|
@@ -0,0 +1 @@
|
|
1
|
+
first mail
|
@@ -0,0 +1 @@
|
|
1
|
+
So, <%= example_format(@text) %>
|
@@ -0,0 +1 @@
|
|
1
|
+
Hello, <%= person_name %>. Thanks for registering!
|
@@ -0,0 +1 @@
|
|
1
|
+
This message brought to you by <%= name_of_the_mailer_class %>.
|