diff options
Diffstat (limited to 'actionmailer')
-rw-r--r-- | actionmailer/CHANGELOG | 4 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/vendor.rb | 4 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/interface.rb | 540 | ||||
-rwxr-xr-x | actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail.rb (renamed from actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail.rb) | 0 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/Makefile (renamed from actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/Makefile) | 0 | ||||
-rwxr-xr-x | actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/address.rb (renamed from actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/address.rb) | 0 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/attachments.rb (renamed from actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/attachments.rb) | 0 | ||||
-rwxr-xr-x | actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/base64.rb (renamed from actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/base64.rb) | 0 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/compat.rb (renamed from actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/compat.rb) | 0 | ||||
-rwxr-xr-x | actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/config.rb (renamed from actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/config.rb) | 0 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/core_extensions.rb (renamed from actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/core_extensions.rb) | 0 | ||||
-rwxr-xr-x | actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/encode.rb (renamed from actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/encode.rb) | 126 | ||||
-rwxr-xr-x | actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/facade.rb (renamed from actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/facade.rb) | 0 | ||||
-rwxr-xr-x | actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/header.rb (renamed from actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/header.rb) | 36 | ||||
-rwxr-xr-x | actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/info.rb (renamed from actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/info.rb) | 0 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/interface.rb | 1123 | ||||
-rwxr-xr-x | actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/loader.rb (renamed from actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/loader.rb) | 0 | ||||
-rwxr-xr-x | actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/mail.rb (renamed from actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/mail.rb) | 47 | ||||
-rwxr-xr-x | actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/mailbox.rb (renamed from actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/mailbox.rb) | 6 | ||||
-rwxr-xr-x | actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/mbox.rb (renamed from actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/mbox.rb) | 0 | ||||
-rwxr-xr-x | actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/net.rb (renamed from actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/net.rb) | 35 | ||||
-rwxr-xr-x | actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/obsolete.rb (renamed from actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/obsolete.rb) | 0 | ||||
-rwxr-xr-x | actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/parser.rb (renamed from actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/parser.rb) | 0 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/parser.y (renamed from actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/parser.y) | 0 | ||||
-rwxr-xr-x | actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/port.rb (renamed from actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/port.rb) | 0 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/quoting.rb (renamed from actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/quoting.rb) | 36 | ||||
-rwxr-xr-x | actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/scanner.rb (renamed from actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/scanner.rb) | 14 | ||||
-rwxr-xr-x | actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/scanner_r.rb (renamed from actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/scanner_r.rb) | 6 | ||||
-rwxr-xr-x | actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/stringio.rb (renamed from actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/stringio.rb) | 0 | ||||
-rwxr-xr-x | actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/tmail.rb (renamed from actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/tmail.rb) | 0 | ||||
-rwxr-xr-x | actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/utils.rb (renamed from actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/utils.rb) | 7 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/version.rb (renamed from actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/version.rb) | 4 | ||||
-rwxr-xr-x | actionmailer/test/mail_service_test.rb | 2 |
33 files changed, 1319 insertions, 671 deletions
diff --git a/actionmailer/CHANGELOG b/actionmailer/CHANGELOG index 892ec71ed1..ee48b25a81 100644 --- a/actionmailer/CHANGELOG +++ b/actionmailer/CHANGELOG @@ -2,6 +2,10 @@ * Fixed that you don't have to call super in ActionMailer::TestCase#setup #10406 [jamesgolick] +* Updated TMail to version 1.2.1 [raasdnil] + +* Fixed test in mail_service_test.rb => 'test_decode_encoded_attachment_filename' which had an incorrect decode value (should have spaces in the file after decode) [raasdnil] + *2.0.2* (December 16th, 2007) diff --git a/actionmailer/lib/action_mailer/vendor.rb b/actionmailer/lib/action_mailer/vendor.rb index 0ad7386fd8..e051be0901 100644 --- a/actionmailer/lib/action_mailer/vendor.rb +++ b/actionmailer/lib/action_mailer/vendor.rb @@ -2,9 +2,9 @@ require 'rubygems' begin - gem 'tmail', '~> 1.1.0' + gem 'tmail', '~> 1.2.1' rescue Gem::LoadError - $:.unshift "#{File.dirname(__FILE__)}/vendor/tmail-1.1.0" + $:.unshift "#{File.dirname(__FILE__)}/vendor/tmail-1.2.1" end begin diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/interface.rb b/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/interface.rb deleted file mode 100644 index 957e899734..0000000000 --- a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/interface.rb +++ /dev/null @@ -1,540 +0,0 @@ -=begin rdoc - -= Facade.rb Provides an interface to the TMail object - -=end -#-- -# Copyright (c) 1998-2003 Minero Aoki <aamine@loveruby.net> -# -# Permission is hereby granted, free of charge, to any person obtaining -# a copy of this software and associated documentation files (the -# "Software"), to deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, merge, publish, -# distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so, subject to -# the following conditions: -# -# The above copyright notice and this permission notice shall be -# included in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# -# Note: Originally licensed under LGPL v2+. Using MIT license for Rails -# with permission of Minero Aoki. -#++ - -require 'tmail/utils' - -module TMail - - class Mail - - def header_string( name, default = nil ) - h = @header[name.downcase] or return default - h.to_s - end - - ### - ### attributes - ### - - include TextUtils - - def set_string_array_attr( key, strs ) - strs.flatten! - if strs.empty? - @header.delete key.downcase - else - store key, strs.join(', ') - end - strs - end - private :set_string_array_attr - - def set_string_attr( key, str ) - if str - store key, str - else - @header.delete key.downcase - end - str - end - private :set_string_attr - - def set_addrfield( name, arg ) - if arg - h = HeaderField.internal_new(name, @config) - h.addrs.replace [arg].flatten - @header[name] = h - else - @header.delete name - end - arg - end - private :set_addrfield - - def addrs2specs( addrs ) - return nil unless addrs - list = addrs.map {|addr| - if addr.address_group? - then addr.map {|a| a.spec } - else addr.spec - end - }.flatten - return nil if list.empty? - list - end - private :addrs2specs - - # - # date time - # - - def date( default = nil ) - if h = @header['date'] - h.date - else - default - end - end - - def date=( time ) - if time - store 'Date', time2str(time) - else - @header.delete 'date' - end - time - end - - def strftime( fmt, default = nil ) - if t = date - t.strftime(fmt) - else - default - end - end - - # - # destination - # - - def to_addrs( default = nil ) - if h = @header['to'] - h.addrs - else - default - end - end - - def cc_addrs( default = nil ) - if h = @header['cc'] - h.addrs - else - default - end - end - - def bcc_addrs( default = nil ) - if h = @header['bcc'] - h.addrs - else - default - end - end - - def to_addrs=( arg ) - set_addrfield 'to', arg - end - - def cc_addrs=( arg ) - set_addrfield 'cc', arg - end - - def bcc_addrs=( arg ) - set_addrfield 'bcc', arg - end - - def to( default = nil ) - addrs2specs(to_addrs(nil)) || default - end - - def cc( default = nil ) - addrs2specs(cc_addrs(nil)) || default - end - - def bcc( default = nil ) - addrs2specs(bcc_addrs(nil)) || default - end - - def to=( *strs ) - set_string_array_attr 'To', strs - end - - def cc=( *strs ) - set_string_array_attr 'Cc', strs - end - - def bcc=( *strs ) - set_string_array_attr 'Bcc', strs - end - - # - # originator - # - - def from_addrs( default = nil ) - if h = @header['from'] - h.addrs - else - default - end - end - - def from_addrs=( arg ) - set_addrfield 'from', arg - end - - def from( default = nil ) - addrs2specs(from_addrs(nil)) || default - end - - def from=( *strs ) - set_string_array_attr 'From', strs - end - - def friendly_from( default = nil ) - h = @header['from'] - a, = h.addrs - return default unless a - return a.phrase if a.phrase - return h.comments.join(' ') unless h.comments.empty? - a.spec - end - - - def reply_to_addrs( default = nil ) - if h = @header['reply-to'] - h.addrs - else - default - end - end - - def reply_to_addrs=( arg ) - set_addrfield 'reply-to', arg - end - - def reply_to( default = nil ) - addrs2specs(reply_to_addrs(nil)) || default - end - - def reply_to=( *strs ) - set_string_array_attr 'Reply-To', strs - end - - - def sender_addr( default = nil ) - f = @header['sender'] or return default - f.addr or return default - end - - def sender_addr=( addr ) - if addr - h = HeaderField.internal_new('sender', @config) - h.addr = addr - @header['sender'] = h - else - @header.delete 'sender' - end - addr - end - - def sender( default ) - f = @header['sender'] or return default - a = f.addr or return default - a.spec - end - - def sender=( str ) - set_string_attr 'Sender', str - end - - - # - # subject - # - - def subject( default = nil ) - if h = @header['subject'] - h.body - else - default - end - end - alias quoted_subject subject - - def subject=( str ) - set_string_attr 'Subject', str - end - - # - # identity & threading - # - - def message_id( default = nil ) - if h = @header['message-id'] - h.id || default - else - default - end - end - - def message_id=( str ) - set_string_attr 'Message-Id', str - end - - def in_reply_to( default = nil ) - if h = @header['in-reply-to'] - h.ids - else - default - end - end - - def in_reply_to=( *idstrs ) - set_string_array_attr 'In-Reply-To', idstrs - end - - def references( default = nil ) - if h = @header['references'] - h.refs - else - default - end - end - - def references=( *strs ) - set_string_array_attr 'References', strs - end - - # - # MIME headers - # - - def mime_version( default = nil ) - if h = @header['mime-version'] - h.version || default - else - default - end - end - - def mime_version=( m, opt = nil ) - if opt - if h = @header['mime-version'] - h.major = m - h.minor = opt - else - store 'Mime-Version', "#{m}.#{opt}" - end - else - store 'Mime-Version', m - end - m - end - - def content_type( default = nil ) - if h = @header['content-type'] - h.content_type || default - else - default - end - end - - def main_type( default = nil ) - if h = @header['content-type'] - h.main_type || default - else - default - end - end - - def sub_type( default = nil ) - if h = @header['content-type'] - h.sub_type || default - else - default - end - end - - def set_content_type( str, sub = nil, param = nil ) - if sub - main, sub = str, sub - else - main, sub = str.split(%r</>, 2) - raise ArgumentError, "sub type missing: #{str.inspect}" unless sub - end - if h = @header['content-type'] - h.main_type = main - h.sub_type = sub - h.params.clear - else - store 'Content-Type', "#{main}/#{sub}" - end - @header['content-type'].params.replace param if param - str - end - - alias content_type= set_content_type - - def type_param( name, default = nil ) - if h = @header['content-type'] - h[name] || default - else - default - end - end - - def charset( default = nil ) - if h = @header['content-type'] - h['charset'] or default - else - default - end - end - - def charset=( str ) - if str - if h = @header[ 'content-type' ] - h['charset'] = str - else - store 'Content-Type', "text/plain; charset=#{str}" - end - end - str - end - - def transfer_encoding( default = nil ) - if h = @header['content-transfer-encoding'] - h.encoding || default - else - default - end - end - - def transfer_encoding=( str ) - set_string_attr 'Content-Transfer-Encoding', str - end - - alias encoding transfer_encoding - alias encoding= transfer_encoding= - alias content_transfer_encoding transfer_encoding - alias content_transfer_encoding= transfer_encoding= - - def disposition( default = nil ) - if h = @header['content-disposition'] - h.disposition || default - else - default - end - end - - alias content_disposition disposition - - def set_disposition( str, params = nil ) - if h = @header['content-disposition'] - h.disposition = str - h.params.clear - else - store('Content-Disposition', str) - h = @header['content-disposition'] - end - h.params.replace params if params - end - - alias disposition= set_disposition - alias set_content_disposition set_disposition - alias content_disposition= set_disposition - - def disposition_param( name, default = nil ) - if h = @header['content-disposition'] - h[name] || default - else - default - end - end - - ### - ### utils - ### - - def create_reply - mail = TMail::Mail.parse('') - mail.subject = 'Re: ' + subject('').sub(/\A(?:\[[^\]]+\])?(?:\s*Re:)*\s*/i, '') - mail.to_addrs = reply_addresses([]) - mail.in_reply_to = [message_id(nil)].compact - mail.references = references([]) + [message_id(nil)].compact - mail.mime_version = '1.0' - mail - end - - def base64_encode - store 'Content-Transfer-Encoding', 'Base64' - self.body = Base64.folding_encode(self.body) - end - - def base64_decode - if /base64/i === self.transfer_encoding('') - store 'Content-Transfer-Encoding', '8bit' - self.body = Base64.decode(self.body, @config.strict_base64decode?) - end - end - - def destinations( default = nil ) - ret = [] - %w( to cc bcc ).each do |nm| - if h = @header[nm] - h.addrs.each {|i| ret.push i.address } - end - end - ret.empty? ? default : ret - end - - def each_destination( &block ) - destinations([]).each do |i| - if Address === i - yield i - else - i.each(&block) - end - end - end - - alias each_dest each_destination - - def reply_addresses( default = nil ) - reply_to_addrs(nil) or from_addrs(nil) or default - end - - def error_reply_addresses( default = nil ) - if s = sender(nil) - [s] - else - from_addrs(default) - end - end - - def multipart? - main_type('').downcase == 'multipart' - end - - end # class Mail - -end # module TMail diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail.rb b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail.rb index 7de185019b..7de185019b 100755 --- a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail.rb diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/Makefile b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/Makefile index 346353b83f..346353b83f 100644 --- a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/Makefile +++ b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/Makefile diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/address.rb b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/address.rb index 224ed7090e..224ed7090e 100755 --- a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/address.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/address.rb diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/attachments.rb b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/attachments.rb index a8b8017cf9..a8b8017cf9 100644 --- a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/attachments.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/attachments.rb diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/base64.rb b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/base64.rb index e99b6b0ba2..e99b6b0ba2 100755 --- a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/base64.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/base64.rb diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/compat.rb b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/compat.rb index 9d2aa83798..9d2aa83798 100644 --- a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/compat.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/compat.rb diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/config.rb b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/config.rb index 4b253d2b2a..4b253d2b2a 100755 --- a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/config.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/config.rb diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/core_extensions.rb b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/core_extensions.rb index cc24e97778..cc24e97778 100644 --- a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/core_extensions.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/core_extensions.rb diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/encode.rb b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/encode.rb index 0721a25490..ba3a5fffcf 100755 --- a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/encode.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/encode.rb @@ -1,36 +1,35 @@ -=begin rdoc - -= Text Encoding class - -=end -#-- -# Copyright (c) 1998-2003 Minero Aoki <aamine@loveruby.net> +# = TITLE: +# +# Text Encoding class +# +# = COPYRIGHT: # -# Permission is hereby granted, free of charge, to any person obtaining -# a copy of this software and associated documentation files (the -# "Software"), to deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, merge, publish, -# distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so, subject to -# the following conditions: +# Copyright (c) 1998-2003 Minero Aoki <aamine@loveruby.net> # -# The above copyright notice and this permission notice shall be -# included in all copies or substantial portions of the Software. +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: # -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. # -# Note: Originally licensed under LGPL v2+. Using MIT license for Rails -# with permission of Minero Aoki. -#++ +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# Note: Originally licensed under LGPL v2+. Using MIT license for Rails +# with permission of Minero Aoki. require 'nkf' -require 'tmail/base64.rb' +require 'tmail/base64' require 'tmail/stringio' require 'tmail/utils' @@ -52,25 +51,25 @@ module TMail end end module_function :create_dest - + def encoded( eol = "\r\n", charset = 'j', dest = nil ) accept_strategy Encoder, eol, charset, dest end - + def decoded( eol = "\n", charset = 'e', dest = nil ) # Turn the E-Mail into a string and return it with all # encoded characters decoded. alias for to_s accept_strategy Decoder, eol, charset, dest end - + alias to_s decoded - + def accept_strategy( klass, eol, charset, dest = nil ) dest ||= '' accept klass.new( create_dest(dest), charset, eol ) dest end - + end @@ -121,7 +120,7 @@ module TMail def header_body( str ) @f << decode(str) end - + def space @f << ' ' end @@ -131,7 +130,7 @@ module TMail def lwsp( str ) @f << str end - + def meta( str ) @f << str end @@ -182,7 +181,8 @@ module TMail end SPACER = "\t" - MAX_LINE_LEN = 70 + MAX_LINE_LEN = 78 + RFC_2822_MAX_LENGTH = 998 OPTIONS = { 'EUC' => '-Ej -m0', @@ -202,7 +202,7 @@ module TMail def preserve_quotes=( bool ) @preserve_quotes end - + def preserve_quotes @preserve_quotes end @@ -378,7 +378,7 @@ module TMail i += 1 end end - + METHOD_ID = { ?j => :extract_J, ?e => :extract_E, @@ -451,31 +451,73 @@ module TMail # puts '---- lwsp -------------------------------------' # puts "+ #{lwsp.inspect}" fold if restsize() <= 0 - flush + flush(@folded) @lwsp = lwsp end - def flush + def flush(folded = false) # puts '---- flush ----' # puts "spc >>>#{@lwsp.inspect}<<<" # puts "txt >>>#{@text.inspect}<<<" @f << @lwsp << @text - @curlen += (@lwsp.size + @text.size) + if folded + @curlen = 0 + else + @curlen += (@lwsp.size + @text.size) + end @text = '' @lwsp = '' end def fold # puts '---- fold ----' - @f << @eol + unless @f.string =~ /^.*?:$/ + @f << @eol + @lwsp = SPACER + else + fold_header + @folded = true + end @curlen = 0 - @lwsp = SPACER + end + + def fold_header + # Called because line is too long - so we need to wrap. + # First look for whitespace in the text + # if it has text, fold there + # check the remaining text, if too long, fold again + # if it doesn't, then don't fold unless the line goes beyond 998 chars + + # Check the text to see if there is whitespace, or if not + @wrapped_text = [] + until @text == '' + fold_the_string + end + @text = @wrapped_text.join("#{@eol}#{SPACER}") + end + + def fold_the_string + whitespace_location = @text =~ /\s/ || @text.length + # Is the location of the whitespace shorter than the RCF_2822_MAX_LENGTH? + # if there is no whitespace in the string, then this + unless mazsize(whitespace_location) <= 0 + @wrapped_text << @text.slice!(0...whitespace_location) + # If it is not less, we have to wrap it destructively + else + slice_point = RFC_2822_MAX_LENGTH - @curlen - @lwsp.length + @wrapped_text << @text.slice!(0...slice_point) + end end def restsize MAX_LINE_LEN - (@curlen + @lwsp.size + @text.size) end + def mazsize(whitespace_location) + # Per RFC2822, the maximum length of a line is 998 chars + RFC_2822_MAX_LENGTH - (@curlen + @lwsp.size + whitespace_location) + end + end end # module TMail diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/facade.rb b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/facade.rb index 1ecd64bff8..1ecd64bff8 100755 --- a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/facade.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/facade.rb diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/header.rb b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/header.rb index 41c371f37f..31ad6fd612 100755 --- a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/header.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/header.rb @@ -54,8 +54,40 @@ module TMail klass.newobj body, conf end + # Returns a HeaderField object matching the header you specify in the "name" param. + # Requires an initialized TMail::Port to be passed in. + # + # The method searches the header of the Port you pass into it to find a match on + # the header line you pass. Once a match is found, it will unwrap the matching line + # as needed to return an initialized HeaderField object. + # + # If you want to get the Envelope sender of the email object, pass in "EnvelopeSender", + # if you want the From address of the email itself, pass in 'From'. + # + # This is because a mailbox doesn't have the : after the From that designates the + # beginning of the envelope sender (which can be different to the from address of + # the emial) + # + # Other fields can be passed as normal, "Reply-To", "Received" etc. + # + # Note: Change of behaviour in 1.2.1 => returns nil if it does not find the specified + # header field, otherwise returns an instantiated object of the correct header class + # + # For example: + # port = TMail::FilePort.new("/test/fixtures/raw_email_simple") + # h = TMail::HeaderField.new_from_port(port, "From") + # h.addrs.to_s #=> "Mikel Lindsaar <mikel@nowhere.com>" + # h = TMail::HeaderField.new_from_port(port, "EvelopeSender") + # h.addrs.to_s #=> "mike@anotherplace.com.au" + # h = TMail::HeaderField.new_from_port(port, "SomeWeirdHeaderField") + # h #=> nil def new_from_port( port, name, conf = DEFAULT_CONFIG ) - re = Regep.new('\A(' + Regexp.quote(name) + '):', 'i') + if name == "EnvelopeSender" + name = "From" + re = Regexp.new('\A(From) ', 'i') + else + re = Regexp.new('\A(' + Regexp.quote(name) + '):', 'i') + end str = nil port.ropen {|f| f.each do |line| @@ -66,7 +98,7 @@ module TMail end end } - new(name, str, Config.to_config(conf)) + new(name, str, Config.to_config(conf)) if str end def internal_new( name, conf ) diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/info.rb b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/info.rb index 5c115d5876..5c115d5876 100755 --- a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/info.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/info.rb diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/interface.rb b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/interface.rb new file mode 100644 index 0000000000..991c1b829e --- /dev/null +++ b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/interface.rb @@ -0,0 +1,1123 @@ +=begin rdoc + += interface.rb Provides an interface to the TMail object + +=end +#-- +# Copyright (c) 1998-2003 Minero Aoki <aamine@loveruby.net> +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# Note: Originally licensed under LGPL v2+. Using MIT license for Rails +# with permission of Minero Aoki. +#++ + +# TMail::Mail objects get accessed primarily through the methods in this file. +# +# + +require 'tmail/utils' + +module TMail + + class Mail + + # Allows you to query the mail object with a string to get the contents + # of the field you want. + # + # Returns a string of the exact contnts of the field + # + # mail.from = "mikel <mikel@lindsaar.net>" + # mail.header_string("From") #=> "mikel <mikel@lindsaar.net>" + def header_string( name, default = nil ) + h = @header[name.downcase] or return default + h.to_s + end + + #:stopdoc: + #-- + #== Attributes + + include TextUtils + + def set_string_array_attr( key, strs ) + strs.flatten! + if strs.empty? + @header.delete key.downcase + else + store key, strs.join(', ') + end + strs + end + private :set_string_array_attr + + def set_string_attr( key, str ) + if str + store key, str + else + @header.delete key.downcase + end + str + end + private :set_string_attr + + def set_addrfield( name, arg ) + if arg + h = HeaderField.internal_new(name, @config) + h.addrs.replace [arg].flatten + @header[name] = h + else + @header.delete name + end + arg + end + private :set_addrfield + + def addrs2specs( addrs ) + return nil unless addrs + list = addrs.map {|addr| + if addr.address_group? + then addr.map {|a| a.spec } + else addr.spec + end + }.flatten + return nil if list.empty? + list + end + private :addrs2specs + + #:startdoc: + + #== Date and Time methods + + # Returns the date of the email message as per the "date" header value or returns + # nil by default (if no date field exists). + # + # You can also pass whatever default you want into this method and it will return + # that instead of nil if there is no date already set. + def date( default = nil ) + if h = @header['date'] + h.date + else + default + end + end + + # Destructively sets the date of the mail object with the passed Time instance, + # returns a Time instance set to the date/time of the mail + # + # Example: + # + # now = Time.now + # mail.date = now + # mail.date #=> Sat Nov 03 18:47:50 +1100 2007 + # mail.date.class #=> Time + def date=( time ) + if time + store 'Date', time2str(time) + else + @header.delete 'date' + end + time + end + + # Returns the time of the mail message formatted to your taste using a + # strftime format string. If no date set returns nil by default or whatever value + # you pass as the second optional parameter. + # + # time = Time.now # (on Nov 16 2007) + # mail.date = time + # mail.strftime("%D") #=> "11/16/07" + def strftime( fmt, default = nil ) + if t = date + t.strftime(fmt) + else + default + end + end + + #== Destination methods + + # Return a TMail::Addresses instance for each entry in the "To:" field of the mail object header. + # + # If the "To:" field does not exist, will return nil by default or the value you + # pass as the optional parameter. + # + # Example: + # + # mail = TMail::Mail.new + # mail.to_addrs #=> nil + # mail.to_addrs([]) #=> [] + # mail.to = "Mikel <mikel@me.org>, another Mikel <mikel@you.org>" + # mail.to_addrs #=> [#<TMail::Address mikel@me.org>, #<TMail::Address mikel@you.org>] + def to_addrs( default = nil ) + if h = @header['to'] + h.addrs + else + default + end + end + + # Return a TMail::Addresses instance for each entry in the "Cc:" field of the mail object header. + # + # If the "Cc:" field does not exist, will return nil by default or the value you + # pass as the optional parameter. + # + # Example: + # + # mail = TMail::Mail.new + # mail.cc_addrs #=> nil + # mail.cc_addrs([]) #=> [] + # mail.cc = "Mikel <mikel@me.org>, another Mikel <mikel@you.org>" + # mail.cc_addrs #=> [#<TMail::Address mikel@me.org>, #<TMail::Address mikel@you.org>] + def cc_addrs( default = nil ) + if h = @header['cc'] + h.addrs + else + default + end + end + + # Return a TMail::Addresses instance for each entry in the "Bcc:" field of the mail object header. + # + # If the "Bcc:" field does not exist, will return nil by default or the value you + # pass as the optional parameter. + # + # Example: + # + # mail = TMail::Mail.new + # mail.bcc_addrs #=> nil + # mail.bcc_addrs([]) #=> [] + # mail.bcc = "Mikel <mikel@me.org>, another Mikel <mikel@you.org>" + # mail.bcc_addrs #=> [#<TMail::Address mikel@me.org>, #<TMail::Address mikel@you.org>] + def bcc_addrs( default = nil ) + if h = @header['bcc'] + h.addrs + else + default + end + end + + # Destructively set the to field of the "To:" header to equal the passed in string. + # + # TMail will parse your contents and turn each valid email address into a TMail::Address + # object before assigning it to the mail message. + # + # Example: + # + # mail = TMail::Mail.new + # mail.to = "Mikel <mikel@me.org>, another Mikel <mikel@you.org>" + # mail.to_addrs #=> [#<TMail::Address mikel@me.org>, #<TMail::Address mikel@you.org>] + def to_addrs=( arg ) + set_addrfield 'to', arg + end + + # Destructively set the to field of the "Cc:" header to equal the passed in string. + # + # TMail will parse your contents and turn each valid email address into a TMail::Address + # object before assigning it to the mail message. + # + # Example: + # + # mail = TMail::Mail.new + # mail.cc = "Mikel <mikel@me.org>, another Mikel <mikel@you.org>" + # mail.cc_addrs #=> [#<TMail::Address mikel@me.org>, #<TMail::Address mikel@you.org>] + def cc_addrs=( arg ) + set_addrfield 'cc', arg + end + + # Destructively set the to field of the "Bcc:" header to equal the passed in string. + # + # TMail will parse your contents and turn each valid email address into a TMail::Address + # object before assigning it to the mail message. + # + # Example: + # + # mail = TMail::Mail.new + # mail.bcc = "Mikel <mikel@me.org>, another Mikel <mikel@you.org>" + # mail.bcc_addrs #=> [#<TMail::Address mikel@me.org>, #<TMail::Address mikel@you.org>] + def bcc_addrs=( arg ) + set_addrfield 'bcc', arg + end + + # Returns who the email is to as an Array of email addresses as opposed to an Array of + # TMail::Address objects which is what Mail#to_addrs returns + # + # Example: + # + # mail = TMail::Mail.new + # mail.to = "Mikel <mikel@me.org>, another Mikel <mikel@you.org>" + # mail.to #=> ["mikel@me.org", "mikel@you.org"] + def to( default = nil ) + addrs2specs(to_addrs(nil)) || default + end + + # Returns who the email cc'd as an Array of email addresses as opposed to an Array of + # TMail::Address objects which is what Mail#to_addrs returns + # + # Example: + # + # mail = TMail::Mail.new + # mail.cc = "Mikel <mikel@me.org>, another Mikel <mikel@you.org>" + # mail.cc #=> ["mikel@me.org", "mikel@you.org"] + def cc( default = nil ) + addrs2specs(cc_addrs(nil)) || default + end + + # Returns who the email bcc'd as an Array of email addresses as opposed to an Array of + # TMail::Address objects which is what Mail#to_addrs returns + # + # Example: + # + # mail = TMail::Mail.new + # mail.bcc = "Mikel <mikel@me.org>, another Mikel <mikel@you.org>" + # mail.bcc #=> ["mikel@me.org", "mikel@you.org"] + def bcc( default = nil ) + addrs2specs(bcc_addrs(nil)) || default + end + + # Destructively sets the "To:" field to the passed array of strings (which should be valid + # email addresses) + # + # Example: + # + # mail = TMail::Mail.new + # mail.to = ["mikel@abc.com", "Mikel <mikel@xyz.com>"] + # mail.to #=> ["mikel@abc.org", "mikel@xyz.org"] + # mail['to'].to_s #=> "mikel@abc.com, Mikel <mikel@xyz.com>" + def to=( *strs ) + set_string_array_attr 'To', strs + end + + # Destructively sets the "Cc:" field to the passed array of strings (which should be valid + # email addresses) + # + # Example: + # + # mail = TMail::Mail.new + # mail.cc = ["mikel@abc.com", "Mikel <mikel@xyz.com>"] + # mail.cc #=> ["mikel@abc.org", "mikel@xyz.org"] + # mail['cc'].to_s #=> "mikel@abc.com, Mikel <mikel@xyz.com>" + def cc=( *strs ) + set_string_array_attr 'Cc', strs + end + + # Destructively sets the "Bcc:" field to the passed array of strings (which should be valid + # email addresses) + # + # Example: + # + # mail = TMail::Mail.new + # mail.bcc = ["mikel@abc.com", "Mikel <mikel@xyz.com>"] + # mail.bcc #=> ["mikel@abc.org", "mikel@xyz.org"] + # mail['bcc'].to_s #=> "mikel@abc.com, Mikel <mikel@xyz.com>" + def bcc=( *strs ) + set_string_array_attr 'Bcc', strs + end + + #== Originator methods + + # Return a TMail::Addresses instance for each entry in the "From:" field of the mail object header. + # + # If the "From:" field does not exist, will return nil by default or the value you + # pass as the optional parameter. + # + # Example: + # + # mail = TMail::Mail.new + # mail.from_addrs #=> nil + # mail.from_addrs([]) #=> [] + # mail.from = "Mikel <mikel@me.org>, another Mikel <mikel@you.org>" + # mail.from_addrs #=> [#<TMail::Address mikel@me.org>, #<TMail::Address mikel@you.org>] + def from_addrs( default = nil ) + if h = @header['from'] + h.addrs + else + default + end + end + + # Destructively set the to value of the "From:" header to equal the passed in string. + # + # TMail will parse your contents and turn each valid email address into a TMail::Address + # object before assigning it to the mail message. + # + # Example: + # + # mail = TMail::Mail.new + # mail.from_addrs = "Mikel <mikel@me.org>, another Mikel <mikel@you.org>" + # mail.from_addrs #=> [#<TMail::Address mikel@me.org>, #<TMail::Address mikel@you.org>] + def from_addrs=( arg ) + set_addrfield 'from', arg + end + + # Returns who the email is from as an Array of email address strings instead to an Array of + # TMail::Address objects which is what Mail#from_addrs returns + # + # Example: + # + # mail = TMail::Mail.new + # mail.from = "Mikel <mikel@me.org>, another Mikel <mikel@you.org>" + # mail.from #=> ["mikel@me.org", "mikel@you.org"] + def from( default = nil ) + addrs2specs(from_addrs(nil)) || default + end + + # Destructively sets the "From:" field to the passed array of strings (which should be valid + # email addresses) + # + # Example: + # + # mail = TMail::Mail.new + # mail.from = ["mikel@abc.com", "Mikel <mikel@xyz.com>"] + # mail.from #=> ["mikel@abc.org", "mikel@xyz.org"] + # mail['from'].to_s #=> "mikel@abc.com, Mikel <mikel@xyz.com>" + def from=( *strs ) + set_string_array_attr 'From', strs + end + + # Returns the "friendly" human readable part of the address + # + # Example: + # + # mail = TMail::Mail.new + # mail.from = "Mikel Lindsaar <mikel@abc.com>" + # mail.friendly_from #=> "Mikel Lindsaar" + def friendly_from( default = nil ) + h = @header['from'] + a, = h.addrs + return default unless a + return a.phrase if a.phrase + return h.comments.join(' ') unless h.comments.empty? + a.spec + end + + # Return a TMail::Addresses instance for each entry in the "Reply-To:" field of the mail object header. + # + # If the "Reply-To:" field does not exist, will return nil by default or the value you + # pass as the optional parameter. + # + # Example: + # + # mail = TMail::Mail.new + # mail.reply_to_addrs #=> nil + # mail.reply_to_addrs([]) #=> [] + # mail.reply_to = "Mikel <mikel@me.org>, another Mikel <mikel@you.org>" + # mail.reply_to_addrs #=> [#<TMail::Address mikel@me.org>, #<TMail::Address mikel@you.org>] + def reply_to_addrs( default = nil ) + if h = @header['reply-to'] + h.addrs.blank? ? default : h.addrs + else + default + end + end + + # Destructively set the to value of the "Reply-To:" header to equal the passed in argument. + # + # TMail will parse your contents and turn each valid email address into a TMail::Address + # object before assigning it to the mail message. + # + # Example: + # + # mail = TMail::Mail.new + # mail.reply_to_addrs = "Mikel <mikel@me.org>, another Mikel <mikel@you.org>" + # mail.reply_to_addrs #=> [#<TMail::Address mikel@me.org>, #<TMail::Address mikel@you.org>] + def reply_to_addrs=( arg ) + set_addrfield 'reply-to', arg + end + + # Returns who the email is from as an Array of email address strings instead to an Array of + # TMail::Address objects which is what Mail#reply_to_addrs returns + # + # Example: + # + # mail = TMail::Mail.new + # mail.reply_to = "Mikel <mikel@me.org>, another Mikel <mikel@you.org>" + # mail.reply_to #=> ["mikel@me.org", "mikel@you.org"] + def reply_to( default = nil ) + addrs2specs(reply_to_addrs(nil)) || default + end + + # Destructively sets the "Reply-To:" field to the passed array of strings (which should be valid + # email addresses) + # + # Example: + # + # mail = TMail::Mail.new + # mail.reply_to = ["mikel@abc.com", "Mikel <mikel@xyz.com>"] + # mail.reply_to #=> ["mikel@abc.org", "mikel@xyz.org"] + # mail['reply_to'].to_s #=> "mikel@abc.com, Mikel <mikel@xyz.com>" + def reply_to=( *strs ) + set_string_array_attr 'Reply-To', strs + end + + # Return a TMail::Addresses instance of the "Sender:" field of the mail object header. + # + # If the "Sender:" field does not exist, will return nil by default or the value you + # pass as the optional parameter. + # + # Example: + # + # mail = TMail::Mail.new + # mail.sender #=> nil + # mail.sender([]) #=> [] + # mail.sender = "Mikel <mikel@me.org>" + # mail.reply_to_addrs #=> [#<TMail::Address mikel@me.org>] + def sender_addr( default = nil ) + f = @header['sender'] or return default + f.addr or return default + end + + # Destructively set the to value of the "Sender:" header to equal the passed in argument. + # + # TMail will parse your contents and turn each valid email address into a TMail::Address + # object before assigning it to the mail message. + # + # Example: + # + # mail = TMail::Mail.new + # mail.sender_addrs = "Mikel <mikel@me.org>, another Mikel <mikel@you.org>" + # mail.sender_addrs #=> [#<TMail::Address mikel@me.org>, #<TMail::Address mikel@you.org>] + def sender_addr=( addr ) + if addr + h = HeaderField.internal_new('sender', @config) + h.addr = addr + @header['sender'] = h + else + @header.delete 'sender' + end + addr + end + + # Returns who the sender of this mail is as string instead to an Array of + # TMail::Address objects which is what Mail#sender_addr returns + # + # Example: + # + # mail = TMail::Mail.new + # mail.sender = "Mikel <mikel@me.org>" + # mail.sender #=> "mikel@me.org" + def sender( default = nil ) + f = @header['sender'] or return default + a = f.addr or return default + a.spec + end + + # Destructively sets the "Sender:" field to the passed string (which should be a valid + # email address) + # + # Example: + # + # mail = TMail::Mail.new + # mail.sender = "mikel@abc.com" + # mail.sender #=> "mikel@abc.org" + # mail['sender'].to_s #=> "mikel@abc.com" + def sender=( str ) + set_string_attr 'Sender', str + end + + #== Subject methods + + # Returns the subject of the mail instance. + # + # If the subject field does not exist, returns nil by default or you can pass in as + # the parameter for what you want the default value to be. + # + # Example: + # + # mail = TMail::Mail.new + # mail.subject #=> nil + # mail.subject("") #=> "" + # mail.subject = "Hello" + # mail.subject #=> "Hello" + def subject( default = nil ) + if h = @header['subject'] + h.body + else + default + end + end + alias quoted_subject subject + + # Destructively sets the passed string as the subject of the mail message. + # + # Example + # + # mail = TMail::Mail.new + # mail.subject #=> "This subject" + # mail.subject = "Another subject" + # mail.subject #=> "Another subject" + def subject=( str ) + set_string_attr 'Subject', str + end + + #== Message Identity & Threading Methods + + # Returns the message ID for this mail object instance. + # + # If the message_id field does not exist, returns nil by default or you can pass in as + # the parameter for what you want the default value to be. + # + # Example: + # + # mail = TMail::Mail.new + # mail.message_id #=> nil + # mail.message_id(TMail.new_message_id) #=> "<47404c5326d9c_2ad4fbb80161@baci.local.tmail>" + # mail.message_id = TMail.new_message_id + # mail.message_id #=> "<47404c5326d9c_2ad4fbb80161@baci.local.tmail>" + def message_id( default = nil ) + if h = @header['message-id'] + h.id || default + else + default + end + end + + # Destructively sets the message ID of the mail object instance to the passed in string + # + # Example: + # + # mail = TMail::Mail.new + # mail.message_id = "this_is_my_badly_formatted_message_id" + # mail.message_id #=> "this_is_my_badly_formatted_message_id" + def message_id=( str ) + set_string_attr 'Message-Id', str + end + + # Returns the "In-Reply-To:" field contents as an array of this mail instance if it exists + # + # If the in_reply_to field does not exist, returns nil by default or you can pass in as + # the parameter for what you want the default value to be. + # + # Example: + # + # mail = TMail::Mail.new + # mail.in_reply_to #=> nil + # mail.in_reply_to([]) #=> [] + # TMail::Mail.load("../test/fixtures/raw_email_reply") + # mail.in_reply_to #=> ["<348F04F142D69C21-291E56D292BC@xxxx.net>"] + def in_reply_to( default = nil ) + if h = @header['in-reply-to'] + h.ids + else + default + end + end + + # Destructively sets the value of the "In-Reply-To:" field of an email. + # + # Accepts an array of a single string of a message id + # + # Example: + # + # mail = TMail::Mail.new + # mail.in_reply_to = ["<348F04F142D69C21-291E56D292BC@xxxx.net>"] + # mail.in_reply_to #=> ["<348F04F142D69C21-291E56D292BC@xxxx.net>"] + def in_reply_to=( *idstrs ) + set_string_array_attr 'In-Reply-To', idstrs + end + + # Returns the references of this email (prior messages relating to this message) + # as an array of message ID strings. Useful when you are trying to thread an + # email. + # + # If the references field does not exist, returns nil by default or you can pass in as + # the parameter for what you want the default value to be. + # + # Example: + # + # mail = TMail::Mail.new + # mail.references #=> nil + # mail.references([]) #=> [] + # mail = TMail::Mail.load("../test/fixtures/raw_email_reply") + # mail.references #=> ["<473FF3B8.9020707@xxx.org>", "<348F04F142D69C21-291E56D292BC@xxxx.net>"] + def references( default = nil ) + if h = @header['references'] + h.refs + else + default + end + end + + # Destructively sets the value of the "References:" field of an email. + # + # Accepts an array of strings of message IDs + # + # Example: + # + # mail = TMail::Mail.new + # mail.references = ["<348F04F142D69C21-291E56D292BC@xxxx.net>"] + # mail.references #=> ["<348F04F142D69C21-291E56D292BC@xxxx.net>"] + def references=( *strs ) + set_string_array_attr 'References', strs + end + + #== MIME header methods + + # Returns the listed MIME version of this email from the "Mime-Version:" header field + # + # If the mime_version field does not exist, returns nil by default or you can pass in as + # the parameter for what you want the default value to be. + # + # Example: + # + # mail = TMail::Mail.new + # mail.mime_version #=> nil + # mail.mime_version([]) #=> [] + # mail = TMail::Mail.load("../test/fixtures/raw_email") + # mail.mime_version #=> "1.0" + def mime_version( default = nil ) + if h = @header['mime-version'] + h.version || default + else + default + end + end + + def mime_version=( m, opt = nil ) + if opt + if h = @header['mime-version'] + h.major = m + h.minor = opt + else + store 'Mime-Version', "#{m}.#{opt}" + end + else + store 'Mime-Version', m + end + m + end + + # Returns the current "Content-Type" of the mail instance. + # + # If the content_type field does not exist, returns nil by default or you can pass in as + # the parameter for what you want the default value to be. + # + # Example: + # + # mail = TMail::Mail.new + # mail.content_type #=> nil + # mail.content_type([]) #=> [] + # mail = TMail::Mail.load("../test/fixtures/raw_email") + # mail.content_type #=> "text/plain" + def content_type( default = nil ) + if h = @header['content-type'] + h.content_type || default + else + default + end + end + + # Returns the current main type of the "Content-Type" of the mail instance. + # + # If the content_type field does not exist, returns nil by default or you can pass in as + # the parameter for what you want the default value to be. + # + # Example: + # + # mail = TMail::Mail.new + # mail.main_type #=> nil + # mail.main_type([]) #=> [] + # mail = TMail::Mail.load("../test/fixtures/raw_email") + # mail.main_type #=> "text" + def main_type( default = nil ) + if h = @header['content-type'] + h.main_type || default + else + default + end + end + + # Returns the current sub type of the "Content-Type" of the mail instance. + # + # If the content_type field does not exist, returns nil by default or you can pass in as + # the parameter for what you want the default value to be. + # + # Example: + # + # mail = TMail::Mail.new + # mail.sub_type #=> nil + # mail.sub_type([]) #=> [] + # mail = TMail::Mail.load("../test/fixtures/raw_email") + # mail.sub_type #=> "plain" + def sub_type( default = nil ) + if h = @header['content-type'] + h.sub_type || default + else + default + end + end + + # Destructively sets the "Content-Type:" header field of this mail object + # + # Allows you to set the main type, sub type as well as parameters to the field. + # The main type and sub type need to be a string. + # + # The optional params hash can be passed with keys as symbols and values as a string, + # or strings as keys and values. + # + # Example: + # + # mail = TMail::Mail.new + # mail.set_content_type("text", "plain") + # mail.to_s #=> "Content-Type: text/plain\n\n" + # + # mail.set_content_type("text", "plain", {:charset => "EUC-KR", :format => "flowed"}) + # mail.to_s #=> "Content-Type: text/plain; charset=EUC-KR; format=flowed\n\n" + # + # mail.set_content_type("text", "plain", {"charset" => "EUC-KR", "format" => "flowed"}) + # mail.to_s #=> "Content-Type: text/plain; charset=EUC-KR; format=flowed\n\n" + def set_content_type( str, sub = nil, param = nil ) + if sub + main, sub = str, sub + else + main, sub = str.split(%r</>, 2) + raise ArgumentError, "sub type missing: #{str.inspect}" unless sub + end + if h = @header['content-type'] + h.main_type = main + h.sub_type = sub + h.params.clear + else + store 'Content-Type', "#{main}/#{sub}" + end + @header['content-type'].params.replace param if param + str + end + + alias content_type= set_content_type + + # Returns the named type parameter as a string, from the "Content-Type:" header. + # + # Example: + # + # mail = TMail::Mail.new + # mail.type_param("charset") #=> nil + # mail.type_param("charset", []) #=> [] + # mail.set_content_type("text", "plain", {:charset => "EUC-KR", :format => "flowed"}) + # mail.type_param("charset") #=> "EUC-KR" + # mail.type_param("format") #=> "flowed" + def type_param( name, default = nil ) + if h = @header['content-type'] + h[name] || default + else + default + end + end + + # Returns the character set of the email. Returns nil if no encoding set or returns + # whatever default you pass as a parameter - note passing the parameter does NOT change + # the mail object in any way. + # + # Example: + # + # mail = TMail::Mail.load("path_to/utf8_email") + # mail.charset #=> "UTF-8" + # + # mail = TMail::Mail.new + # mail.charset #=> nil + # mail.charset("US-ASCII") #=> "US-ASCII" + def charset( default = nil ) + if h = @header['content-type'] + h['charset'] or default + else + default + end + end + + # Destructively sets the character set used by this mail object to the passed string, you + # should note though that this does nothing to the mail body, just changes the header + # value, you will need to transliterate the body as well to match whatever you put + # in this header value if you are changing character sets. + # + # Example: + # + # mail = TMail::Mail.new + # mail.charset #=> nil + # mail.charset = "UTF-8" + # mail.charset #=> "UTF-8" + def charset=( str ) + if str + if h = @header[ 'content-type' ] + h['charset'] = str + else + store 'Content-Type', "text/plain; charset=#{str}" + end + end + str + end + + # Returns the transfer encoding of the email. Returns nil if no encoding set or returns + # whatever default you pass as a parameter - note passing the parameter does NOT change + # the mail object in any way. + # + # Example: + # + # mail = TMail::Mail.load("path_to/base64_encoded_email") + # mail.transfer_encoding #=> "base64" + # + # mail = TMail::Mail.new + # mail.transfer_encoding #=> nil + # mail.transfer_encoding("base64") #=> "base64" + def transfer_encoding( default = nil ) + if h = @header['content-transfer-encoding'] + h.encoding || default + else + default + end + end + + # Destructively sets the transfer encoding of the mail object to the passed string, you + # should note though that this does nothing to the mail body, just changes the header + # value, you will need to encode or decode the body as well to match whatever you put + # in this header value. + # + # Example: + # + # mail = TMail::Mail.new + # mail.transfer_encoding #=> nil + # mail.transfer_encoding = "base64" + # mail.transfer_encoding #=> "base64" + def transfer_encoding=( str ) + set_string_attr 'Content-Transfer-Encoding', str + end + + alias encoding transfer_encoding + alias encoding= transfer_encoding= + alias content_transfer_encoding transfer_encoding + alias content_transfer_encoding= transfer_encoding= + + # Returns the content-disposition of the mail object, returns nil or the passed + # default value if given + # + # Example: + # + # mail = TMail::Mail.load("path_to/raw_mail_with_attachment") + # mail.disposition #=> "attachment" + # + # mail = TMail::Mail.load("path_to/plain_simple_email") + # mail.disposition #=> nil + # mail.disposition(false) #=> false + def disposition( default = nil ) + if h = @header['content-disposition'] + h.disposition || default + else + default + end + end + + alias content_disposition disposition + + # Allows you to set the content-disposition of the mail object. Accepts a type + # and a hash of parameters. + # + # Example: + # + # mail.set_disposition("attachment", {:filename => "test.rb"}) + # mail.disposition #=> "attachment" + # mail['content-disposition'].to_s #=> "attachment; filename=test.rb" + def set_disposition( str, params = nil ) + if h = @header['content-disposition'] + h.disposition = str + h.params.clear + else + store('Content-Disposition', str) + h = @header['content-disposition'] + end + h.params.replace params if params + end + + alias disposition= set_disposition + alias set_content_disposition set_disposition + alias content_disposition= set_disposition + + # Returns the value of a parameter in an existing content-disposition header + # + # Example: + # + # mail.set_disposition("attachment", {:filename => "test.rb"}) + # mail['content-disposition'].to_s #=> "attachment; filename=test.rb" + # mail.disposition_param("filename") #=> "test.rb" + # mail.disposition_param("missing_param_key") #=> nil + # mail.disposition_param("missing_param_key", false) #=> false + # mail.disposition_param("missing_param_key", "Nothing to see here") #=> "Nothing to see here" + def disposition_param( name, default = nil ) + if h = @header['content-disposition'] + h[name] || default + else + default + end + end + + # Destructively convert the Mail object's body into a Base64 encoded email + # returning the modified Mail object + def base64_encode! + store 'Content-Transfer-Encoding', 'Base64' + self.body = Base64.folding_encode(self.body) + end + + # ==Depreciation warning + # base64_encode will return the body encoded, not modify the message body in + # future versions of TMail + alias :base64_encode :base64_encode! + + # Destructively convert the Mail object's body into a Base64 decoded email + # returning the modified Mail object + def base64_decode! + if /base64/i === self.transfer_encoding('') + store 'Content-Transfer-Encoding', '8bit' + self.body = Base64.decode(self.body, @config.strict_base64decode?) + end + end + + # ==Depreciation warning + # base64_decode will return the body decoded, not modify the message body in + # future versions of TMail + alias :base64_decode :base64_decode! + + # Returns an array of each destination in the email message including to: cc: or bcc: + # + # Example: + # + # mail.to = "Mikel <mikel@lindsaar.net>" + # mail.cc = "Trans <t@t.com>" + # mail.bcc = "bob <bob@me.com>" + # mail.destinations #=> ["mikel@lindsaar.net", "t@t.com", "bob@me.com"] + def destinations( default = nil ) + ret = [] + %w( to cc bcc ).each do |nm| + if h = @header[nm] + h.addrs.each {|i| ret.push i.address } + end + end + ret.empty? ? default : ret + end + + # Yields a block of destination, yielding each as a string. + # (from the destinations example) + # mail.each_destination { |d| puts "#{d.class}: #{d}" } + # String: mikel@lindsaar.net + # String: t@t.com + # String: bob@me.com + def each_destination( &block ) + destinations([]).each do |i| + if Address === i + yield i + else + i.each(&block) + end + end + end + + alias each_dest each_destination + + # Returns an array of reply to addresses that the Mail object has, + # or if the Mail message has no reply-to, returns an array of the + # Mail objects from addresses. Else returns the default which can + # either be passed as a parameter or defaults to nil + # + # Example: + # mail.from = "Mikel <mikel@lindsaar.net>" + # mail.reply_to = nil + # mail.reply_addresses #=> [""] + # + def reply_addresses( default = nil ) + reply_to_addrs(nil) or from_addrs(nil) or default + end + + # Returns the "sender" field as an array -> useful to find out who to + # send an error email to. + def error_reply_addresses( default = nil ) + if s = sender(nil) + [s] + else + from_addrs(default) + end + end + + # Returns true if the Mail object is a multipart message + def multipart? + main_type('').downcase == 'multipart' + end + + # Creates a new email in reply to self. Sets the In-Reply-To and + # References headers for you automagically. + # + # Example: + # mail = TMail::Mail.load("my_email") + # reply_email = mail.create_reply + # reply_email.class #=> TMail::Mail + # reply_email.references #=> ["<d3b8cf8e49f04480850c28713a1f473e@lindsaar.net>"] + # reply_email.in_reply_to #=> ["<d3b8cf8e49f04480850c28713a1f473e@lindsaar.net>"] + def create_reply + setup_reply create_empty_mail() + end + + # Creates a new email in reply to self. Sets the In-Reply-To and + # References headers for you automagically. + # + # Example: + # mail = TMail::Mail.load("my_email") + # forward_email = mail.create_forward + # forward_email.class #=> TMail::Mail + # forward_email.content_type #=> "multipart/mixed" + # forward_email.body #=> "Attachment: (unnamed)" + # forward_email.encoded #=> Returns the original email as a MIME attachment + def create_forward + setup_forward create_empty_mail() + end + + #:stopdoc: + private + + def create_empty_mail + self.class.new(StringPort.new(''), @config) + end + + def setup_reply( mail ) + if tmp = reply_addresses(nil) + mail.to_addrs = tmp + end + + mid = message_id(nil) + tmp = references(nil) || [] + tmp.push mid if mid + mail.in_reply_to = [mid] if mid + mail.references = tmp unless tmp.empty? + mail.subject = 'Re: ' + subject('').sub(/\A(?:\[[^\]]+\])?(?:\s*Re:)*\s*/i, '') + mail.mime_version = '1.0' + mail + end + + def setup_forward( mail ) + m = Mail.new(StringPort.new('')) + m.body = decoded + m.set_content_type 'message', 'rfc822' + m.encoding = encoding('7bit') + mail.parts.push m + # call encoded to reparse the message + mail.encoded + mail + end + + #:startdoc: + end # class Mail + +end # module TMail diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/loader.rb b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/loader.rb index 7907315401..7907315401 100755 --- a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/loader.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/loader.rb diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/mail.rb b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/mail.rb index d10275b734..252c91846f 100755 --- a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/mail.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/mail.rb @@ -28,6 +28,23 @@ # Note: Originally licensed under LGPL v2+. Using MIT license for Rails # with permission of Minero Aoki. #++ +# == TMail::Mail +# === Class Methods +# +# +# +# +# +# +# +# +# +# +# +# +# +# + require 'tmail/interface' require 'tmail/encode' @@ -162,6 +179,14 @@ module TMail @header.dup end + # Returns a TMail::AddressHeader object of the field you are querying. + # Examples: + # @mail['from'] #=> #<TMail::AddressHeader "mikel@test.com.au"> + # @mail['to'] #=> #<TMail::AddressHeader "mikel@test.com.au"> + # + # You can get the string value of this by passing "to_s" to the query: + # Example: + # @mail['to'].to_s #=> "mikel@test.com.au" def []( key ) @header[key.downcase] end @@ -172,6 +197,19 @@ module TMail alias fetch [] + # Allows you to set or delete TMail header objects at will. + # Eamples: + # @mail = TMail::Mail.new + # @mail['to'].to_s # => 'mikel@test.com.au' + # @mail['to'] = 'mikel@elsewhere.org' + # @mail['to'].to_s # => 'mikel@elsewhere.org' + # @mail.encoded # => "To: mikel@elsewhere.org\r\n\r\n" + # @mail['to'] = nil + # @mail['to'].to_s # => nil + # @mail.encoded # => "\r\n" + # + # Note: setting mail[] = nil actualy deletes the header field in question from the object, + # it does not just set the value of the hash to nil def []=( key, val ) dkey = key.downcase @@ -203,7 +241,14 @@ module TMail end alias store []= - + + # Allows you to loop through each header in the TMail::Mail object in a block + # Example: + # @mail['to'] = 'mikel@elsewhere.org' + # @mail['from'] = 'me@me.com' + # @mail.each_header { |k,v| puts "#{k} = #{v}" } + # # => from = me@me.com + # # => to = mikel@elsewhere.org def each_header @header.each do |key, val| [val].flatten.each {|v| yield key, v } diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/mailbox.rb b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/mailbox.rb index bb7a460e1a..8dd51059e7 100755 --- a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/mailbox.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/mailbox.rb @@ -213,13 +213,13 @@ module TMail fromaddr(), TextUtils.time2str(File.mtime(port.filename)) end - def UNIXMbox.fromaddr + def UNIXMbox.fromaddr(port) h = HeaderField.new_from_port(port, 'Return-Path') || - HeaderField.new_from_port(port, 'From') or return 'nobody' + HeaderField.new_from_port(port, 'From') || + HeaderField.new_from_port(port, 'EnvelopeSender') or return 'nobody' a = h.addrs[0] or return 'nobody' a.spec end - private_class_method :fromaddr def close return if @closed diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/mbox.rb b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/mbox.rb index 7907315401..7907315401 100755 --- a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/mbox.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/mbox.rb diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/net.rb b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/net.rb index 50b1dd95be..df524975d6 100755 --- a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/net.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/net.rb @@ -128,41 +128,6 @@ module TMail 'using C.T.Encoding with multipart mail is not permitted' end end - - def create_empty_mail - self.class.new(StringPort.new(''), @config) - end - - def create_reply - setup_reply create_empty_mail() - end - - def setup_reply( m ) - if tmp = reply_addresses(nil) - m.to_addrs = tmp - end - - mid = message_id(nil) - tmp = references(nil) || [] - tmp.push mid if mid - m.in_reply_to = [mid] if mid - m.references = tmp unless tmp.empty? - m.subject = 'Re: ' + subject('').sub(/\A(?:\s*re:)+/i, '') - - m - end - - def create_forward - setup_forward create_empty_mail() - end - - def setup_forward( mail ) - m = Mail.new(StringPort.new('')) - m.body = decoded - m.set_content_type 'message', 'rfc822' - m.encoding = encoding('7bit') - mail.parts.push m - end end diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/obsolete.rb b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/obsolete.rb index b871510b82..b871510b82 100755 --- a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/obsolete.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/obsolete.rb diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/parser.rb b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/parser.rb index 5deb0ff655..5deb0ff655 100755 --- a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/parser.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/parser.rb diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/parser.y b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/parser.y index 77a1457794..77a1457794 100644 --- a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/parser.y +++ b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/parser.y diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/port.rb b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/port.rb index 445f0e632b..445f0e632b 100755 --- a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/port.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/port.rb diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/quoting.rb b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/quoting.rb index 0b2d11c3f0..cb9f4288f1 100644 --- a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/quoting.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/quoting.rb @@ -13,12 +13,12 @@ module TMail from_charset = sub_header("content-type", "charset") case (content_transfer_encoding || "7bit").downcase when "quoted-printable" - # the default charset is set to iso-8859-1 instead of 'us-ascii'. + # the default charset is set to iso-8859-1 instead of 'us-ascii'. # This is needed as many mailer do not set the charset but send in ISO. This is only used if no charset is set. if !from_charset.blank? && from_charset.downcase == 'us-ascii' from_charset = 'iso-8859-1' end - + Unquoter.unquote_quoted_printable_and_convert_to(quoted_body, to_charset, from_charset, true) when "base64" @@ -35,9 +35,9 @@ module TMail def body(to_charset = 'utf-8', &block) attachment_presenter = block || Proc.new { |file_name| "Attachment: #{file_name}\n" } - + if multipart? - parts.collect { |part| + parts.collect { |part| header = part["content-type"] if part.multipart? @@ -81,13 +81,13 @@ module TMail end end end - + def unquote_quoted_printable_and_convert_to(text, to, from, preserve_underscores=false) text = text.gsub(/_/, " ") unless preserve_underscores text = text.gsub(/\r\n|\r/, "\n") # normalize newlines convert_to(text.unpack("M*").first, to, from) end - + def unquote_base64_and_convert_to(text, to, from) convert_to(Base64.decode(text), to, from) end @@ -116,27 +116,3 @@ module TMail end end end - -if __FILE__ == $0 - require 'test/unit' - - class TC_Unquoter < Test::Unit::TestCase - def test_unquote_quoted_printable - a ="=?ISO-8859-1?Q?[166417]_Bekr=E6ftelse_fra_Rejsefeber?=" - b = TMail::Unquoter.unquote_and_convert_to(a, 'utf-8') - assert_equal "[166417] Bekr\303\246ftelse fra Rejsefeber", b - end - - def test_unquote_base64 - a ="=?ISO-8859-1?B?WzE2NjQxN10gQmVrcuZmdGVsc2UgZnJhIFJlanNlZmViZXI=?=" - b = TMail::Unquoter.unquote_and_convert_to(a, 'utf-8') - assert_equal "[166417] Bekr\303\246ftelse fra Rejsefeber", b - end - - def test_unquote_without_charset - a ="[166417]_Bekr=E6ftelse_fra_Rejsefeber" - b = TMail::Unquoter.unquote_and_convert_to(a, 'utf-8') - assert_equal "[166417]_Bekr=E6ftelse_fra_Rejsefeber", b - end - end -end diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/scanner.rb b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/scanner.rb index 9216b430fa..15cc3c4977 100755 --- a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/scanner.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/scanner.rb @@ -30,14 +30,18 @@ #++ require 'tmail/utils' +require 'tmail/config' module TMail - require 'tmail/scanner_r.rb' + # NOTE: It woiuld be nice if these two libs could boith be called "tmailscanner", and + # the native extension would have precedence. However RubyGems boffs that up b/c + # it does not gaurantee load_path order. begin - raise LoadError, 'Turn off Ruby extention by user choice' if ENV['NORUBYEXT'] - require 'tmail/scanner_c.so' - Scanner = Scanner_C + raise LoadError, 'Turned off native extentions by user choice' if ENV['NORUBYEXT'] + require('tmail/tmailscanner') # c extension + Scanner = TMailScanner rescue LoadError - Scanner = Scanner_R + require 'tmail/scanner_r' + Scanner = TMailScanner end end diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/scanner_r.rb b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/scanner_r.rb index d9169c53f4..cc10a0c7db 100755 --- a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/scanner_r.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/scanner_r.rb @@ -29,12 +29,11 @@ require 'tmail/config' - module TMail - class Scanner_R + class TMailScanner - Version = '0.10.7' + Version = '0.11.0' Version.freeze MIME_HEADERS = { @@ -46,7 +45,6 @@ module TMail alnum = 'a-zA-Z0-9' atomsyms = %q[ _#!$%&`'*+-{|}~^/=? ].strip tokensyms = %q[ _#!$%&`'*+-{|}~^@. ].strip - atomchars = alnum + Regexp.quote(atomsyms) tokenchars = alnum + Regexp.quote(tokensyms) iso2022str = '\e(?!\(B)..(?:[^\e]+|\e(?!\(B)..)*\e\(B' diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/stringio.rb b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/stringio.rb index 3817850f63..3817850f63 100755 --- a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/stringio.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/stringio.rb diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/tmail.rb b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/tmail.rb index 57ed3cc581..57ed3cc581 100755 --- a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/tmail.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/tmail.rb diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/utils.rb b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/utils.rb index 016330ffd5..9e6af8ee02 100755 --- a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/utils.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/utils.rb @@ -56,7 +56,7 @@ module TMail module TextUtils # Defines characters per RFC that are OK for TOKENs, ATOMs, PHRASEs and CONTROL characters. - + aspecial = '()<>[]:;.\\,"' tspecial = '()<>[];:\\,"/?=' lwsp = " \t\r\n" @@ -248,8 +248,7 @@ module TMail def decode_RFC2231( str ) m = RFC2231_ENCODED.match(str) or return str begin - NKF.nkf(NKF_FLAGS[$KCODE], - m.post_match.gsub(/%[\da-f]{2}/in) {|s| s[1,2].hex.chr }) + to_kcode(m.post_match.gsub(/%[\da-f]{2}/in) {|s| s[1,2].hex.chr }) rescue m.post_match.gsub(/%[\da-f]{2}/in, "") end @@ -263,7 +262,7 @@ module TMail preamble = $1 remainder = $2 if remainder =~ /;/ - remainder =~ /^(.*)(;.*)$/m + remainder =~ /^(.*?)(;.*)$/m boundary_text = $1 post = $2.chomp else diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/version.rb b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/version.rb index 14df4b06eb..c618a729e4 100644 --- a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/version.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/version.rb @@ -30,8 +30,8 @@ module TMail #:nodoc: module VERSION #:nodoc: MAJOR = 1 - MINOR = 1 - TINY = 1 + MINOR = 2 + TINY = 0 STRING = [MAJOR, MINOR, TINY].join('.') end diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb index b90035f5f9..73a6f0f6d5 100755 --- a/actionmailer/test/mail_service_test.rb +++ b/actionmailer/test/mail_service_test.rb @@ -838,7 +838,7 @@ EOF fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email8") mail = TMail::Mail.parse(fixture) attachment = mail.attachments.last - assert_equal "01QuienTeDijat.Pitbull.mp3", attachment.original_filename + assert_equal "01 Quien Te Dij\212at. Pitbull.mp3", attachment.original_filename end def test_wrong_mail_header |