actionmailer-rack-upgrade 2.3.14.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +387 -0
- data/MIT-LICENSE +21 -0
- data/README +149 -0
- data/Rakefile +97 -0
- data/install.rb +30 -0
- data/lib/action_mailer/adv_attr_accessor.rb +30 -0
- data/lib/action_mailer/base.rb +739 -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 +62 -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.7/tmail/Makefile +18 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/address.rb +392 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/attachments.rb +65 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/base64.rb +46 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/compat.rb +41 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/config.rb +67 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/core_extensions.rb +63 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/encode.rb +590 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/header.rb +962 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/index.rb +9 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/interface.rb +1162 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/loader.rb +3 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/mail.rb +578 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/mailbox.rb +496 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/main.rb +6 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/mbox.rb +3 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/net.rb +250 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/obsolete.rb +132 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/parser.rb +1060 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/parser.y +416 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/port.rb +379 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/quoting.rb +164 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/require_arch.rb +58 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/scanner.rb +49 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/scanner_r.rb +262 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/stringio.rb +280 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/utils.rb +362 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/COPYING +504 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/README +12 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/big5freq.rb +927 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/big5prober.rb +42 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/chardistribution.rb +238 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/charsetgroupprober.rb +112 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/charsetprober.rb +75 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/codingstatemachine.rb +64 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/constants.rb +42 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/escprober.rb +89 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/escsm.rb +244 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/eucjpprober.rb +88 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/euckrfreq.rb +596 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/euckrprober.rb +42 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/euctwfreq.rb +430 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/euctwprober.rb +42 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/gb2312freq.rb +474 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/gb2312prober.rb +42 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/hebrewprober.rb +289 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/jisfreq.rb +570 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/jpcntx.rb +229 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/langbulgarianmodel.rb +229 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/langcyrillicmodel.rb +330 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/langgreekmodel.rb +227 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/langhebrewmodel.rb +202 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/langhungarianmodel.rb +226 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/langthaimodel.rb +201 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/latin1prober.rb +147 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/mbcharsetprober.rb +89 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/mbcsgroupprober.rb +45 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/mbcssm.rb +542 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/sbcharsetprober.rb +124 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/sbcsgroupprober.rb +56 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/sjisprober.rb +88 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/universaldetector.rb +168 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/utf8prober.rb +87 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet.rb +67 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail/version.rb +39 -0
- data/lib/action_mailer/vendor/tmail-1.2.7/tmail.rb +6 -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 +1145 -0
- data/test/quoting_test.rb +105 -0
- data/test/test_helper_test.rb +129 -0
- data/test/tmail_test.rb +22 -0
- data/test/url_test.rb +76 -0
- metadata +209 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
# lib/tmail/Makefile
|
2
|
+
#
|
3
|
+
|
4
|
+
debug:
|
5
|
+
rm -f parser.rb
|
6
|
+
make parser.rb DEBUG=true
|
7
|
+
|
8
|
+
parser.rb: parser.y
|
9
|
+
if [ "$(DEBUG)" = true ]; then \
|
10
|
+
racc -v -g -o$@ parser.y ;\
|
11
|
+
else \
|
12
|
+
racc -E -o$@ parser.y ;\
|
13
|
+
fi
|
14
|
+
|
15
|
+
clean:
|
16
|
+
rm -f parser.rb parser.output
|
17
|
+
|
18
|
+
distclean: clean
|
@@ -0,0 +1,392 @@
|
|
1
|
+
=begin rdoc
|
2
|
+
|
3
|
+
= Address handling class
|
4
|
+
|
5
|
+
=end
|
6
|
+
#--
|
7
|
+
# Copyright (c) 1998-2003 Minero Aoki <aamine@loveruby.net>
|
8
|
+
#
|
9
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
10
|
+
# a copy of this software and associated documentation files (the
|
11
|
+
# "Software"), to deal in the Software without restriction, including
|
12
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
13
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
14
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
15
|
+
# the following conditions:
|
16
|
+
#
|
17
|
+
# The above copyright notice and this permission notice shall be
|
18
|
+
# included in all copies or substantial portions of the Software.
|
19
|
+
#
|
20
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
21
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
23
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
24
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
25
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
26
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27
|
+
#
|
28
|
+
# Note: Originally licensed under LGPL v2+. Using MIT license for Rails
|
29
|
+
# with permission of Minero Aoki.
|
30
|
+
#++
|
31
|
+
|
32
|
+
require 'tmail/encode'
|
33
|
+
require 'tmail/parser'
|
34
|
+
|
35
|
+
|
36
|
+
module TMail
|
37
|
+
|
38
|
+
# = Class Address
|
39
|
+
#
|
40
|
+
# Provides a complete handling library for email addresses. Can parse a string of an
|
41
|
+
# address directly or take in preformatted addresses themselves. Allows you to add
|
42
|
+
# and remove phrases from the front of the address and provides a compare function for
|
43
|
+
# email addresses.
|
44
|
+
#
|
45
|
+
# == Parsing and Handling a Valid Address:
|
46
|
+
#
|
47
|
+
# Just pass the email address in as a string to Address.parse:
|
48
|
+
#
|
49
|
+
# email = TMail::Address.parse('Mikel Lindsaar <mikel@lindsaar.net>')
|
50
|
+
# #=> #<TMail::Address mikel@lindsaar.net>
|
51
|
+
# email.address
|
52
|
+
# #=> "mikel@lindsaar.net"
|
53
|
+
# email.local
|
54
|
+
# #=> "mikel"
|
55
|
+
# email.domain
|
56
|
+
# #=> "lindsaar.net"
|
57
|
+
# email.name # Aliased as phrase as well
|
58
|
+
# #=> "Mikel Lindsaar"
|
59
|
+
#
|
60
|
+
# == Detecting an Invalid Address
|
61
|
+
#
|
62
|
+
# If you want to check the syntactical validity of an email address, just pass it to
|
63
|
+
# Address.parse and catch any SyntaxError:
|
64
|
+
#
|
65
|
+
# begin
|
66
|
+
# TMail::Address.parse("mikel 2@@@@@ me .com")
|
67
|
+
# rescue TMail::SyntaxError
|
68
|
+
# puts("Invalid Email Address Detected")
|
69
|
+
# else
|
70
|
+
# puts("Address is valid")
|
71
|
+
# end
|
72
|
+
# #=> "Invalid Email Address Detected"
|
73
|
+
class Address
|
74
|
+
|
75
|
+
include TextUtils #:nodoc:
|
76
|
+
|
77
|
+
# Sometimes you need to parse an address, TMail can do it for you and provide you with
|
78
|
+
# a fairly robust method of detecting a valid address.
|
79
|
+
#
|
80
|
+
# Takes in a string, returns a TMail::Address object.
|
81
|
+
#
|
82
|
+
# Raises a TMail::SyntaxError on invalid email format
|
83
|
+
def Address.parse( str )
|
84
|
+
Parser.parse :ADDRESS, str
|
85
|
+
end
|
86
|
+
|
87
|
+
def address_group? #:nodoc:
|
88
|
+
false
|
89
|
+
end
|
90
|
+
|
91
|
+
# Address.new(local, domain)
|
92
|
+
#
|
93
|
+
# Accepts:
|
94
|
+
#
|
95
|
+
# * local - Left of the at symbol
|
96
|
+
#
|
97
|
+
# * domain - Array of the domain split at the periods.
|
98
|
+
#
|
99
|
+
# For example:
|
100
|
+
#
|
101
|
+
# Address.new("mikel", ["lindsaar", "net"])
|
102
|
+
# #=> "#<TMail::Address mikel@lindsaar.net>"
|
103
|
+
def initialize( local, domain )
|
104
|
+
if domain
|
105
|
+
domain.each do |s|
|
106
|
+
raise SyntaxError, 'empty word in domain' if s.empty?
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# This is to catch an unquoted "@" symbol in the local part of the
|
111
|
+
# address. Handles addresses like <"@"@me.com> and makes sure they
|
112
|
+
# stay like <"@"@me.com> (previously were becoming <@@me.com>)
|
113
|
+
if local && (local.join == '@' || local.join =~ /\A[^"].*?@.*?[^"]\Z/)
|
114
|
+
@local = "\"#{local.join}\""
|
115
|
+
else
|
116
|
+
@local = local
|
117
|
+
end
|
118
|
+
|
119
|
+
@domain = domain
|
120
|
+
@name = nil
|
121
|
+
@routes = []
|
122
|
+
end
|
123
|
+
|
124
|
+
# Provides the name or 'phrase' of the email address.
|
125
|
+
#
|
126
|
+
# For Example:
|
127
|
+
#
|
128
|
+
# email = TMail::Address.parse("Mikel Lindsaar <mikel@lindsaar.net>")
|
129
|
+
# email.name
|
130
|
+
# #=> "Mikel Lindsaar"
|
131
|
+
def name
|
132
|
+
@name
|
133
|
+
end
|
134
|
+
|
135
|
+
# Setter method for the name or phrase of the email
|
136
|
+
#
|
137
|
+
# For Example:
|
138
|
+
#
|
139
|
+
# email = TMail::Address.parse("mikel@lindsaar.net")
|
140
|
+
# email.name
|
141
|
+
# #=> nil
|
142
|
+
# email.name = "Mikel Lindsaar"
|
143
|
+
# email.to_s
|
144
|
+
# #=> "Mikel Lindsaar <mikel@me.com>"
|
145
|
+
def name=( str )
|
146
|
+
@name = str
|
147
|
+
@name = nil if str and str.empty?
|
148
|
+
end
|
149
|
+
|
150
|
+
#:stopdoc:
|
151
|
+
alias phrase name
|
152
|
+
alias phrase= name=
|
153
|
+
#:startdoc:
|
154
|
+
|
155
|
+
# This is still here from RFC 822, and is now obsolete per RFC2822 Section 4.
|
156
|
+
#
|
157
|
+
# "When interpreting addresses, the route portion SHOULD be ignored."
|
158
|
+
#
|
159
|
+
# It is still here, so you can access it.
|
160
|
+
#
|
161
|
+
# Routes return the route portion at the front of the email address, if any.
|
162
|
+
#
|
163
|
+
# For Example:
|
164
|
+
# email = TMail::Address.parse( "<@sa,@another:Mikel@me.com>")
|
165
|
+
# => #<TMail::Address Mikel@me.com>
|
166
|
+
# email.to_s
|
167
|
+
# => "<@sa,@another:Mikel@me.com>"
|
168
|
+
# email.routes
|
169
|
+
# => ["sa", "another"]
|
170
|
+
def routes
|
171
|
+
@routes
|
172
|
+
end
|
173
|
+
|
174
|
+
def inspect #:nodoc:
|
175
|
+
"#<#{self.class} #{address()}>"
|
176
|
+
end
|
177
|
+
|
178
|
+
# Returns the local part of the email address
|
179
|
+
#
|
180
|
+
# For Example:
|
181
|
+
#
|
182
|
+
# email = TMail::Address.parse("mikel@lindsaar.net")
|
183
|
+
# email.local
|
184
|
+
# #=> "mikel"
|
185
|
+
def local
|
186
|
+
return nil unless @local
|
187
|
+
return '""' if @local.size == 1 and @local[0].empty?
|
188
|
+
# Check to see if it is an array before trying to map it
|
189
|
+
if @local.respond_to?(:map)
|
190
|
+
@local.map {|i| quote_atom(i) }.join('.')
|
191
|
+
else
|
192
|
+
quote_atom(@local)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
# Returns the domain part of the email address
|
197
|
+
#
|
198
|
+
# For Example:
|
199
|
+
#
|
200
|
+
# email = TMail::Address.parse("mikel@lindsaar.net")
|
201
|
+
# email.local
|
202
|
+
# #=> "lindsaar.net"
|
203
|
+
def domain
|
204
|
+
return nil unless @domain
|
205
|
+
join_domain(@domain)
|
206
|
+
end
|
207
|
+
|
208
|
+
# Returns the full specific address itself
|
209
|
+
#
|
210
|
+
# For Example:
|
211
|
+
#
|
212
|
+
# email = TMail::Address.parse("mikel@lindsaar.net")
|
213
|
+
# email.address
|
214
|
+
# #=> "mikel@lindsaar.net"
|
215
|
+
def spec
|
216
|
+
s = self.local
|
217
|
+
d = self.domain
|
218
|
+
if s and d
|
219
|
+
s + '@' + d
|
220
|
+
else
|
221
|
+
s
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
alias address spec
|
226
|
+
|
227
|
+
# Provides == function to the email. Only checks the actual address
|
228
|
+
# and ignores the name/phrase component
|
229
|
+
#
|
230
|
+
# For Example
|
231
|
+
#
|
232
|
+
# addr1 = TMail::Address.parse("My Address <mikel@lindsaar.net>")
|
233
|
+
# #=> "#<TMail::Address mikel@lindsaar.net>"
|
234
|
+
# addr2 = TMail::Address.parse("Another <mikel@lindsaar.net>")
|
235
|
+
# #=> "#<TMail::Address mikel@lindsaar.net>"
|
236
|
+
# addr1 == addr2
|
237
|
+
# #=> true
|
238
|
+
def ==( other )
|
239
|
+
other.respond_to? :spec and self.spec == other.spec
|
240
|
+
end
|
241
|
+
|
242
|
+
alias eql? ==
|
243
|
+
|
244
|
+
# Provides a unique hash value for this record against the local and domain
|
245
|
+
# parts, ignores the name/phrase value
|
246
|
+
#
|
247
|
+
# email = TMail::Address.parse("mikel@lindsaar.net")
|
248
|
+
# email.hash
|
249
|
+
# #=> 18767598
|
250
|
+
def hash
|
251
|
+
@local.hash ^ @domain.hash
|
252
|
+
end
|
253
|
+
|
254
|
+
# Duplicates a TMail::Address object returning the duplicate
|
255
|
+
#
|
256
|
+
# addr1 = TMail::Address.parse("mikel@lindsaar.net")
|
257
|
+
# addr2 = addr1.dup
|
258
|
+
# addr1.id == addr2.id
|
259
|
+
# #=> false
|
260
|
+
def dup
|
261
|
+
obj = self.class.new(@local.dup, @domain.dup)
|
262
|
+
obj.name = @name.dup if @name
|
263
|
+
obj.routes.replace @routes
|
264
|
+
obj
|
265
|
+
end
|
266
|
+
|
267
|
+
include StrategyInterface #:nodoc:
|
268
|
+
|
269
|
+
def accept( strategy, dummy1 = nil, dummy2 = nil ) #:nodoc:
|
270
|
+
unless @local
|
271
|
+
strategy.meta '<>' # empty return-path
|
272
|
+
return
|
273
|
+
end
|
274
|
+
|
275
|
+
spec_p = (not @name and @routes.empty?)
|
276
|
+
if @name
|
277
|
+
strategy.phrase @name
|
278
|
+
strategy.space
|
279
|
+
end
|
280
|
+
tmp = spec_p ? '' : '<'
|
281
|
+
unless @routes.empty?
|
282
|
+
tmp << @routes.map {|i| '@' + i }.join(',') << ':'
|
283
|
+
end
|
284
|
+
tmp << self.spec
|
285
|
+
tmp << '>' unless spec_p
|
286
|
+
strategy.meta tmp
|
287
|
+
strategy.lwsp ''
|
288
|
+
end
|
289
|
+
|
290
|
+
end
|
291
|
+
|
292
|
+
|
293
|
+
class AddressGroup
|
294
|
+
|
295
|
+
include Enumerable
|
296
|
+
|
297
|
+
def address_group?
|
298
|
+
true
|
299
|
+
end
|
300
|
+
|
301
|
+
def initialize( name, addrs )
|
302
|
+
@name = name
|
303
|
+
@addresses = addrs
|
304
|
+
end
|
305
|
+
|
306
|
+
attr_reader :name
|
307
|
+
|
308
|
+
def ==( other )
|
309
|
+
other.respond_to? :to_a and @addresses == other.to_a
|
310
|
+
end
|
311
|
+
|
312
|
+
alias eql? ==
|
313
|
+
|
314
|
+
def hash
|
315
|
+
map {|i| i.hash }.hash
|
316
|
+
end
|
317
|
+
|
318
|
+
def []( idx )
|
319
|
+
@addresses[idx]
|
320
|
+
end
|
321
|
+
|
322
|
+
def size
|
323
|
+
@addresses.size
|
324
|
+
end
|
325
|
+
|
326
|
+
def empty?
|
327
|
+
@addresses.empty?
|
328
|
+
end
|
329
|
+
|
330
|
+
def each( &block )
|
331
|
+
@addresses.each(&block)
|
332
|
+
end
|
333
|
+
|
334
|
+
def to_a
|
335
|
+
@addresses.dup
|
336
|
+
end
|
337
|
+
|
338
|
+
alias to_ary to_a
|
339
|
+
|
340
|
+
def include?( a )
|
341
|
+
@addresses.include? a
|
342
|
+
end
|
343
|
+
|
344
|
+
def flatten
|
345
|
+
set = []
|
346
|
+
@addresses.each do |a|
|
347
|
+
if a.respond_to? :flatten
|
348
|
+
set.concat a.flatten
|
349
|
+
else
|
350
|
+
set.push a
|
351
|
+
end
|
352
|
+
end
|
353
|
+
set
|
354
|
+
end
|
355
|
+
|
356
|
+
def each_address( &block )
|
357
|
+
flatten.each(&block)
|
358
|
+
end
|
359
|
+
|
360
|
+
def add( a )
|
361
|
+
@addresses.push a
|
362
|
+
end
|
363
|
+
|
364
|
+
alias push add
|
365
|
+
|
366
|
+
def delete( a )
|
367
|
+
@addresses.delete a
|
368
|
+
end
|
369
|
+
|
370
|
+
include StrategyInterface
|
371
|
+
|
372
|
+
def accept( strategy, dummy1 = nil, dummy2 = nil )
|
373
|
+
strategy.phrase @name
|
374
|
+
strategy.meta ':'
|
375
|
+
strategy.space
|
376
|
+
first = true
|
377
|
+
each do |mbox|
|
378
|
+
if first
|
379
|
+
first = false
|
380
|
+
else
|
381
|
+
strategy.puts_meta ','
|
382
|
+
end
|
383
|
+
strategy.space
|
384
|
+
mbox.accept strategy
|
385
|
+
end
|
386
|
+
strategy.meta ';'
|
387
|
+
strategy.lwsp ''
|
388
|
+
end
|
389
|
+
|
390
|
+
end
|
391
|
+
|
392
|
+
end # module TMail
|
@@ -0,0 +1,65 @@
|
|
1
|
+
=begin rdoc
|
2
|
+
|
3
|
+
= Attachment handling file
|
4
|
+
|
5
|
+
=end
|
6
|
+
|
7
|
+
require 'kconv'
|
8
|
+
require 'stringio'
|
9
|
+
|
10
|
+
module TMail
|
11
|
+
class Attachment < StringIO
|
12
|
+
attr_accessor :original_filename, :content_type
|
13
|
+
alias quoted_filename original_filename
|
14
|
+
end
|
15
|
+
|
16
|
+
class Mail
|
17
|
+
def has_attachments?
|
18
|
+
attachment?(self) || multipart? && parts.any? { |part| attachment?(part) }
|
19
|
+
end
|
20
|
+
|
21
|
+
# Returns true if this part's content main type is text, else returns false.
|
22
|
+
# By main type is meant "text/plain" is text. "text/html" is text
|
23
|
+
def text_content_type?
|
24
|
+
self.header['content-type'] && (self.header['content-type'].main_type == 'text')
|
25
|
+
end
|
26
|
+
|
27
|
+
def inline_attachment?(part)
|
28
|
+
part['content-id'] || (part['content-disposition'] && part['content-disposition'].disposition == 'inline' && !part.text_content_type?)
|
29
|
+
end
|
30
|
+
|
31
|
+
def attachment?(part)
|
32
|
+
part.disposition_is_attachment? || (!part.content_type.nil? && !part.text_content_type?) unless part.multipart?
|
33
|
+
end
|
34
|
+
|
35
|
+
def attachments
|
36
|
+
if multipart?
|
37
|
+
parts.collect { |part| attachment(part) }.flatten.compact
|
38
|
+
elsif attachment?(self)
|
39
|
+
[attachment(self)]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def attachment(part)
|
46
|
+
if part.multipart?
|
47
|
+
part.attachments
|
48
|
+
elsif attachment?(part)
|
49
|
+
content = part.body # unquoted automatically by TMail#body
|
50
|
+
file_name = (part['content-location'] && part['content-location'].body) ||
|
51
|
+
part.sub_header('content-type', 'name') ||
|
52
|
+
part.sub_header('content-disposition', 'filename') ||
|
53
|
+
'noname'
|
54
|
+
|
55
|
+
return if content.blank?
|
56
|
+
|
57
|
+
attachment = TMail::Attachment.new(content)
|
58
|
+
attachment.original_filename = file_name.strip unless file_name.blank?
|
59
|
+
attachment.content_type = part.content_type
|
60
|
+
attachment
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,46 @@
|
|
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
|
+
#:stopdoc:
|
27
|
+
module TMail
|
28
|
+
module Base64
|
29
|
+
|
30
|
+
module_function
|
31
|
+
|
32
|
+
def folding_encode( str, eol = "\n", limit = 60 )
|
33
|
+
[str].pack('m')
|
34
|
+
end
|
35
|
+
|
36
|
+
def encode( str )
|
37
|
+
[str].pack('m').tr( "\r\n", '' )
|
38
|
+
end
|
39
|
+
|
40
|
+
def decode( str, strict = false )
|
41
|
+
str.unpack('m').first
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
#:startdoc:
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#:stopdoc:
|
2
|
+
unless Enumerable.method_defined?(:map)
|
3
|
+
module Enumerable #:nodoc:
|
4
|
+
alias map collect
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
unless Enumerable.method_defined?(:select)
|
9
|
+
module Enumerable #:nodoc:
|
10
|
+
alias select find_all
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
unless Enumerable.method_defined?(:reject)
|
15
|
+
module Enumerable #:nodoc:
|
16
|
+
def reject
|
17
|
+
result = []
|
18
|
+
each do |i|
|
19
|
+
result.push i unless yield(i)
|
20
|
+
end
|
21
|
+
result
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
unless Enumerable.method_defined?(:sort_by)
|
27
|
+
module Enumerable #:nodoc:
|
28
|
+
def sort_by
|
29
|
+
map {|i| [yield(i), i] }.sort.map {|val, i| i }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
unless File.respond_to?(:read)
|
35
|
+
def File.read(fname) #:nodoc:
|
36
|
+
File.open(fname) {|f|
|
37
|
+
return f.read
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
#:startdoc:
|
@@ -0,0 +1,67 @@
|
|
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
|
+
#:stopdoc:
|
27
|
+
module TMail
|
28
|
+
|
29
|
+
class Config
|
30
|
+
|
31
|
+
def initialize( strict )
|
32
|
+
@strict_parse = strict
|
33
|
+
@strict_base64decode = strict
|
34
|
+
end
|
35
|
+
|
36
|
+
def strict_parse?
|
37
|
+
@strict_parse
|
38
|
+
end
|
39
|
+
|
40
|
+
attr_writer :strict_parse
|
41
|
+
|
42
|
+
def strict_base64decode?
|
43
|
+
@strict_base64decode
|
44
|
+
end
|
45
|
+
|
46
|
+
attr_writer :strict_base64decode
|
47
|
+
|
48
|
+
def new_body_port( mail )
|
49
|
+
StringPort.new
|
50
|
+
end
|
51
|
+
|
52
|
+
alias new_preamble_port new_body_port
|
53
|
+
alias new_part_port new_body_port
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
DEFAULT_CONFIG = Config.new(false)
|
58
|
+
DEFAULT_STRICT_CONFIG = Config.new(true)
|
59
|
+
|
60
|
+
def Config.to_config( arg )
|
61
|
+
return DEFAULT_STRICT_CONFIG if arg == true
|
62
|
+
return DEFAULT_CONFIG if arg == false
|
63
|
+
arg or DEFAULT_CONFIG
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
#:startdoc:
|
@@ -0,0 +1,63 @@
|
|
1
|
+
#:stopdoc:
|
2
|
+
unless Object.respond_to?(:blank?)
|
3
|
+
class Object
|
4
|
+
# Check first to see if we are in a Rails environment, no need to
|
5
|
+
# define these methods if we are
|
6
|
+
|
7
|
+
# An object is blank if it's nil, empty, or a whitespace string.
|
8
|
+
# For example, "", " ", nil, [], and {} are blank.
|
9
|
+
#
|
10
|
+
# This simplifies
|
11
|
+
# if !address.nil? && !address.empty?
|
12
|
+
# to
|
13
|
+
# if !address.blank?
|
14
|
+
def blank?
|
15
|
+
if respond_to?(:empty?) && respond_to?(:strip)
|
16
|
+
empty? or strip.empty?
|
17
|
+
elsif respond_to?(:empty?)
|
18
|
+
empty?
|
19
|
+
else
|
20
|
+
!self
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class NilClass
|
26
|
+
def blank?
|
27
|
+
true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class FalseClass
|
32
|
+
def blank?
|
33
|
+
true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class TrueClass
|
38
|
+
def blank?
|
39
|
+
false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class Array
|
44
|
+
alias_method :blank?, :empty?
|
45
|
+
end
|
46
|
+
|
47
|
+
class Hash
|
48
|
+
alias_method :blank?, :empty?
|
49
|
+
end
|
50
|
+
|
51
|
+
class String
|
52
|
+
def blank?
|
53
|
+
empty? || strip.empty?
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class Numeric
|
58
|
+
def blank?
|
59
|
+
false
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
#:startdoc:
|