65147228a12466cd1c6eb8b8d895c79757f59f0b
2 # Copyright (c) 1998-2003 Minero Aoki <aamine@loveruby.net>
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:
12 # The above copyright notice and this permission notice shall be
13 # included in all copies or substantial portions of the Software.
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.
23 # Note: Originally licensed under LGPL v2+. Using MIT license for Rails
24 # with permission of Minero Aoki.
41 def send_text_to( smtp
)
48 def do_send_to( smtp
)
49 from
= from_address
or raise ArgumentError
, 'no from address'
50 (dests
= destinations
).empty
? and raise ArgumentError
, 'no receipient'
52 send_to_0 smtp
, from
, dests
56 def send_to_0( smtp
, from
, to
)
57 smtp
.ready(from
, to
) do |f
|
58 encoded
"\r\n", 'j', f
, ''
73 def delete_no_send_fields
74 NOSEND_FIELDS
.each
do |nm
|
77 delete_if
{|n
,v
| v
.empty
? }
80 def add_message_id( fqdn
= nil )
81 self.message_id
= ::TMail::new_message_id(fqdn
)
90 mime_encode_singlepart
92 mime_encode_multipart
true
96 def mime_encode_singlepart
97 self.mime_version
= '1.0'
99 if NKF
.guess(b
) != NKF
::BINARY
106 def mime_encode_text( body
)
107 self.body
= NKF
.nkf('-j -m0', body
)
108 self.set_content_type
'text', 'plain', {'charset' => 'iso-2022-jp'}
109 self.encoding
= '7bit'
112 def mime_encode_binary( body
)
113 self.body
= [body
].pack('m')
114 self.set_content_type
'application', 'octet-stream'
115 self.encoding
= 'Base64'
118 def mime_encode_multipart( top
= true )
119 self.mime_version
= '1.0' if top
120 self.set_content_type
'multipart', 'mixed'
122 if e
and not /\A(?:7bit|8bit|binary)\z/i
=== e
124 'using C.T.Encoding with multipart mail is not permitted'
138 def initialize( nosend
= nil, delempty
= true )
139 @no_send_fields = nosend
|| NOSEND_FIELDS
.dup
140 @delete_empty_fields = delempty
144 attr
:delete_empty_fields, true
147 @no_send_fields.each
do |nm
|
150 delete_if
{|n
,v
| v
.empty
? } if @delete_empty_fields
159 def initialize( fqdn
= nil )
166 mail
.message_id
= ::TMail::new_msgid(@fqdn)
185 def initialize( s
= nil, m
= nil )
186 @singlepart_composer = s
|| MimeEncodeSingle
.new
187 @multipart_composer = m
|| MimeEncodeMulti
.new
190 attr
:singlepart_composer
191 attr
:multipart_composer
194 if mail
._builtin_multipart
?
195 then @multipart_composer
196 else @singlepart_composer end.exec mail
203 class MimeEncodeSingle
206 mail
.mime_version
= '1.0'
208 if NKF
.guess(b
) != NKF
::BINARY
216 mail
.body
= NKF
.nkf('-j -m0', body
)
217 mail
.set_content_type
'text', 'plain', {'charset' => 'iso-2022-jp'}
218 mail
.encoding
= '7bit'
221 def on_binary( body
)
222 mail
.body
= [body
].pack('m')
223 mail
.set_content_type
'application', 'octet-stream'
224 mail
.encoding
= 'Base64'
231 class MimeEncodeMulti
233 def exec( mail
, top
= true )
234 mail
.mime_version
= '1.0' if top
235 mail
.set_content_type
'multipart', 'mixed'
237 if e
and not /\A(?:7bit|8bit|binary)\z/i
=== e
239 'using C.T.Encoding with multipart mail is not permitted'
241 mail
.parts
.each
do |m
|
242 exec m
, false if m
._builtin_multipart
?