actionmailer-rack-upgrade-2 2.3.15
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,1162 @@
|
|
1
|
+
=begin rdoc
|
2
|
+
|
3
|
+
= interface.rb Provides an interface to the TMail object
|
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
|
+
# TMail::Mail objects get accessed primarily through the methods in this file.
|
33
|
+
#
|
34
|
+
#
|
35
|
+
|
36
|
+
require 'tmail/utils'
|
37
|
+
|
38
|
+
module TMail
|
39
|
+
|
40
|
+
class Mail
|
41
|
+
|
42
|
+
# Allows you to query the mail object with a string to get the contents
|
43
|
+
# of the field you want.
|
44
|
+
#
|
45
|
+
# Returns a string of the exact contents of the field
|
46
|
+
#
|
47
|
+
# mail.from = "mikel <mikel@lindsaar.net>"
|
48
|
+
# mail.header_string("From") #=> "mikel <mikel@lindsaar.net>"
|
49
|
+
def header_string( name, default = nil )
|
50
|
+
h = @header[name.downcase] or return default
|
51
|
+
h.to_s
|
52
|
+
end
|
53
|
+
|
54
|
+
#:stopdoc:
|
55
|
+
#--
|
56
|
+
#== Attributes
|
57
|
+
|
58
|
+
include TextUtils
|
59
|
+
|
60
|
+
def set_string_array_attr( key, strs )
|
61
|
+
strs.flatten!
|
62
|
+
if strs.empty?
|
63
|
+
@header.delete key.downcase
|
64
|
+
else
|
65
|
+
store key, strs.join(', ')
|
66
|
+
end
|
67
|
+
strs
|
68
|
+
end
|
69
|
+
private :set_string_array_attr
|
70
|
+
|
71
|
+
def set_string_attr( key, str )
|
72
|
+
if str
|
73
|
+
store key, str
|
74
|
+
else
|
75
|
+
@header.delete key.downcase
|
76
|
+
end
|
77
|
+
str
|
78
|
+
end
|
79
|
+
private :set_string_attr
|
80
|
+
|
81
|
+
def set_addrfield( name, arg )
|
82
|
+
if arg
|
83
|
+
h = HeaderField.internal_new(name, @config)
|
84
|
+
h.addrs.replace [arg].flatten
|
85
|
+
@header[name] = h
|
86
|
+
else
|
87
|
+
@header.delete name
|
88
|
+
end
|
89
|
+
arg
|
90
|
+
end
|
91
|
+
private :set_addrfield
|
92
|
+
|
93
|
+
def addrs2specs( addrs )
|
94
|
+
return nil unless addrs
|
95
|
+
list = addrs.map {|addr|
|
96
|
+
if addr.address_group?
|
97
|
+
then addr.map {|a| a.spec }
|
98
|
+
else addr.spec
|
99
|
+
end
|
100
|
+
}.flatten
|
101
|
+
return nil if list.empty?
|
102
|
+
list
|
103
|
+
end
|
104
|
+
private :addrs2specs
|
105
|
+
|
106
|
+
#:startdoc:
|
107
|
+
|
108
|
+
#== Date and Time methods
|
109
|
+
|
110
|
+
# Returns the date of the email message as per the "date" header value or returns
|
111
|
+
# nil by default (if no date field exists).
|
112
|
+
#
|
113
|
+
# You can also pass whatever default you want into this method and it will return
|
114
|
+
# that instead of nil if there is no date already set.
|
115
|
+
def date( default = nil )
|
116
|
+
if h = @header['date']
|
117
|
+
h.date
|
118
|
+
else
|
119
|
+
default
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
# Destructively sets the date of the mail object with the passed Time instance,
|
124
|
+
# returns a Time instance set to the date/time of the mail
|
125
|
+
#
|
126
|
+
# Example:
|
127
|
+
#
|
128
|
+
# now = Time.now
|
129
|
+
# mail.date = now
|
130
|
+
# mail.date #=> Sat Nov 03 18:47:50 +1100 2007
|
131
|
+
# mail.date.class #=> Time
|
132
|
+
def date=( time )
|
133
|
+
if time
|
134
|
+
store 'Date', time2str(time)
|
135
|
+
else
|
136
|
+
@header.delete 'date'
|
137
|
+
end
|
138
|
+
time
|
139
|
+
end
|
140
|
+
|
141
|
+
# Returns the time of the mail message formatted to your taste using a
|
142
|
+
# strftime format string. If no date set returns nil by default or whatever value
|
143
|
+
# you pass as the second optional parameter.
|
144
|
+
#
|
145
|
+
# time = Time.now # (on Nov 16 2007)
|
146
|
+
# mail.date = time
|
147
|
+
# mail.strftime("%D") #=> "11/16/07"
|
148
|
+
def strftime( fmt, default = nil )
|
149
|
+
if t = date
|
150
|
+
t.strftime(fmt)
|
151
|
+
else
|
152
|
+
default
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
#== Destination methods
|
157
|
+
|
158
|
+
# Return a TMail::Addresses instance for each entry in the "To:" field of the mail object header.
|
159
|
+
#
|
160
|
+
# If the "To:" field does not exist, will return nil by default or the value you
|
161
|
+
# pass as the optional parameter.
|
162
|
+
#
|
163
|
+
# Example:
|
164
|
+
#
|
165
|
+
# mail = TMail::Mail.new
|
166
|
+
# mail.to_addrs #=> nil
|
167
|
+
# mail.to_addrs([]) #=> []
|
168
|
+
# mail.to = "Mikel <mikel@me.org>, another Mikel <mikel@you.org>"
|
169
|
+
# mail.to_addrs #=> [#<TMail::Address mikel@me.org>, #<TMail::Address mikel@you.org>]
|
170
|
+
def to_addrs( default = nil )
|
171
|
+
if h = @header['to']
|
172
|
+
h.addrs
|
173
|
+
else
|
174
|
+
default
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
# Return a TMail::Addresses instance for each entry in the "Cc:" field of the mail object header.
|
179
|
+
#
|
180
|
+
# If the "Cc:" field does not exist, will return nil by default or the value you
|
181
|
+
# pass as the optional parameter.
|
182
|
+
#
|
183
|
+
# Example:
|
184
|
+
#
|
185
|
+
# mail = TMail::Mail.new
|
186
|
+
# mail.cc_addrs #=> nil
|
187
|
+
# mail.cc_addrs([]) #=> []
|
188
|
+
# mail.cc = "Mikel <mikel@me.org>, another Mikel <mikel@you.org>"
|
189
|
+
# mail.cc_addrs #=> [#<TMail::Address mikel@me.org>, #<TMail::Address mikel@you.org>]
|
190
|
+
def cc_addrs( default = nil )
|
191
|
+
if h = @header['cc']
|
192
|
+
h.addrs
|
193
|
+
else
|
194
|
+
default
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
# Return a TMail::Addresses instance for each entry in the "Bcc:" field of the mail object header.
|
199
|
+
#
|
200
|
+
# If the "Bcc:" field does not exist, will return nil by default or the value you
|
201
|
+
# pass as the optional parameter.
|
202
|
+
#
|
203
|
+
# Example:
|
204
|
+
#
|
205
|
+
# mail = TMail::Mail.new
|
206
|
+
# mail.bcc_addrs #=> nil
|
207
|
+
# mail.bcc_addrs([]) #=> []
|
208
|
+
# mail.bcc = "Mikel <mikel@me.org>, another Mikel <mikel@you.org>"
|
209
|
+
# mail.bcc_addrs #=> [#<TMail::Address mikel@me.org>, #<TMail::Address mikel@you.org>]
|
210
|
+
def bcc_addrs( default = nil )
|
211
|
+
if h = @header['bcc']
|
212
|
+
h.addrs
|
213
|
+
else
|
214
|
+
default
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
# Destructively set the to field of the "To:" header to equal the passed in string.
|
219
|
+
#
|
220
|
+
# TMail will parse your contents and turn each valid email address into a TMail::Address
|
221
|
+
# object before assigning it to the mail message.
|
222
|
+
#
|
223
|
+
# Example:
|
224
|
+
#
|
225
|
+
# mail = TMail::Mail.new
|
226
|
+
# mail.to = "Mikel <mikel@me.org>, another Mikel <mikel@you.org>"
|
227
|
+
# mail.to_addrs #=> [#<TMail::Address mikel@me.org>, #<TMail::Address mikel@you.org>]
|
228
|
+
def to_addrs=( arg )
|
229
|
+
set_addrfield 'to', arg
|
230
|
+
end
|
231
|
+
|
232
|
+
# Destructively set the to field of the "Cc:" header to equal the passed in string.
|
233
|
+
#
|
234
|
+
# TMail will parse your contents and turn each valid email address into a TMail::Address
|
235
|
+
# object before assigning it to the mail message.
|
236
|
+
#
|
237
|
+
# Example:
|
238
|
+
#
|
239
|
+
# mail = TMail::Mail.new
|
240
|
+
# mail.cc = "Mikel <mikel@me.org>, another Mikel <mikel@you.org>"
|
241
|
+
# mail.cc_addrs #=> [#<TMail::Address mikel@me.org>, #<TMail::Address mikel@you.org>]
|
242
|
+
def cc_addrs=( arg )
|
243
|
+
set_addrfield 'cc', arg
|
244
|
+
end
|
245
|
+
|
246
|
+
# Destructively set the to field of the "Bcc:" header to equal the passed in string.
|
247
|
+
#
|
248
|
+
# TMail will parse your contents and turn each valid email address into a TMail::Address
|
249
|
+
# object before assigning it to the mail message.
|
250
|
+
#
|
251
|
+
# Example:
|
252
|
+
#
|
253
|
+
# mail = TMail::Mail.new
|
254
|
+
# mail.bcc = "Mikel <mikel@me.org>, another Mikel <mikel@you.org>"
|
255
|
+
# mail.bcc_addrs #=> [#<TMail::Address mikel@me.org>, #<TMail::Address mikel@you.org>]
|
256
|
+
def bcc_addrs=( arg )
|
257
|
+
set_addrfield 'bcc', arg
|
258
|
+
end
|
259
|
+
|
260
|
+
# Returns who the email is to as an Array of email addresses as opposed to an Array of
|
261
|
+
# TMail::Address objects which is what Mail#to_addrs returns
|
262
|
+
#
|
263
|
+
# Example:
|
264
|
+
#
|
265
|
+
# mail = TMail::Mail.new
|
266
|
+
# mail.to = "Mikel <mikel@me.org>, another Mikel <mikel@you.org>"
|
267
|
+
# mail.to #=> ["mikel@me.org", "mikel@you.org"]
|
268
|
+
def to( default = nil )
|
269
|
+
addrs2specs(to_addrs(nil)) || default
|
270
|
+
end
|
271
|
+
|
272
|
+
# Returns who the email cc'd as an Array of email addresses as opposed to an Array of
|
273
|
+
# TMail::Address objects which is what Mail#to_addrs returns
|
274
|
+
#
|
275
|
+
# Example:
|
276
|
+
#
|
277
|
+
# mail = TMail::Mail.new
|
278
|
+
# mail.cc = "Mikel <mikel@me.org>, another Mikel <mikel@you.org>"
|
279
|
+
# mail.cc #=> ["mikel@me.org", "mikel@you.org"]
|
280
|
+
def cc( default = nil )
|
281
|
+
addrs2specs(cc_addrs(nil)) || default
|
282
|
+
end
|
283
|
+
|
284
|
+
# Returns who the email bcc'd as an Array of email addresses as opposed to an Array of
|
285
|
+
# TMail::Address objects which is what Mail#to_addrs returns
|
286
|
+
#
|
287
|
+
# Example:
|
288
|
+
#
|
289
|
+
# mail = TMail::Mail.new
|
290
|
+
# mail.bcc = "Mikel <mikel@me.org>, another Mikel <mikel@you.org>"
|
291
|
+
# mail.bcc #=> ["mikel@me.org", "mikel@you.org"]
|
292
|
+
def bcc( default = nil )
|
293
|
+
addrs2specs(bcc_addrs(nil)) || default
|
294
|
+
end
|
295
|
+
|
296
|
+
# Destructively sets the "To:" field to the passed array of strings (which should be valid
|
297
|
+
# email addresses)
|
298
|
+
#
|
299
|
+
# Example:
|
300
|
+
#
|
301
|
+
# mail = TMail::Mail.new
|
302
|
+
# mail.to = ["mikel@abc.com", "Mikel <mikel@xyz.com>"]
|
303
|
+
# mail.to #=> ["mikel@abc.org", "mikel@xyz.org"]
|
304
|
+
# mail['to'].to_s #=> "mikel@abc.com, Mikel <mikel@xyz.com>"
|
305
|
+
def to=( *strs )
|
306
|
+
set_string_array_attr 'To', strs
|
307
|
+
end
|
308
|
+
|
309
|
+
# Destructively sets the "Cc:" field to the passed array of strings (which should be valid
|
310
|
+
# email addresses)
|
311
|
+
#
|
312
|
+
# Example:
|
313
|
+
#
|
314
|
+
# mail = TMail::Mail.new
|
315
|
+
# mail.cc = ["mikel@abc.com", "Mikel <mikel@xyz.com>"]
|
316
|
+
# mail.cc #=> ["mikel@abc.org", "mikel@xyz.org"]
|
317
|
+
# mail['cc'].to_s #=> "mikel@abc.com, Mikel <mikel@xyz.com>"
|
318
|
+
def cc=( *strs )
|
319
|
+
set_string_array_attr 'Cc', strs
|
320
|
+
end
|
321
|
+
|
322
|
+
# Destructively sets the "Bcc:" field to the passed array of strings (which should be valid
|
323
|
+
# email addresses)
|
324
|
+
#
|
325
|
+
# Example:
|
326
|
+
#
|
327
|
+
# mail = TMail::Mail.new
|
328
|
+
# mail.bcc = ["mikel@abc.com", "Mikel <mikel@xyz.com>"]
|
329
|
+
# mail.bcc #=> ["mikel@abc.org", "mikel@xyz.org"]
|
330
|
+
# mail['bcc'].to_s #=> "mikel@abc.com, Mikel <mikel@xyz.com>"
|
331
|
+
def bcc=( *strs )
|
332
|
+
set_string_array_attr 'Bcc', strs
|
333
|
+
end
|
334
|
+
|
335
|
+
#== Originator methods
|
336
|
+
|
337
|
+
# Return a TMail::Addresses instance for each entry in the "From:" field of the mail object header.
|
338
|
+
#
|
339
|
+
# If the "From:" field does not exist, will return nil by default or the value you
|
340
|
+
# pass as the optional parameter.
|
341
|
+
#
|
342
|
+
# Example:
|
343
|
+
#
|
344
|
+
# mail = TMail::Mail.new
|
345
|
+
# mail.from_addrs #=> nil
|
346
|
+
# mail.from_addrs([]) #=> []
|
347
|
+
# mail.from = "Mikel <mikel@me.org>, another Mikel <mikel@you.org>"
|
348
|
+
# mail.from_addrs #=> [#<TMail::Address mikel@me.org>, #<TMail::Address mikel@you.org>]
|
349
|
+
def from_addrs( default = nil )
|
350
|
+
if h = @header['from']
|
351
|
+
h.addrs
|
352
|
+
else
|
353
|
+
default
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
# Destructively set the to value of the "From:" header to equal the passed in string.
|
358
|
+
#
|
359
|
+
# TMail will parse your contents and turn each valid email address into a TMail::Address
|
360
|
+
# object before assigning it to the mail message.
|
361
|
+
#
|
362
|
+
# Example:
|
363
|
+
#
|
364
|
+
# mail = TMail::Mail.new
|
365
|
+
# mail.from_addrs = "Mikel <mikel@me.org>, another Mikel <mikel@you.org>"
|
366
|
+
# mail.from_addrs #=> [#<TMail::Address mikel@me.org>, #<TMail::Address mikel@you.org>]
|
367
|
+
def from_addrs=( arg )
|
368
|
+
set_addrfield 'from', arg
|
369
|
+
end
|
370
|
+
|
371
|
+
# Returns who the email is from as an Array of email address strings instead to an Array of
|
372
|
+
# TMail::Address objects which is what Mail#from_addrs returns
|
373
|
+
#
|
374
|
+
# Example:
|
375
|
+
#
|
376
|
+
# mail = TMail::Mail.new
|
377
|
+
# mail.from = "Mikel <mikel@me.org>, another Mikel <mikel@you.org>"
|
378
|
+
# mail.from #=> ["mikel@me.org", "mikel@you.org"]
|
379
|
+
def from( default = nil )
|
380
|
+
addrs2specs(from_addrs(nil)) || default
|
381
|
+
end
|
382
|
+
|
383
|
+
# Destructively sets the "From:" field to the passed array of strings (which should be valid
|
384
|
+
# email addresses)
|
385
|
+
#
|
386
|
+
# Example:
|
387
|
+
#
|
388
|
+
# mail = TMail::Mail.new
|
389
|
+
# mail.from = ["mikel@abc.com", "Mikel <mikel@xyz.com>"]
|
390
|
+
# mail.from #=> ["mikel@abc.org", "mikel@xyz.org"]
|
391
|
+
# mail['from'].to_s #=> "mikel@abc.com, Mikel <mikel@xyz.com>"
|
392
|
+
def from=( *strs )
|
393
|
+
set_string_array_attr 'From', strs
|
394
|
+
end
|
395
|
+
|
396
|
+
# Returns the "friendly" human readable part of the address
|
397
|
+
#
|
398
|
+
# Example:
|
399
|
+
#
|
400
|
+
# mail = TMail::Mail.new
|
401
|
+
# mail.from = "Mikel Lindsaar <mikel@abc.com>"
|
402
|
+
# mail.friendly_from #=> "Mikel Lindsaar"
|
403
|
+
def friendly_from( default = nil )
|
404
|
+
h = @header['from']
|
405
|
+
a, = h.addrs
|
406
|
+
return default unless a
|
407
|
+
return a.phrase if a.phrase
|
408
|
+
return h.comments.join(' ') unless h.comments.empty?
|
409
|
+
a.spec
|
410
|
+
end
|
411
|
+
|
412
|
+
# Return a TMail::Addresses instance for each entry in the "Reply-To:" field of the mail object header.
|
413
|
+
#
|
414
|
+
# If the "Reply-To:" field does not exist, will return nil by default or the value you
|
415
|
+
# pass as the optional parameter.
|
416
|
+
#
|
417
|
+
# Example:
|
418
|
+
#
|
419
|
+
# mail = TMail::Mail.new
|
420
|
+
# mail.reply_to_addrs #=> nil
|
421
|
+
# mail.reply_to_addrs([]) #=> []
|
422
|
+
# mail.reply_to = "Mikel <mikel@me.org>, another Mikel <mikel@you.org>"
|
423
|
+
# mail.reply_to_addrs #=> [#<TMail::Address mikel@me.org>, #<TMail::Address mikel@you.org>]
|
424
|
+
def reply_to_addrs( default = nil )
|
425
|
+
if h = @header['reply-to']
|
426
|
+
h.addrs.blank? ? default : h.addrs
|
427
|
+
else
|
428
|
+
default
|
429
|
+
end
|
430
|
+
end
|
431
|
+
|
432
|
+
# Destructively set the to value of the "Reply-To:" header to equal the passed in argument.
|
433
|
+
#
|
434
|
+
# TMail will parse your contents and turn each valid email address into a TMail::Address
|
435
|
+
# object before assigning it to the mail message.
|
436
|
+
#
|
437
|
+
# Example:
|
438
|
+
#
|
439
|
+
# mail = TMail::Mail.new
|
440
|
+
# mail.reply_to_addrs = "Mikel <mikel@me.org>, another Mikel <mikel@you.org>"
|
441
|
+
# mail.reply_to_addrs #=> [#<TMail::Address mikel@me.org>, #<TMail::Address mikel@you.org>]
|
442
|
+
def reply_to_addrs=( arg )
|
443
|
+
set_addrfield 'reply-to', arg
|
444
|
+
end
|
445
|
+
|
446
|
+
# Returns who the email is from as an Array of email address strings instead to an Array of
|
447
|
+
# TMail::Address objects which is what Mail#reply_to_addrs returns
|
448
|
+
#
|
449
|
+
# Example:
|
450
|
+
#
|
451
|
+
# mail = TMail::Mail.new
|
452
|
+
# mail.reply_to = "Mikel <mikel@me.org>, another Mikel <mikel@you.org>"
|
453
|
+
# mail.reply_to #=> ["mikel@me.org", "mikel@you.org"]
|
454
|
+
def reply_to( default = nil )
|
455
|
+
addrs2specs(reply_to_addrs(nil)) || default
|
456
|
+
end
|
457
|
+
|
458
|
+
# Destructively sets the "Reply-To:" field to the passed array of strings (which should be valid
|
459
|
+
# email addresses)
|
460
|
+
#
|
461
|
+
# Example:
|
462
|
+
#
|
463
|
+
# mail = TMail::Mail.new
|
464
|
+
# mail.reply_to = ["mikel@abc.com", "Mikel <mikel@xyz.com>"]
|
465
|
+
# mail.reply_to #=> ["mikel@abc.org", "mikel@xyz.org"]
|
466
|
+
# mail['reply_to'].to_s #=> "mikel@abc.com, Mikel <mikel@xyz.com>"
|
467
|
+
def reply_to=( *strs )
|
468
|
+
set_string_array_attr 'Reply-To', strs
|
469
|
+
end
|
470
|
+
|
471
|
+
# Return a TMail::Addresses instance of the "Sender:" field of the mail object header.
|
472
|
+
#
|
473
|
+
# If the "Sender:" field does not exist, will return nil by default or the value you
|
474
|
+
# pass as the optional parameter.
|
475
|
+
#
|
476
|
+
# Example:
|
477
|
+
#
|
478
|
+
# mail = TMail::Mail.new
|
479
|
+
# mail.sender #=> nil
|
480
|
+
# mail.sender([]) #=> []
|
481
|
+
# mail.sender = "Mikel <mikel@me.org>"
|
482
|
+
# mail.reply_to_addrs #=> [#<TMail::Address mikel@me.org>]
|
483
|
+
def sender_addr( default = nil )
|
484
|
+
f = @header['sender'] or return default
|
485
|
+
f.addr or return default
|
486
|
+
end
|
487
|
+
|
488
|
+
# Destructively set the to value of the "Sender:" header to equal the passed in argument.
|
489
|
+
#
|
490
|
+
# TMail will parse your contents and turn each valid email address into a TMail::Address
|
491
|
+
# object before assigning it to the mail message.
|
492
|
+
#
|
493
|
+
# Example:
|
494
|
+
#
|
495
|
+
# mail = TMail::Mail.new
|
496
|
+
# mail.sender_addrs = "Mikel <mikel@me.org>, another Mikel <mikel@you.org>"
|
497
|
+
# mail.sender_addrs #=> [#<TMail::Address mikel@me.org>, #<TMail::Address mikel@you.org>]
|
498
|
+
def sender_addr=( addr )
|
499
|
+
if addr
|
500
|
+
h = HeaderField.internal_new('sender', @config)
|
501
|
+
h.addr = addr
|
502
|
+
@header['sender'] = h
|
503
|
+
else
|
504
|
+
@header.delete 'sender'
|
505
|
+
end
|
506
|
+
addr
|
507
|
+
end
|
508
|
+
|
509
|
+
# Returns who the sender of this mail is as string instead to an Array of
|
510
|
+
# TMail::Address objects which is what Mail#sender_addr returns
|
511
|
+
#
|
512
|
+
# Example:
|
513
|
+
#
|
514
|
+
# mail = TMail::Mail.new
|
515
|
+
# mail.sender = "Mikel <mikel@me.org>"
|
516
|
+
# mail.sender #=> "mikel@me.org"
|
517
|
+
def sender( default = nil )
|
518
|
+
f = @header['sender'] or return default
|
519
|
+
a = f.addr or return default
|
520
|
+
a.spec
|
521
|
+
end
|
522
|
+
|
523
|
+
# Destructively sets the "Sender:" field to the passed string (which should be a valid
|
524
|
+
# email address)
|
525
|
+
#
|
526
|
+
# Example:
|
527
|
+
#
|
528
|
+
# mail = TMail::Mail.new
|
529
|
+
# mail.sender = "mikel@abc.com"
|
530
|
+
# mail.sender #=> "mikel@abc.org"
|
531
|
+
# mail['sender'].to_s #=> "mikel@abc.com"
|
532
|
+
def sender=( str )
|
533
|
+
set_string_attr 'Sender', str
|
534
|
+
end
|
535
|
+
|
536
|
+
#== Subject methods
|
537
|
+
|
538
|
+
# Returns the subject of the mail instance.
|
539
|
+
#
|
540
|
+
# If the subject field does not exist, returns nil by default or you can pass in as
|
541
|
+
# the parameter for what you want the default value to be.
|
542
|
+
#
|
543
|
+
# Example:
|
544
|
+
#
|
545
|
+
# mail = TMail::Mail.new
|
546
|
+
# mail.subject #=> nil
|
547
|
+
# mail.subject("") #=> ""
|
548
|
+
# mail.subject = "Hello"
|
549
|
+
# mail.subject #=> "Hello"
|
550
|
+
def subject( default = nil )
|
551
|
+
if h = @header['subject']
|
552
|
+
h.body
|
553
|
+
else
|
554
|
+
default
|
555
|
+
end
|
556
|
+
end
|
557
|
+
alias quoted_subject subject
|
558
|
+
|
559
|
+
# Destructively sets the passed string as the subject of the mail message.
|
560
|
+
#
|
561
|
+
# Example
|
562
|
+
#
|
563
|
+
# mail = TMail::Mail.new
|
564
|
+
# mail.subject #=> "This subject"
|
565
|
+
# mail.subject = "Another subject"
|
566
|
+
# mail.subject #=> "Another subject"
|
567
|
+
def subject=( str )
|
568
|
+
set_string_attr 'Subject', str
|
569
|
+
end
|
570
|
+
|
571
|
+
#== Message Identity & Threading Methods
|
572
|
+
|
573
|
+
# Returns the message ID for this mail object instance.
|
574
|
+
#
|
575
|
+
# If the message_id field does not exist, returns nil by default or you can pass in as
|
576
|
+
# the parameter for what you want the default value to be.
|
577
|
+
#
|
578
|
+
# Example:
|
579
|
+
#
|
580
|
+
# mail = TMail::Mail.new
|
581
|
+
# mail.message_id #=> nil
|
582
|
+
# mail.message_id(TMail.new_message_id) #=> "<47404c5326d9c_2ad4fbb80161@baci.local.tmail>"
|
583
|
+
# mail.message_id = TMail.new_message_id
|
584
|
+
# mail.message_id #=> "<47404c5326d9c_2ad4fbb80161@baci.local.tmail>"
|
585
|
+
def message_id( default = nil )
|
586
|
+
if h = @header['message-id']
|
587
|
+
h.id || default
|
588
|
+
else
|
589
|
+
default
|
590
|
+
end
|
591
|
+
end
|
592
|
+
|
593
|
+
# Destructively sets the message ID of the mail object instance to the passed in string
|
594
|
+
#
|
595
|
+
# Invalid message IDs are ignored (silently, unless configured otherwise) and result in
|
596
|
+
# a nil message ID. Left and right angle brackets are required.
|
597
|
+
#
|
598
|
+
# Be warned however, that calling mail.ready_to_send will overwrite whatever value you
|
599
|
+
# have in this field with an automatically generated unique value.
|
600
|
+
#
|
601
|
+
# If you really want to set your own message ID and know what you are doing per the
|
602
|
+
# various RFCs, you can do so with the enforced_message_id= command
|
603
|
+
#
|
604
|
+
# Example:
|
605
|
+
#
|
606
|
+
# mail = TMail::Mail.new
|
607
|
+
# mail.message_id = "<348F04F142D69C21-291E56D292BC@xxxx.net>"
|
608
|
+
# mail.message_id #=> "<348F04F142D69C21-291E56D292BC@xxxx.net>"
|
609
|
+
# mail.message_id = "this_is_my_badly_formatted_message_id"
|
610
|
+
# mail.message_id #=> nil
|
611
|
+
def message_id=( str )
|
612
|
+
set_string_attr 'Message-Id', str
|
613
|
+
end
|
614
|
+
|
615
|
+
# Destructively sets the message ID of the mail object instance to the passed in string
|
616
|
+
# and also guarantees that calling #ready_to_send will not destroy what you set as the
|
617
|
+
# message_id
|
618
|
+
#
|
619
|
+
# Example:
|
620
|
+
#
|
621
|
+
# mail = TMail::Mail.new
|
622
|
+
# mail.message_id = "<348F04F142D69C21-291E56D292BC@xxxx.net>"
|
623
|
+
# mail.message_id #=> "<348F04F142D69C21-291E56D292BC@xxxx.net>"
|
624
|
+
# mail.ready_to_send
|
625
|
+
# mail.message_id #=> "<348F04F142D69C21-291E56D292BC@xxxx.net>"
|
626
|
+
def enforced_message_id=( str )
|
627
|
+
@message_id_enforced = true
|
628
|
+
self.message_id = ( str )
|
629
|
+
end
|
630
|
+
|
631
|
+
# Returns the "In-Reply-To:" field contents as an array of this mail instance if it exists
|
632
|
+
#
|
633
|
+
# If the in_reply_to field does not exist, returns nil by default or you can pass in as
|
634
|
+
# the parameter for what you want the default value to be.
|
635
|
+
#
|
636
|
+
# Example:
|
637
|
+
#
|
638
|
+
# mail = TMail::Mail.new
|
639
|
+
# mail.in_reply_to #=> nil
|
640
|
+
# mail.in_reply_to([]) #=> []
|
641
|
+
# TMail::Mail.load("../test/fixtures/raw_email_reply")
|
642
|
+
# mail.in_reply_to #=> ["<348F04F142D69C21-291E56D292BC@xxxx.net>"]
|
643
|
+
def in_reply_to( default = nil )
|
644
|
+
if h = @header['in-reply-to']
|
645
|
+
h.ids
|
646
|
+
else
|
647
|
+
default
|
648
|
+
end
|
649
|
+
end
|
650
|
+
|
651
|
+
# Destructively sets the value of the "In-Reply-To:" field of an email.
|
652
|
+
#
|
653
|
+
# Accepts an array of a single string of a message id
|
654
|
+
#
|
655
|
+
# Example:
|
656
|
+
#
|
657
|
+
# mail = TMail::Mail.new
|
658
|
+
# mail.in_reply_to = ["<348F04F142D69C21-291E56D292BC@xxxx.net>"]
|
659
|
+
# mail.in_reply_to #=> ["<348F04F142D69C21-291E56D292BC@xxxx.net>"]
|
660
|
+
def in_reply_to=( *idstrs )
|
661
|
+
set_string_array_attr 'In-Reply-To', idstrs
|
662
|
+
end
|
663
|
+
|
664
|
+
# Returns the references of this email (prior messages relating to this message)
|
665
|
+
# as an array of message ID strings. Useful when you are trying to thread an
|
666
|
+
# email.
|
667
|
+
#
|
668
|
+
# If the references field does not exist, returns nil by default or you can pass in as
|
669
|
+
# the parameter for what you want the default value to be.
|
670
|
+
#
|
671
|
+
# Example:
|
672
|
+
#
|
673
|
+
# mail = TMail::Mail.new
|
674
|
+
# mail.references #=> nil
|
675
|
+
# mail.references([]) #=> []
|
676
|
+
# mail = TMail::Mail.load("../test/fixtures/raw_email_reply")
|
677
|
+
# mail.references #=> ["<473FF3B8.9020707@xxx.org>", "<348F04F142D69C21-291E56D292BC@xxxx.net>"]
|
678
|
+
def references( default = nil )
|
679
|
+
if h = @header['references']
|
680
|
+
h.refs
|
681
|
+
else
|
682
|
+
default
|
683
|
+
end
|
684
|
+
end
|
685
|
+
|
686
|
+
# Destructively sets the value of the "References:" field of an email.
|
687
|
+
#
|
688
|
+
# Accepts an array of strings of message IDs
|
689
|
+
#
|
690
|
+
# Example:
|
691
|
+
#
|
692
|
+
# mail = TMail::Mail.new
|
693
|
+
# mail.references = ["<348F04F142D69C21-291E56D292BC@xxxx.net>"]
|
694
|
+
# mail.references #=> ["<348F04F142D69C21-291E56D292BC@xxxx.net>"]
|
695
|
+
def references=( *strs )
|
696
|
+
set_string_array_attr 'References', strs
|
697
|
+
end
|
698
|
+
|
699
|
+
#== MIME header methods
|
700
|
+
|
701
|
+
# Returns the listed MIME version of this email from the "Mime-Version:" header field
|
702
|
+
#
|
703
|
+
# If the mime_version field does not exist, returns nil by default or you can pass in as
|
704
|
+
# the parameter for what you want the default value to be.
|
705
|
+
#
|
706
|
+
# Example:
|
707
|
+
#
|
708
|
+
# mail = TMail::Mail.new
|
709
|
+
# mail.mime_version #=> nil
|
710
|
+
# mail.mime_version([]) #=> []
|
711
|
+
# mail = TMail::Mail.load("../test/fixtures/raw_email")
|
712
|
+
# mail.mime_version #=> "1.0"
|
713
|
+
def mime_version( default = nil )
|
714
|
+
if h = @header['mime-version']
|
715
|
+
h.version || default
|
716
|
+
else
|
717
|
+
default
|
718
|
+
end
|
719
|
+
end
|
720
|
+
|
721
|
+
def mime_version=( m, opt = nil )
|
722
|
+
if opt
|
723
|
+
if h = @header['mime-version']
|
724
|
+
h.major = m
|
725
|
+
h.minor = opt
|
726
|
+
else
|
727
|
+
store 'Mime-Version', "#{m}.#{opt}"
|
728
|
+
end
|
729
|
+
else
|
730
|
+
store 'Mime-Version', m
|
731
|
+
end
|
732
|
+
m
|
733
|
+
end
|
734
|
+
|
735
|
+
# Returns the current "Content-Type" of the mail instance.
|
736
|
+
#
|
737
|
+
# If the content_type field does not exist, returns nil by default or you can pass in as
|
738
|
+
# the parameter for what you want the default value to be.
|
739
|
+
#
|
740
|
+
# Example:
|
741
|
+
#
|
742
|
+
# mail = TMail::Mail.new
|
743
|
+
# mail.content_type #=> nil
|
744
|
+
# mail.content_type([]) #=> []
|
745
|
+
# mail = TMail::Mail.load("../test/fixtures/raw_email")
|
746
|
+
# mail.content_type #=> "text/plain"
|
747
|
+
def content_type( default = nil )
|
748
|
+
if h = @header['content-type']
|
749
|
+
h.content_type || default
|
750
|
+
else
|
751
|
+
default
|
752
|
+
end
|
753
|
+
end
|
754
|
+
|
755
|
+
# Returns the current main type of the "Content-Type" of the mail instance.
|
756
|
+
#
|
757
|
+
# If the content_type field does not exist, returns nil by default or you can pass in as
|
758
|
+
# the parameter for what you want the default value to be.
|
759
|
+
#
|
760
|
+
# Example:
|
761
|
+
#
|
762
|
+
# mail = TMail::Mail.new
|
763
|
+
# mail.main_type #=> nil
|
764
|
+
# mail.main_type([]) #=> []
|
765
|
+
# mail = TMail::Mail.load("../test/fixtures/raw_email")
|
766
|
+
# mail.main_type #=> "text"
|
767
|
+
def main_type( default = nil )
|
768
|
+
if h = @header['content-type']
|
769
|
+
h.main_type || default
|
770
|
+
else
|
771
|
+
default
|
772
|
+
end
|
773
|
+
end
|
774
|
+
|
775
|
+
# Returns the current sub type of the "Content-Type" of the mail instance.
|
776
|
+
#
|
777
|
+
# If the content_type field does not exist, returns nil by default or you can pass in as
|
778
|
+
# the parameter for what you want the default value to be.
|
779
|
+
#
|
780
|
+
# Example:
|
781
|
+
#
|
782
|
+
# mail = TMail::Mail.new
|
783
|
+
# mail.sub_type #=> nil
|
784
|
+
# mail.sub_type([]) #=> []
|
785
|
+
# mail = TMail::Mail.load("../test/fixtures/raw_email")
|
786
|
+
# mail.sub_type #=> "plain"
|
787
|
+
def sub_type( default = nil )
|
788
|
+
if h = @header['content-type']
|
789
|
+
h.sub_type || default
|
790
|
+
else
|
791
|
+
default
|
792
|
+
end
|
793
|
+
end
|
794
|
+
|
795
|
+
# Destructively sets the "Content-Type:" header field of this mail object
|
796
|
+
#
|
797
|
+
# Allows you to set the main type, sub type as well as parameters to the field.
|
798
|
+
# The main type and sub type need to be a string.
|
799
|
+
#
|
800
|
+
# The optional params hash can be passed with keys as symbols and values as a string,
|
801
|
+
# or strings as keys and values.
|
802
|
+
#
|
803
|
+
# Example:
|
804
|
+
#
|
805
|
+
# mail = TMail::Mail.new
|
806
|
+
# mail.set_content_type("text", "plain")
|
807
|
+
# mail.to_s #=> "Content-Type: text/plain\n\n"
|
808
|
+
#
|
809
|
+
# mail.set_content_type("text", "plain", {:charset => "EUC-KR", :format => "flowed"})
|
810
|
+
# mail.to_s #=> "Content-Type: text/plain; charset=EUC-KR; format=flowed\n\n"
|
811
|
+
#
|
812
|
+
# mail.set_content_type("text", "plain", {"charset" => "EUC-KR", "format" => "flowed"})
|
813
|
+
# mail.to_s #=> "Content-Type: text/plain; charset=EUC-KR; format=flowed\n\n"
|
814
|
+
def set_content_type( str, sub = nil, param = nil )
|
815
|
+
if sub
|
816
|
+
main, sub = str, sub
|
817
|
+
else
|
818
|
+
main, sub = str.split(%r</>, 2)
|
819
|
+
raise ArgumentError, "sub type missing: #{str.inspect}" unless sub
|
820
|
+
end
|
821
|
+
if h = @header['content-type']
|
822
|
+
h.main_type = main
|
823
|
+
h.sub_type = sub
|
824
|
+
h.params.clear
|
825
|
+
else
|
826
|
+
store 'Content-Type', "#{main}/#{sub}"
|
827
|
+
end
|
828
|
+
@header['content-type'].params.replace param if param
|
829
|
+
str
|
830
|
+
end
|
831
|
+
|
832
|
+
alias content_type= set_content_type
|
833
|
+
|
834
|
+
# Returns the named type parameter as a string, from the "Content-Type:" header.
|
835
|
+
#
|
836
|
+
# Example:
|
837
|
+
#
|
838
|
+
# mail = TMail::Mail.new
|
839
|
+
# mail.type_param("charset") #=> nil
|
840
|
+
# mail.type_param("charset", []) #=> []
|
841
|
+
# mail.set_content_type("text", "plain", {:charset => "EUC-KR", :format => "flowed"})
|
842
|
+
# mail.type_param("charset") #=> "EUC-KR"
|
843
|
+
# mail.type_param("format") #=> "flowed"
|
844
|
+
def type_param( name, default = nil )
|
845
|
+
if h = @header['content-type']
|
846
|
+
h[name] || default
|
847
|
+
else
|
848
|
+
default
|
849
|
+
end
|
850
|
+
end
|
851
|
+
|
852
|
+
# Returns the character set of the email. Returns nil if no encoding set or returns
|
853
|
+
# whatever default you pass as a parameter - note passing the parameter does NOT change
|
854
|
+
# the mail object in any way.
|
855
|
+
#
|
856
|
+
# Example:
|
857
|
+
#
|
858
|
+
# mail = TMail::Mail.load("path_to/utf8_email")
|
859
|
+
# mail.charset #=> "UTF-8"
|
860
|
+
#
|
861
|
+
# mail = TMail::Mail.new
|
862
|
+
# mail.charset #=> nil
|
863
|
+
# mail.charset("US-ASCII") #=> "US-ASCII"
|
864
|
+
def charset( default = nil )
|
865
|
+
if h = @header['content-type']
|
866
|
+
h['charset'] or default
|
867
|
+
else
|
868
|
+
mime_version_charset || default
|
869
|
+
end
|
870
|
+
end
|
871
|
+
|
872
|
+
# some weird emails come with the charset specified in the mime-version header:
|
873
|
+
#
|
874
|
+
# #<TMail::MimeVersionHeader "1.0\n charset=\"gb2312\"">
|
875
|
+
#
|
876
|
+
def mime_version_charset
|
877
|
+
if header['mime-version'].inspect =~ /charset=('|\\")?([^\\"']+)/
|
878
|
+
$2
|
879
|
+
end
|
880
|
+
end
|
881
|
+
|
882
|
+
# Destructively sets the character set used by this mail object to the passed string, you
|
883
|
+
# should note though that this does nothing to the mail body, just changes the header
|
884
|
+
# value, you will need to transliterate the body as well to match whatever you put
|
885
|
+
# in this header value if you are changing character sets.
|
886
|
+
#
|
887
|
+
# Example:
|
888
|
+
#
|
889
|
+
# mail = TMail::Mail.new
|
890
|
+
# mail.charset #=> nil
|
891
|
+
# mail.charset = "UTF-8"
|
892
|
+
# mail.charset #=> "UTF-8"
|
893
|
+
def charset=( str )
|
894
|
+
if str
|
895
|
+
if h = @header[ 'content-type' ]
|
896
|
+
h['charset'] = str
|
897
|
+
else
|
898
|
+
store 'Content-Type', "text/plain; charset=#{str}"
|
899
|
+
end
|
900
|
+
end
|
901
|
+
str
|
902
|
+
end
|
903
|
+
|
904
|
+
# Returns the transfer encoding of the email. Returns nil if no encoding set or returns
|
905
|
+
# whatever default you pass as a parameter - note passing the parameter does NOT change
|
906
|
+
# the mail object in any way.
|
907
|
+
#
|
908
|
+
# Example:
|
909
|
+
#
|
910
|
+
# mail = TMail::Mail.load("path_to/base64_encoded_email")
|
911
|
+
# mail.transfer_encoding #=> "base64"
|
912
|
+
#
|
913
|
+
# mail = TMail::Mail.new
|
914
|
+
# mail.transfer_encoding #=> nil
|
915
|
+
# mail.transfer_encoding("base64") #=> "base64"
|
916
|
+
def transfer_encoding( default = nil )
|
917
|
+
if h = @header['content-transfer-encoding']
|
918
|
+
h.encoding || default
|
919
|
+
else
|
920
|
+
default
|
921
|
+
end
|
922
|
+
end
|
923
|
+
|
924
|
+
# Destructively sets the transfer encoding of the mail object to the passed string, you
|
925
|
+
# should note though that this does nothing to the mail body, just changes the header
|
926
|
+
# value, you will need to encode or decode the body as well to match whatever you put
|
927
|
+
# in this header value.
|
928
|
+
#
|
929
|
+
# Example:
|
930
|
+
#
|
931
|
+
# mail = TMail::Mail.new
|
932
|
+
# mail.transfer_encoding #=> nil
|
933
|
+
# mail.transfer_encoding = "base64"
|
934
|
+
# mail.transfer_encoding #=> "base64"
|
935
|
+
def transfer_encoding=( str )
|
936
|
+
set_string_attr 'Content-Transfer-Encoding', str
|
937
|
+
end
|
938
|
+
|
939
|
+
alias encoding transfer_encoding
|
940
|
+
alias encoding= transfer_encoding=
|
941
|
+
alias content_transfer_encoding transfer_encoding
|
942
|
+
alias content_transfer_encoding= transfer_encoding=
|
943
|
+
|
944
|
+
# Returns the content-disposition of the mail object, returns nil or the passed
|
945
|
+
# default value if given
|
946
|
+
#
|
947
|
+
# Example:
|
948
|
+
#
|
949
|
+
# mail = TMail::Mail.load("path_to/raw_mail_with_attachment")
|
950
|
+
# mail.disposition #=> "attachment"
|
951
|
+
#
|
952
|
+
# mail = TMail::Mail.load("path_to/plain_simple_email")
|
953
|
+
# mail.disposition #=> nil
|
954
|
+
# mail.disposition(false) #=> false
|
955
|
+
def disposition( default = nil )
|
956
|
+
if h = @header['content-disposition']
|
957
|
+
h.disposition || default
|
958
|
+
else
|
959
|
+
default
|
960
|
+
end
|
961
|
+
end
|
962
|
+
|
963
|
+
alias content_disposition disposition
|
964
|
+
|
965
|
+
# Allows you to set the content-disposition of the mail object. Accepts a type
|
966
|
+
# and a hash of parameters.
|
967
|
+
#
|
968
|
+
# Example:
|
969
|
+
#
|
970
|
+
# mail.set_disposition("attachment", {:filename => "test.rb"})
|
971
|
+
# mail.disposition #=> "attachment"
|
972
|
+
# mail['content-disposition'].to_s #=> "attachment; filename=test.rb"
|
973
|
+
def set_disposition( str, params = nil )
|
974
|
+
if h = @header['content-disposition']
|
975
|
+
h.disposition = str
|
976
|
+
h.params.clear
|
977
|
+
else
|
978
|
+
store('Content-Disposition', str)
|
979
|
+
h = @header['content-disposition']
|
980
|
+
end
|
981
|
+
h.params.replace params if params
|
982
|
+
end
|
983
|
+
|
984
|
+
alias disposition= set_disposition
|
985
|
+
alias set_content_disposition set_disposition
|
986
|
+
alias content_disposition= set_disposition
|
987
|
+
|
988
|
+
# Returns the value of a parameter in an existing content-disposition header
|
989
|
+
#
|
990
|
+
# Example:
|
991
|
+
#
|
992
|
+
# mail.set_disposition("attachment", {:filename => "test.rb"})
|
993
|
+
# mail['content-disposition'].to_s #=> "attachment; filename=test.rb"
|
994
|
+
# mail.disposition_param("filename") #=> "test.rb"
|
995
|
+
# mail.disposition_param("missing_param_key") #=> nil
|
996
|
+
# mail.disposition_param("missing_param_key", false) #=> false
|
997
|
+
# mail.disposition_param("missing_param_key", "Nothing to see here") #=> "Nothing to see here"
|
998
|
+
def disposition_param( name, default = nil )
|
999
|
+
if h = @header['content-disposition']
|
1000
|
+
h[name] || default
|
1001
|
+
else
|
1002
|
+
default
|
1003
|
+
end
|
1004
|
+
end
|
1005
|
+
|
1006
|
+
# Convert the Mail object's body into a Base64 encoded email
|
1007
|
+
# returning the modified Mail object
|
1008
|
+
def base64_encode!
|
1009
|
+
store 'Content-Transfer-Encoding', 'Base64'
|
1010
|
+
self.body = base64_encode
|
1011
|
+
end
|
1012
|
+
|
1013
|
+
# Return the result of encoding the TMail::Mail object body
|
1014
|
+
# without altering the current body
|
1015
|
+
def base64_encode
|
1016
|
+
Base64.folding_encode(self.body)
|
1017
|
+
end
|
1018
|
+
|
1019
|
+
# Convert the Mail object's body into a Base64 decoded email
|
1020
|
+
# returning the modified Mail object
|
1021
|
+
def base64_decode!
|
1022
|
+
if /base64/i === self.transfer_encoding('')
|
1023
|
+
store 'Content-Transfer-Encoding', '8bit'
|
1024
|
+
self.body = base64_decode
|
1025
|
+
end
|
1026
|
+
end
|
1027
|
+
|
1028
|
+
# Returns the result of decoding the TMail::Mail object body
|
1029
|
+
# without altering the current body
|
1030
|
+
def base64_decode
|
1031
|
+
Base64.decode(self.body, @config.strict_base64decode?)
|
1032
|
+
end
|
1033
|
+
|
1034
|
+
# Returns an array of each destination in the email message including to: cc: or bcc:
|
1035
|
+
#
|
1036
|
+
# Example:
|
1037
|
+
#
|
1038
|
+
# mail.to = "Mikel <mikel@lindsaar.net>"
|
1039
|
+
# mail.cc = "Trans <t@t.com>"
|
1040
|
+
# mail.bcc = "bob <bob@me.com>"
|
1041
|
+
# mail.destinations #=> ["mikel@lindsaar.net", "t@t.com", "bob@me.com"]
|
1042
|
+
def destinations( default = nil )
|
1043
|
+
ret = []
|
1044
|
+
%w( to cc bcc ).each do |nm|
|
1045
|
+
if h = @header[nm]
|
1046
|
+
h.addrs.each {|i| ret.push i.address }
|
1047
|
+
end
|
1048
|
+
end
|
1049
|
+
ret.empty? ? default : ret
|
1050
|
+
end
|
1051
|
+
|
1052
|
+
# Yields a block of destination, yielding each as a string.
|
1053
|
+
# (from the destinations example)
|
1054
|
+
# mail.each_destination { |d| puts "#{d.class}: #{d}" }
|
1055
|
+
# String: mikel@lindsaar.net
|
1056
|
+
# String: t@t.com
|
1057
|
+
# String: bob@me.com
|
1058
|
+
def each_destination( &block )
|
1059
|
+
destinations([]).each do |i|
|
1060
|
+
if Address === i
|
1061
|
+
yield i
|
1062
|
+
else
|
1063
|
+
i.each(&block)
|
1064
|
+
end
|
1065
|
+
end
|
1066
|
+
end
|
1067
|
+
|
1068
|
+
alias each_dest each_destination
|
1069
|
+
|
1070
|
+
# Returns an array of reply to addresses that the Mail object has,
|
1071
|
+
# or if the Mail message has no reply-to, returns an array of the
|
1072
|
+
# Mail objects from addresses. Else returns the default which can
|
1073
|
+
# either be passed as a parameter or defaults to nil
|
1074
|
+
#
|
1075
|
+
# Example:
|
1076
|
+
# mail.from = "Mikel <mikel@lindsaar.net>"
|
1077
|
+
# mail.reply_to = nil
|
1078
|
+
# mail.reply_addresses #=> [""]
|
1079
|
+
#
|
1080
|
+
def reply_addresses( default = nil )
|
1081
|
+
reply_to_addrs(nil) or from_addrs(nil) or default
|
1082
|
+
end
|
1083
|
+
|
1084
|
+
# Returns the "sender" field as an array -> useful to find out who to
|
1085
|
+
# send an error email to.
|
1086
|
+
def error_reply_addresses( default = nil )
|
1087
|
+
if s = sender(nil)
|
1088
|
+
[s]
|
1089
|
+
else
|
1090
|
+
from_addrs(default)
|
1091
|
+
end
|
1092
|
+
end
|
1093
|
+
|
1094
|
+
# Returns true if the Mail object is a multipart message
|
1095
|
+
def multipart?
|
1096
|
+
main_type('').downcase == 'multipart'
|
1097
|
+
end
|
1098
|
+
|
1099
|
+
# Creates a new email in reply to self. Sets the In-Reply-To and
|
1100
|
+
# References headers for you automagically.
|
1101
|
+
#
|
1102
|
+
# Example:
|
1103
|
+
# mail = TMail::Mail.load("my_email")
|
1104
|
+
# reply_email = mail.create_reply
|
1105
|
+
# reply_email.class #=> TMail::Mail
|
1106
|
+
# reply_email.references #=> ["<d3b8cf8e49f04480850c28713a1f473e@lindsaar.net>"]
|
1107
|
+
# reply_email.in_reply_to #=> ["<d3b8cf8e49f04480850c28713a1f473e@lindsaar.net>"]
|
1108
|
+
def create_reply
|
1109
|
+
setup_reply create_empty_mail()
|
1110
|
+
end
|
1111
|
+
|
1112
|
+
# Creates a new email in reply to self. Sets the In-Reply-To and
|
1113
|
+
# References headers for you automagically.
|
1114
|
+
#
|
1115
|
+
# Example:
|
1116
|
+
# mail = TMail::Mail.load("my_email")
|
1117
|
+
# forward_email = mail.create_forward
|
1118
|
+
# forward_email.class #=> TMail::Mail
|
1119
|
+
# forward_email.content_type #=> "multipart/mixed"
|
1120
|
+
# forward_email.body #=> "Attachment: (unnamed)"
|
1121
|
+
# forward_email.encoded #=> Returns the original email as a MIME attachment
|
1122
|
+
def create_forward
|
1123
|
+
setup_forward create_empty_mail()
|
1124
|
+
end
|
1125
|
+
|
1126
|
+
#:stopdoc:
|
1127
|
+
private
|
1128
|
+
|
1129
|
+
def create_empty_mail
|
1130
|
+
self.class.new(StringPort.new(''), @config)
|
1131
|
+
end
|
1132
|
+
|
1133
|
+
def setup_reply( mail )
|
1134
|
+
if tmp = reply_addresses(nil)
|
1135
|
+
mail.to_addrs = tmp
|
1136
|
+
end
|
1137
|
+
|
1138
|
+
mid = message_id(nil)
|
1139
|
+
tmp = references(nil) || []
|
1140
|
+
tmp.push mid if mid
|
1141
|
+
mail.in_reply_to = [mid] if mid
|
1142
|
+
mail.references = tmp unless tmp.empty?
|
1143
|
+
mail.subject = 'Re: ' + subject('').sub(/\A(?:\[[^\]]+\])?(?:\s*Re:)*\s*/i, '')
|
1144
|
+
mail.mime_version = '1.0'
|
1145
|
+
mail
|
1146
|
+
end
|
1147
|
+
|
1148
|
+
def setup_forward( mail )
|
1149
|
+
m = Mail.new(StringPort.new(''))
|
1150
|
+
m.body = decoded
|
1151
|
+
m.set_content_type 'message', 'rfc822'
|
1152
|
+
m.encoding = encoding('7bit')
|
1153
|
+
mail.parts.push m
|
1154
|
+
# call encoded to reparse the message
|
1155
|
+
mail.encoded
|
1156
|
+
mail
|
1157
|
+
end
|
1158
|
+
|
1159
|
+
#:startdoc:
|
1160
|
+
end # class Mail
|
1161
|
+
|
1162
|
+
end # module TMail
|