Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8620

Show
Ignore:
Timestamp:
01/11/08 01:55:20 (1 year ago)
Author:
rick
Message:

Updated TMail to version 1.2.1 [raasdnil]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionmailer/CHANGELOG

    r8536 r8620  
    22 
    33* Fixed that you don't have to call super in ActionMailer::TestCase#setup #10406 [jamesgolick] 
     4 
     5* Updated TMail to version 1.2.1 [raasdnil] 
     6 
     7* 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] 
    48 
    59 
  • trunk/actionmailer/lib/action_mailer/vendor.rb

    r8112 r8620  
    33 
    44begin 
    5   gem 'tmail', '~> 1.1.0
     5  gem 'tmail', '~> 1.2.1
    66rescue Gem::LoadError 
    7   $:.unshift "#{File.dirname(__FILE__)}/vendor/tmail-1.1.0
     7  $:.unshift "#{File.dirname(__FILE__)}/vendor/tmail-1.2.1
    88end 
    99 
  • trunk/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/encode.rb

    r8084 r8620  
    1 =begin rdoc 
    2  
    3 = Text Encoding class 
    4  
    5 =end 
    6 #-- 
    7 # Copyright (c) 1998-2003 Minero Aoki <aamine@loveruby.net> 
    8 
    9 # Permission is hereby granted, free of charge, to any person obtaining 
    10 # a copy of this software and associated documentation files (the 
    11 # "Software"), to deal in the Software without restriction, including 
    12 # without limitation the rights to use, copy, modify, merge, publish, 
    13 # distribute, sublicense, and/or sell copies of the Software, and to 
    14 # permit persons to whom the Software is furnished to do so, subject to 
    15 # the following conditions: 
    16 
    17 # The above copyright notice and this permission notice shall be 
    18 # included in all copies or substantial portions of the Software. 
    19 
    20 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
    21 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
    22 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
    23 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
    24 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
    25 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
    26 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
    27 
    28 # Note: Originally licensed under LGPL v2+. Using MIT license for Rails 
    29 # with permission of Minero Aoki. 
    30 #++ 
     1# = TITLE: 
     2
     3#   Text Encoding class 
     4
     5# = COPYRIGHT: 
     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. 
    3130 
    3231require 'nkf' 
    33 require 'tmail/base64.rb
     32require 'tmail/base64
    3433require 'tmail/stringio' 
    3534require 'tmail/utils' 
     
    5352    end 
    5453    module_function :create_dest 
    55      
     54 
    5655    def encoded( eol = "\r\n", charset = 'j', dest = nil ) 
    5756      accept_strategy Encoder, eol, charset, dest 
    5857    end 
    59      
     58 
    6059    def decoded( eol = "\n", charset = 'e', dest = nil ) 
    6160      # Turn the E-Mail into a string and return it with all 
     
    6362      accept_strategy Decoder, eol, charset, dest 
    6463    end 
    65      
     64 
    6665    alias to_s decoded 
    67      
     66 
    6867    def accept_strategy( klass, eol, charset, dest = nil ) 
    6968      dest ||= '' 
     
    7170      dest 
    7271    end 
    73      
     72 
    7473  end 
    7574 
     
    122121      @f << decode(str) 
    123122    end 
    124        
     123 
    125124    def space 
    126125      @f << ' ' 
     
    132131      @f << str 
    133132    end 
    134        
     133 
    135134    def meta( str ) 
    136135      @f << str 
     
    183182 
    184183    SPACER       = "\t" 
    185     MAX_LINE_LEN = 70 
     184    MAX_LINE_LEN = 78 
     185    RFC_2822_MAX_LENGTH = 998 
    186186 
    187187    OPTIONS = { 
     
    203203      @preserve_quotes 
    204204    end 
    205      
     205 
    206206    def preserve_quotes 
    207207      @preserve_quotes 
     
    379379      end 
    380380    end 
    381      
     381 
    382382    METHOD_ID = { 
    383383      ?j => :extract_J, 
     
    452452      # puts "+ #{lwsp.inspect}" 
    453453      fold if restsize() <= 0 
    454       flush 
     454      flush(@folded) 
    455455      @lwsp = lwsp 
    456456    end 
    457457 
    458     def flush 
     458    def flush(folded = false) 
    459459      # puts '---- flush ----' 
    460460      # puts "spc >>>#{@lwsp.inspect}<<<" 
    461461      # puts "txt >>>#{@text.inspect}<<<" 
    462462      @f << @lwsp << @text 
    463       @curlen += (@lwsp.size + @text.size) 
     463      if folded 
     464        @curlen = 0 
     465      else 
     466        @curlen += (@lwsp.size + @text.size) 
     467      end 
    464468      @text = '' 
    465469      @lwsp = '' 
     
    468472    def fold 
    469473      # puts '---- fold ----' 
    470       @f << @eol 
     474      unless @f.string =~ /^.*?:$/ 
     475        @f << @eol 
     476        @lwsp = SPACER 
     477      else 
     478        fold_header 
     479        @folded = true 
     480      end 
    471481      @curlen = 0 
    472       @lwsp = SPACER 
     482    end 
     483 
     484    def fold_header 
     485      # Called because line is too long - so we need to wrap. 
     486      # First look for whitespace in the text 
     487      # if it has text, fold there 
     488      # check the remaining text, if too long, fold again 
     489      # if it doesn't, then don't fold unless the line goes beyond 998 chars 
     490 
     491      # Check the text to see if there is whitespace, or if not 
     492      @wrapped_text = [] 
     493      until @text == '' 
     494        fold_the_string 
     495      end 
     496      @text = @wrapped_text.join("#{@eol}#{SPACER}") 
     497    end 
     498 
     499    def fold_the_string 
     500      whitespace_location = @text =~ /\s/ || @text.length 
     501      # Is the location of the whitespace shorter than the RCF_2822_MAX_LENGTH? 
     502      # if there is no whitespace in the string, then this 
     503      unless mazsize(whitespace_location) <= 0 
     504        @wrapped_text << @text.slice!(0...whitespace_location) 
     505      # If it is not less, we have to wrap it destructively 
     506      else 
     507        slice_point = RFC_2822_MAX_LENGTH - @curlen - @lwsp.length 
     508        @wrapped_text << @text.slice!(0...slice_point) 
     509      end 
    473510    end 
    474511 
     
    477514    end 
    478515 
     516    def mazsize(whitespace_location) 
     517      # Per RFC2822, the maximum length of a line is 998 chars 
     518      RFC_2822_MAX_LENGTH - (@curlen + @lwsp.size + whitespace_location) 
     519    end 
     520 
    479521  end 
    480522 
  • trunk/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/header.rb

    r8084 r8620  
    5555      end 
    5656 
     57      # Returns a HeaderField object matching the header you specify in the "name" param. 
     58      # Requires an initialized TMail::Port to be passed in. 
     59      # 
     60      # The method searches the header of the Port you pass into it to find a match on 
     61      # the header line you pass.  Once a match is found, it will unwrap the matching line 
     62      # as needed to return an initialized HeaderField object. 
     63      # 
     64      # If you want to get the Envelope sender of the email object, pass in "EnvelopeSender", 
     65      # if you want the From address of the email itself, pass in 'From'. 
     66      # 
     67      # This is because a mailbox doesn't have the : after the From that designates the 
     68      # beginning of the envelope sender (which can be different to the from address of  
     69      # the emial) 
     70      # 
     71      # Other fields can be passed as normal, "Reply-To", "Received" etc. 
     72      # 
     73      # Note: Change of behaviour in 1.2.1 => returns nil if it does not find the specified 
     74      # header field, otherwise returns an instantiated object of the correct header class 
     75      #  
     76      # For example: 
     77      #   port = TMail::FilePort.new("/test/fixtures/raw_email_simple") 
     78      #   h = TMail::HeaderField.new_from_port(port, "From") 
     79      #   h.addrs.to_s #=> "Mikel Lindsaar <mikel@nowhere.com>" 
     80      #   h = TMail::HeaderField.new_from_port(port, "EvelopeSender") 
     81      #   h.addrs.to_s #=> "mike@anotherplace.com.au" 
     82      #   h = TMail::HeaderField.new_from_port(port, "SomeWeirdHeaderField") 
     83      #   h #=> nil 
    5784      def new_from_port( port, name, conf = DEFAULT_CONFIG ) 
    58         re = Regep.new('\A(' + Regexp.quote(name) + '):', 'i') 
     85        if name == "EnvelopeSender" 
     86          name = "From" 
     87          re = Regexp.new('\A(From) ', 'i') 
     88        else 
     89          re = Regexp.new('\A(' + Regexp.quote(name) + '):', 'i') 
     90        end 
    5991        str = nil 
    6092        port.ropen {|f| 
     
    6799            end 
    68100        } 
    69         new(name, str, Config.to_config(conf)) 
     101        new(name, str, Config.to_config(conf)) if str 
    70102      end 
    71103 
  • trunk/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/interface.rb

    r8084 r8620  
    11=begin rdoc 
    22 
    3 = Facade.rb Provides an interface to the TMail object 
     3= interface.rb Provides an interface to the TMail object 
    44 
    55=end 
     
    3030#++ 
    3131 
     32# TMail::Mail objects get accessed primarily through the methods in this file. 
     33#  
     34#  
     35 
    3236require 'tmail/utils' 
    3337 
     
    3640  class Mail 
    3741 
     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 contnts of the field 
     46    #  
     47    #  mail.from = "mikel <mikel@lindsaar.net>" 
     48    #  mail.header_string("From") #=> "mikel <mikel@lindsaar.net>" 
    3849    def header_string( name, default = nil ) 
    3950      h = @header[name.downcase] or return default 
     
    4152    end 
    4253 
    43     ### 
    44     ### attributes 
    45     ### 
     54    #:stopdoc: 
     55    #-- 
     56    #== Attributes 
    4657 
    4758    include TextUtils 
     
    93104    private :addrs2specs 
    94105 
    95     # 
    96     # date time 
    97     # 
    98  
     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.  
    99115    def date( default = nil ) 
    100116      if h = @header['date'] 
     
    105121    end 
    106122 
     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 
    107132    def date=( time ) 
    108133      if time 
     
    114139    end 
    115140 
     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" 
    116148    def strftime( fmt, default = nil ) 
    117149      if t = date 
     
    122154    end 
    123155 
    124     # 
    125     # destination 
    126     # 
    127  
     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>] 
    128170    def to_addrs( default = nil ) 
    129171      if h = @header['to'] 
     
    134176    end 
    135177 
    136     def cc_addrs( default = nil ) 
     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 ) 
    137191      if h = @header['cc'] 
    138192        h.addrs 
     
    142196    end 
    143197 
     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>] 
    144210    def bcc_addrs( default = nil ) 
    145211      if h = @header['bcc'] 
     
    150216    end 
    151217 
     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>] 
    152228    def to_addrs=( arg ) 
    153229      set_addrfield 'to', arg 
    154230    end 
    155231 
     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>] 
    156242    def cc_addrs=( arg ) 
    157243      set_addrfield 'cc', arg 
    158244    end 
    159245 
     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>] 
    160256    def bcc_addrs=( arg ) 
    161257      set_addrfield 'bcc', arg 
    162258    end 
    163259 
     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"] 
    164268    def to( default = nil ) 
    165269      addrs2specs(to_addrs(nil)) || default 
    166270    end 
    167271 
     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"] 
    168280    def cc( default = nil ) 
    169281      addrs2specs(cc_addrs(nil)) || default 
    170282    end 
    171283 
     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"] 
    172292    def bcc( default = nil ) 
    173293      addrs2specs(bcc_addrs(nil)) || default 
    174294    end 
    175295 
     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>" 
    176305    def to=( *strs ) 
    177306      set_string_array_attr 'To', strs 
    178307    end 
    179308 
     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>" 
    180318    def cc=( *strs ) 
    181319      set_string_array_attr 'Cc', strs 
    182320    end 
    183321 
     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>" 
    184331    def bcc=( *strs ) 
    185332      set_string_array_attr 'Bcc', strs 
    186333    end 
    187334 
    188     # 
    189     # originator 
    190     # 
    191  
     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>] 
    192349    def from_addrs( default = nil ) 
    193350      if h = @header['from'] 
     
    198355    end 
    199356 
     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>] 
    200367    def from_addrs=( arg ) 
    201368      set_addrfield 'from', arg 
    202369    end 
    203370 
     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"] 
    204379    def from( default = nil ) 
    205380      addrs2specs(from_addrs(nil)) || default 
    206381    end 
    207382 
     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>" 
    208392    def from=( *strs ) 
    209393      set_string_array_attr 'From', strs 
    210394    end 
    211395 
     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" 
    212403    def friendly_from( default = nil ) 
    213404      h = @header['from'] 
     
    219410    end 
    220411 
    221  
     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>] 
    222424    def reply_to_addrs( default = nil ) 
    223425      if h = @header['reply-to'] 
    224         h.addrs 
    225       else 
    226         default 
    227       end 
    228     end 
    229  
     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>] 
    230442    def reply_to_addrs=( arg ) 
    231443      set_addrfield 'reply-to', arg 
    232444    end 
    233445 
     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"] 
    234454    def reply_to( default = nil ) 
    235455      addrs2specs(reply_to_addrs(nil)) || default 
    236456    end 
    237457 
     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>" 
    238467    def reply_to=( *strs ) 
    239468      set_string_array_attr 'Reply-To', strs 
    240469    end 
    241470 
    242  
     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>] 
    243483    def sender_addr( default = nil ) 
    244484      f = @header['sender'] or return default 
     
    246486    end 
    247487 
     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>] 
    248498    def sender_addr=( addr ) 
    249499      if addr 
     
    257507    end 
    258508 
    259     def sender( default ) 
     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 ) 
    260518      f = @header['sender'] or return default 
    261519      a = f.addr            or return default 
     
    263521    end 
    264522 
     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" 
    265532    def sender=( str ) 
    266533      set_string_attr 'Sender', str 
    267534    end 
    268535 
    269  
    270     # 
    271     # subject 
    272     # 
    273  
     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" 
    274550    def subject( default = nil ) 
    275551      if h = @header['subject'] 
     
    281557    alias quoted_subject subject 
    282558 
     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" 
    283567    def subject=( str ) 
    284568      set_string_attr 'Subject', str 
    285569    end 
    286570 
    287     # 
    288     # identity & threading 
    289     # 
    290  
     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>" 
    291585    def message_id( default = nil ) 
    292586      if h = @header['message-id'] 
     
    297591    end 
    298592 
     593    # Destructively sets the message ID of the mail object instance to the passed in string 
     594    # 
     595    # Example: 
     596    #  
     597    #  mail = TMail::Mail.new 
     598    #  mail.message_id = "this_is_my_badly_formatted_message_id" 
     599    #  mail.message_id #=> "this_is_my_badly_formatted_message_id" 
    299600    def message_id=( str ) 
    300601      set_string_attr 'Message-Id', str 
    301602    end 
    302603 
     604    # Returns the "In-Reply-To:" field contents as an array of this mail instance if it exists 
     605    #  
     606    # If the in_reply_to field does not exist, returns nil by default or you can pass in as 
     607    # the parameter for what you want the default value to be. 
     608    #  
     609    # Example: 
     610    #  
     611    #  mail = TMail::Mail.new 
     612    #  mail.in_reply_to #=> nil 
     613    #  mail.in_reply_to([]) #=> [] 
     614    #  TMail::Mail.load("../test/fixtures/raw_email_reply") 
     615    #  mail.in_reply_to #=> ["<348F04F142D69C21-291E56D292BC@xxxx.net>"] 
    303616    def in_reply_to( default = nil ) 
    304617      if h = @header['in-reply-to'] 
     
    309622    end 
    310623 
     624    # Destructively sets the value of the "In-Reply-To:" field of an email. 
     625    #  
     626    # Accepts an array of a single string of a message id 
     627    # 
     628    # Example:  
     629    #  
     630    #  mail = TMail::Mail.new 
     631    #  mail.in_reply_to = ["<348F04F142D69C21-291E56D292BC@xxxx.net>"] 
     632    #  mail.in_reply_to #=> ["<348F04F142D69C21-291E56D292BC@xxxx.net>"] 
    311633    def in_reply_to=( *idstrs ) 
    312634      set_string_array_attr 'In-Reply-To', idstrs 
    313635    end 
    314636 
     637    # Returns the references of this email (prior messages relating to this message) 
     638    # as an array of message ID strings.  Useful when you are trying to thread an 
     639    # email. 
     640    #  
     641    # If the references field does not exist, returns nil by default or you can pass in as 
     642    # the parameter for what you want the default value to be. 
     643    #  
     644    # Example: 
     645    # 
     646    #  mail = TMail::Mail.new 
     647    #  mail.references #=> nil 
     648    #  mail.references([]) #=> [] 
     649    #  mail = TMail::Mail.load("../test/fixtures/raw_email_reply") 
     650    #  mail.references #=> ["<473FF3B8.9020707@xxx.org>", "<348F04F142D69C21-291E56D292BC@xxxx.net>"] 
    315651    def references( default = nil ) 
    316652      if h = @header['references'] 
     
    321657    end 
    322658 
     659    # Destructively sets the value of the "References:" field of an email. 
     660    #  
     661    # Accepts an array of strings of message IDs 
     662    # 
     663    # Example:  
     664    #  
     665    #  mail = TMail::Mail.new 
     666    #  mail.references = ["<348F04F142D69C21-291E56D292BC@xxxx.net>"] 
     667    #  mail.references #=> ["<348F04F142D69C21-291E56D292BC@xxxx.net>"] 
    323668    def references=( *strs ) 
    324669      set_string_array_attr 'References', strs 
    325670    end 
    326671 
    327     # 
    328     # MIME headers 
    329     # 
    330  
     672    #== MIME header methods 
     673 
     674    # Returns the listed MIME version of this email from the "Mime-Version:" header field 
     675    #  
     676    # If the mime_version field does not exist, returns nil by default or you can pass in as 
     677    # the parameter for what you want the default value to be. 
     678    #  
     679    # Example: 
     680    # 
     681    #  mail = TMail::Mail.new 
     682    #  mail.mime_version #=> nil 
     683    #  mail.mime_version([]) #=> [] 
     684    #  mail = TMail::Mail.load("../test/fixtures/raw_email") 
     685    #  mail.mime_version #=> "1.0" 
    331686    def mime_version( default = nil ) 
    332687      if h = @header['mime-version'] 
     
    351706    end 
    352707 
     708    # Returns the current "Content-Type" of the mail instance. 
     709    # 
     710    # If the content_type field does not exist, returns nil by default or you can pass in as 
     711    # the parameter for what you want the default value to be. 
     712    #  
     713    # Example: 
     714    # 
     715    #  mail = TMail::Mail.new 
     716    #  mail.content_type #=> nil 
     717    #  mail.content_type([]) #=> [] 
     718    #  mail = TMail::Mail.load("../test/fixtures/raw_email") 
     719    #  mail.content_type #=> "text/plain" 
    353720    def content_type( default = nil ) 
    354721      if h = @header['content-type'] 
     
    359726    end 
    360727 
     728    # Returns the current main type of the "Content-Type" of the mail instance. 
     729    # 
     730    # If the content_type field does not exist, returns nil by default or you can pass in as 
     731    # the parameter for what you want the default value to be. 
     732    #  
     733    # Example: 
     734    # 
     735    #  mail = TMail::Mail.new 
     736    #  mail.main_type #=> nil 
     737    #  mail.main_type([]) #=> [] 
     738    #  mail = TMail::Mail.load("../test/fixtures/raw_email") 
     739    #  mail.main_type #=> "text" 
    361740    def main_type( default = nil ) 
    362741      if h = @header['content-type'] 
     
    367746    end 
    368747 
     748    # Returns the current sub type of the "Content-Type" of the mail instance. 
     749    # 
     750    # If the content_type field does not exist, returns nil by default or you can pass in as 
     751    # the parameter for what you want the default value to be. 
     752    #  
     753    # Example: 
     754    # 
     755    #  mail = TMail::Mail.new 
     756    #  mail.sub_type #=> nil 
     757    #  mail.sub_type([]) #=> [] 
     758    #  mail = TMail::Mail.load("../test/fixtures/raw_email") 
     759    #  mail.sub_type #=> "plain" 
    369760    def sub_type( default = nil ) 
    370761      if h = @header['content-type'] 
     
    375766    end 
    376767 
     768    # Destructively sets the "Content-Type:" header field of this mail object 
     769    #  
     770    # Allows you to set the main type, sub type as well as parameters to the field. 
     771    # The main type and sub type need to be a string. 
     772    #  
     773    # The optional params hash can be passed with keys as symbols and values as a string, 
     774    # or strings as keys and values. 
     775    #  
     776    # Example: 
     777    #  
     778    #  mail = TMail::Mail.new 
     779    #  mail.set_content_type("text", "plain") 
     780    #  mail.to_s #=> "Content-Type: text/plain\n\n" 
     781    #  
     782    #  mail.set_content_type("text", "plain", {:charset => "EUC-KR", :format => "flowed"}) 
     783    #  mail.to_s #=> "Content-Type: text/plain; charset=EUC-KR; format=flowed\n\n" 
     784    # 
     785    #  mail.set_content_type("text", "plain", {"charset" => "EUC-KR", "format" => "flowed"}) 
     786    #  mail.to_s #=> "Content-Type: text/plain; charset=EUC-KR; format=flowed\n\n" 
    377787    def set_content_type( str, sub = nil, param = nil ) 
    378788      if sub 
     
    395805    alias content_type= set_content_type 
    396806     
     807    # Returns the named type parameter as a string, from the "Content-Type:" header. 
     808    #  
     809    # Example: 
     810    #  
     811    #  mail = TMail::Mail.new 
     812    #  mail.type_param("charset") #=> nil 
     813    #  mail.type_param("charset", []) #=> [] 
     814    #  mail.set_content_type("text", "plain", {:charset => "EUC-KR", :format => "flowed"}) 
     815    #  mail.type_param("charset") #=> "EUC-KR" 
     816    #  mail.type_param("format") #=> "flowed" 
    397817    def type_param( name, default = nil ) 
    398818      if h = @header['content-type'] 
     
    403823    end 
    404824 
     825    # Returns the character set of the email.  Returns nil if no encoding set or returns 
     826    # whatever default you pass as a parameter - note passing the parameter does NOT change 
     827    # the mail object in any way. 
     828    #  
     829    # Example: 
     830    #  
     831    #  mail = TMail::Mail.load("path_to/utf8_email") 
     832    #  mail.charset #=> "UTF-8" 
     833    #  
     834    #  mail = TMail::Mail.new 
     835    #  mail.charset #=> nil 
     836    #  mail.charset("US-ASCII") #=> "US-ASCII" 
    405837    def charset( default = nil ) 
    406838      if h = @header['content-type'] 
     
    411843    end 
    412844 
     845    # Destructively sets the character set used by this mail object to the passed string, you 
     846    # should note though that this does nothing to the mail body, just changes the header 
     847    # value, you will need to transliterate the body as well to match whatever you put  
     848    # in this header value if you are changing character sets. 
     849    #  
     850    # Example: 
     851    #  
     852    #  mail = TMail::Mail.new 
     853    #  mail.charset #=> nil 
     854    #  mail.charset = "UTF-8" 
     855    #  mail.charset #=> "UTF-8" 
    413856    def charset=( str ) 
    414857      if str 
     
    422865    end 
    423866 
     867    # Returns the transfer encoding of the email.  Returns nil if no encoding set or returns 
     868    # whatever default you pass as a parameter - note passing the parameter does NOT change 
     869    # the mail object in any way. 
     870    #  
     871    # Example: 
     872    #  
     873    #  mail = TMail::Mail.load("path_to/base64_encoded_email") 
     874    #  mail.transfer_encoding #=> "base64" 
     875    #  
     876    #  mail = TMail::Mail.new 
     877    #  mail.transfer_encoding #=> nil 
     878    #  mail.transfer_encoding("base64") #=> "base64" 
    424879    def transfer_encoding( default = nil ) 
    425880      if h = @header['content-transfer-encoding'] 
     
    430885    end 
    431886 
     887    # Destructively sets the transfer encoding of the mail object to the passed string, you 
     888    # should note though that this does nothing to the mail body, just changes the header 
     889    # value, you will need to encode or decode the body as well to match whatever you put  
     890    # in this header value. 
     891    #  
     892    # Example: 
     893    #  
     894    #  mail = TMail::Mail.new 
     895    #  mail.transfer_encoding #=> nil 
     896    #  mail.transfer_encoding = "base64" 
     897    #  mail.transfer_encoding #=> "base64" 
    432898    def transfer_encoding=( str ) 
    433899      set_string_attr 'Content-Transfer-Encoding', str 
     
    439905    alias content_transfer_encoding= transfer_encoding= 
    440906 
     907    # Returns the content-disposition of the mail object, returns nil or the passed  
     908    # default value if given 
     909    #  
     910    # Example: 
     911    #  
     912    #  mail = TMail::Mail.load("path_to/raw_mail_with_attachment")  
     913    #  mail.disposition #=> "attachment" 
     914    # 
     915    #  mail = TMail::Mail.load("path_to/plain_simple_email") 
     916    #  mail.disposition #=> nil 
     917    #  mail.disposition(false) #=> false 
    441918    def disposition( default = nil ) 
    442919      if h = @header['content-disposition'] 
     
    449926    alias content_disposition     disposition 
    450927 
     928    # Allows you to set the content-disposition of the mail object.  Accepts a type 
     929    # and a hash of parameters. 
     930    #  
     931    # Example: 
     932    #  
     933    #  mail.set_disposition("attachment", {:filename => "test.rb"}) 
     934    #  mail.disposition #=> "attachment" 
     935    #  mail['content-disposition'].to_s #=> "attachment; filename=test.rb" 
    451936    def set_disposition( str, params = nil ) 
    452937      if h = @header['content-disposition'] 
     
    463948    alias set_content_disposition set_disposition 
    464949    alias content_disposition=    set_disposition 
    465      
     950 
     951    # Returns the value of a parameter in an existing content-disposition header 
     952    #  
     953    # Example: 
     954    #  
     955    #  mail.set_disposition("attachment", {:filename => "test.rb"}) 
     956    #  mail['content-disposition'].to_s #=> "attachment; filename=test.rb" 
     957    #  mail.disposition_param("filename") #=> "test.rb" 
     958    #  mail.disposition_param("missing_param_key") #=> nil 
     959    #  mail.disposition_param("missing_param_key", false) #=> false 
     960    #  mail.disposition_param("missing_param_key", "Nothing to see here") #=> "Nothing to see here" 
    466961    def disposition_param( name, default = nil ) 
    467962      if h = @header['content-disposition'] 
     
    472967    end 
    473968 
    474     ### 
    475     ### utils 
    476     ### 
    477  
    478     def create_reply 
    479       mail = TMail::Mail.parse('') 
    480       mail.subject = 'Re: ' + subject('').sub(/\A(?:\[[^\]]+\])?(?:\s*Re:)*\s*/i, '') 
    481       mail.to_addrs = reply_addresses([]) 
    482       mail.in_reply_to = [message_id(nil)].compact 
    483       mail.references = references([]) + [message_id(nil)].compact 
    484       mail.mime_version = '1.0' 
    485       mail 
    486     end 
    487  
    488     def base64_encode 
     969    # Destructively convert the Mail object's body into a Base64 encoded email 
     970    # returning the modified Mail object 
     971    def base64_encode! 
    489972      store 'Content-Transfer-Encoding', 'Base64' 
    490973      self.body = Base64.folding_encode(self.body) 
    491974    end 
    492975 
    493     def base64_decode 
     976    # ==Depreciation warning 
     977    # base64_encode will return the body encoded, not modify the message body in  
     978    # future versions of TMail 
     979    alias :base64_encode :base64_encode! 
     980 
     981    # Destructively convert the Mail object's body into a Base64 decoded email 
     982    # returning the modified Mail object 
     983    def base64_decode! 
    494984      if /base64/i === self.transfer_encoding('') 
    495985        store 'Content-Transfer-Encoding', '8bit' 
     
    498988    end 
    499989 
     990    # ==Depreciation warning 
     991    # base64_decode will return the body decoded, not modify the message body in  
     992    # future versions of TMail 
     993    alias :base64_decode :base64_decode! 
     994 
     995    # Returns an array of each destination in the email message including to: cc: or bcc: 
     996    #  
     997    # Example: 
     998    #  
     999    #  mail.to = "Mikel <mikel@lindsaar.net>" 
     1000    #  mail.cc = "Trans <t@t.com>" 
     1001    #  mail.bcc = "bob <bob@me.com>" 
     1002    #  mail.destinations #=> ["mikel@lindsaar.net", "t@t.com", "bob@me.com"] 
    5001003    def destinations( default = nil ) 
    5011004      ret = [] 
     
    5081011    end 
    5091012 
     1013    # Yields a block of destination, yielding each as a string. 
     1014    #  (from the destinations example) 
     1015    #  mail.each_destination { |d| puts "#{d.class}: #{d}" } 
     1016    #  String: mikel@lindsaar.net 
     1017    #  String: t@t.com 
     1018    #  String: bob@me.com 
    5101019    def each_destination( &block ) 
    5111020      destinations([]).each do |i| 
     
    5201029    alias each_dest each_destination 
    5211030 
     1031    # Returns an array of reply to addresses that the Mail object has,  
     1032    # or if the Mail message has no reply-to, returns an array of the 
     1033    # Mail objects from addresses.  Else returns the default which can 
     1034    # either be passed as a parameter or defaults to nil 
     1035    #  
     1036    # Example: 
     1037    #  mail.from = "Mikel <mikel@lindsaar.net>" 
     1038    #  mail.reply_to = nil 
     1039    #  mail.reply_addresses #=> [""]   
     1040    #  
    5221041    def reply_addresses( default = nil ) 
    5231042      reply_to_addrs(nil) or from_addrs(nil) or default 
    5241043    end 
    5251044 
     1045    # Returns the "sender" field as an array -> useful to find out who to  
     1046    # send an error email to. 
    5261047    def error_reply_addresses( default = nil ) 
    5271048      if s = sender(nil) 
     
    5321053    end 
    5331054 
     1055    # Returns true if the Mail object is a multipart message 
    5341056    def multipart? 
    5351057      main_type('').downcase == 'multipart' 
    5361058    end 
    5371059 
     1060    # Creates a new email in reply to self.  Sets the In-Reply-To and 
     1061    # References headers for you automagically. 
     1062    # 
     1063    # Example: 
     1064    #  mail = TMail::Mail.load("my_email") 
     1065    #  reply_email = mail.create_reply 
     1066    #  reply_email.class         #=> TMail::Mail 
     1067    #  reply_email.references  #=> ["<d3b8cf8e49f04480850c28713a1f473e@lindsaar.net>"] 
     1068    #  reply_email.in_reply_to #=> ["<d3b8cf8e49f04480850c28713a1f473e@lindsaar.net>"] 
     1069    def create_reply 
     1070      setup_reply create_empty_mail() 
     1071    end 
     1072 
     1073    # Creates a new email in reply to self.  Sets the In-Reply-To and 
     1074    # References headers for you automagically. 
     1075    # 
     1076    # Example: 
     1077    #  mail = TMail::Mail.load("my_email") 
     1078    #  forward_email = mail.create_forward 
     1079    #  forward_email.class         #=> TMail::Mail 
     1080    #  forward_email.content_type  #=> "multipart/mixed" 
     1081    #  forward_email.body          #=> "Attachment: (unnamed)" 
     1082    #  forward_email.encoded       #=> Returns the original email as a MIME attachment 
     1083    def create_forward 
     1084      setup_forward create_empty_mail() 
     1085    end 
     1086 
     1087    #:stopdoc: 
     1088    private 
     1089 
     1090    def create_empty_mail 
     1091      self.class.new(StringPort.new(''), @config) 
     1092    end 
     1093 
     1094    def setup_reply( mail ) 
     1095      if tmp = reply_addresses(nil) 
     1096        mail.to_addrs = tmp 
     1097      end 
     1098 
     1099      mid = message_id(nil) 
     1100      tmp = references(nil) || [] 
     1101      tmp.push mid if mid 
     1102      mail.in_reply_to = [mid] if mid 
     1103      mail.references = tmp unless tmp.empty? 
     1104      mail.subject = 'Re: ' + subject('').sub(/\A(?:\[[^\]]+\])?(?:\s*Re:)*\s*/i, '') 
     1105      mail.mime_version = '1.0' 
     1106      mail 
     1107    end 
     1108 
     1109    def setup_forward( mail ) 
     1110      m = Mail.new(StringPort.new('')) 
     1111      m.body = decoded 
     1112      m.set_content_type 'message', 'rfc822' 
     1113      m.encoding = encoding('7bit') 
     1114      mail.parts.push m 
     1115      # call encoded to reparse the message 
     1116      mail.encoded 
     1117      mail 
     1118    end 
     1119 
     1120  #:startdoc: 
    5381121  end   # class Mail 
    5391122 
  • trunk/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/mail.rb

    r8084 r8620  
    2929# with permission of Minero Aoki. 
    3030#++ 
     31# == TMail::Mail 
     32# === Class Methods 
     33 
     34#  
     35#  
     36#  
     37#  
     38#  
     39#  
     40#  
     41#  
     42#  
     43#  
     44#  
     45#  
     46#  
     47  
    3148 
    3249require 'tmail/interface' 
     
    163180    end 
    164181 
     182    # Returns a TMail::AddressHeader object of the field you are querying. 
     183    # Examples: 
     184    #  @mail['from']  #=> #<TMail::AddressHeader "mikel@test.com.au"> 
     185    #  @mail['to']    #=> #<TMail::AddressHeader "mikel@test.com.au"> 
     186    # 
     187    # You can get the string value of this by passing "to_s" to the query: 
     188    # Example: 
     189    #  @mail['to'].to_s #=> "mikel@test.com.au" 
    165190    def []( key ) 
    166191      @header[key.downcase] 
     
    173198    alias fetch [] 
    174199 
     200    # Allows you to set or delete TMail header objects at will. 
     201    # Eamples: 
     202    #  @mail = TMail::Mail.new 
     203    #  @mail['to'].to_s       # => 'mikel@test.com.au' 
     204    #  @mail['to'] = 'mikel@elsewhere.org' 
     205    #  @mail['to'].to_s       # => 'mikel@elsewhere.org' 
     206    #  @mail.encoded          # => "To: mikel@elsewhere.org\r\n\r\n" 
     207    #  @mail['to'] = nil 
     208    #  @mail['to'].to_s       # => nil 
     209    #  @mail.encoded          # => "\r\n" 
     210    #  
     211    # Note: setting mail[] = nil actualy deletes the header field in question from the object, 
     212    # it does not just set the value of the hash to nil 
    175213    def []=( key, val ) 
    176214      dkey = key.downcase 
     
    204242 
    205243    alias store []= 
    206  
     244     
     245    # Allows you to loop through each header in the TMail::Mail object in a block 
     246    # Example: 
     247    #   @mail['to'] = 'mikel@elsewhere.org' 
     248    #   @mail['from'] = 'me@me.com' 
     249    #   @mail.each_header { |k,v| puts "#{k} = #{v}" } 
     250    #   # => from = me@me.com 
     251    #   # => to = mikel@elsewhere.org 
    207252    def each_header 
    208253      @header.each do |key, val| 
  • trunk/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/mailbox.rb

    r8084 r8620  
    214214    end 
    215215 
    216     def UNIXMbox.fromaddr 
     216    def UNIXMbox.fromaddr(port) 
    217217      h = HeaderField.new_from_port(port, 'Return-Path') || 
    218           HeaderField.new_from_port(port, 'From') or return 'nobody' 
     218      HeaderField.new_from_port(port, 'From') || 
     219      HeaderField.new_from_port(port, 'EnvelopeSender') or return 'nobody' 
    219220      a = h.addrs[0] or return 'nobody' 
    220221      a.spec 
    221222    end 
    222     private_class_method :fromaddr 
    223223 
    224224    def close 
  • trunk/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/net.rb

    r8084 r8620  
    129129      end 
    130130    end 
    131  
    132     def create_empty_mail 
    133       self.class.new(StringPort.new(''), @config) 
    134     end 
    135  
    136     def create_reply 
    137       setup_reply create_empty_mail() 
    138     end 
    139  
    140     def setup_reply( m ) 
    141       if tmp = reply_addresses(nil) 
    142         m.to_addrs = tmp 
    143       end 
    144  
    145       mid = message_id(nil) 
    146       tmp = references(nil) || [] 
    147       tmp.push mid if mid 
    148       m.in_reply_to = [mid] if mid 
    149       m.references = tmp unless tmp.empty? 
    150       m.subject = 'Re: ' + subject('').sub(/\A(?:\s*re:)+/i, '') 
    151  
    152       m 
    153     end 
    154  
    155     def create_forward 
    156       setup_forward create_empty_mail() 
    157     end 
    158  
    159     def setup_forward( mail ) 
    160       m = Mail.new(StringPort.new('')) 
    161       m.body = decoded 
    162       m.set_content_type 'message', 'rfc822' 
    163       m.encoding = encoding('7bit') 
    164       mail.parts.push m 
    165     end 
    166131   
    167132  end 
  • trunk/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/quoting.rb

    r8084 r8620  
    1414      case (content_transfer_encoding || "7bit").downcase 
    1515        when "quoted-printable" 
    16           # the default charset is set to iso-8859-1 instead of 'us-ascii'.  
     16          # the default charset is set to iso-8859-1 instead of 'us-ascii'. 
    1717          # This is needed as many mailer do not set the charset but send in ISO. This is only used if no charset is set. 
    1818          if !from_charset.blank? && from_charset.downcase == 'us-ascii' 
    1919            from_charset = 'iso-8859-1' 
    2020          end 
    21            
     21 
    2222          Unquoter.unquote_quoted_printable_and_convert_to(quoted_body, 
    2323            to_charset, from_charset, true) 
     
    3636    def body(to_charset = 'utf-8', &block) 
    3737      attachment_presenter = block || Proc.new { |file_name| "Attachment: #{file_name}\n" } 
    38      
     38 
    3939      if multipart? 
    40         parts.collect { |part|  
     40        parts.collect { |part| 
    4141          header = part["content-type"] 
    4242 
     
    8282        end 
    8383      end 
    84   
     84 
    8585      def unquote_quoted_printable_and_convert_to(text, to, from, preserve_underscores=false) 
    8686        text = text.gsub(/_/, " ") unless preserve_underscores 
     
    8888        convert_to(text.unpack("M*").first, to, from) 
    8989      end 
    90   
     90 
    9191      def unquote_base64_and_convert_to(text, to, from) 
    9292        convert_to(Base64.decode(text), to, from) 
     
    117117  end 
    118118end 
    119  
    120 if __FILE__ == $0 
    121   require 'test/unit' 
    122  
    123   class TC_Unquoter < Test::Unit::TestCase 
    124     def test_unquote_quoted_printable 
    125       a ="=?ISO-8859-1?Q?[166417]_Bekr=E6ftelse_fra_Rejsefeber?="  
    126       b = TMail::Unquoter.unquote_and_convert_to(a, 'utf-8') 
    127       assert_equal "[166417] Bekr\303\246ftelse fra Rejsefeber", b 
    128     end 
    129  
    130     def test_unquote_base64 
    131       a ="=?ISO-8859-1?B?WzE2NjQxN10gQmVrcuZmdGVsc2UgZnJhIFJlanNlZmViZXI=?=" 
    132       b = TMail::Unquoter.unquote_and_convert_to(a, 'utf-8') 
    133       assert_equal "[166417] Bekr\303\246ftelse fra Rejsefeber", b 
    134     end 
    135  
    136     def test_unquote_without_charset 
    137       a ="[166417]_Bekr=E6ftelse_fra_Rejsefeber"  
    138       b = TMail::Unquoter.unquote_and_convert_to(a, 'utf-8') 
    139       assert_equal "[166417]_Bekr=E6ftelse_fra_Rejsefeber", b 
    140     end 
    141   end 
    142 end 
  • trunk/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/scanner_r.rb

    r8246 r8620  
    3030require 'tmail/config' 
    3131 
    32  
    3332module TMail 
    3433 
    35   class Scanner_R 
    36  
    37     Version = '0.10.7
     34  class TMailScanner 
     35 
     36    Version = '0.11.0
    3837    Version.freeze 
    3938 
     
    4746    atomsyms   = %q[  _#!$%&`'*+-{|}~^/=?  ].strip 
    4847    tokensyms  = %q[  _#!$%&`'*+-{|}~^@.    ].strip 
    49  
    5048    atomchars  = alnum + Regexp.quote(atomsyms) 
    5149    tokenchars = alnum + Regexp.quote(tokensyms) 
  • trunk/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/scanner.rb

    r8084 r8620  
    3131 
    3232require 'tmail/utils' 
     33require 'tmail/config' 
    3334 
    3435module TMail 
    35   require 'tmail/scanner_r.rb' 
     36  # NOTE: It woiuld be nice if these two libs could boith be called "tmailscanner", and 
     37  # the native extension would have precedence. However RubyGems boffs that up b/c 
     38  # it does not gaurantee load_path order. 
    3639  begin 
    37     raise LoadError, 'Turn off Ruby extention by user choice' if ENV['NORUBYEXT'] 
    38     require 'tmail/scanner_c.so' 
    39     Scanner = Scanner_C 
     40    raise LoadError, 'Turned off native extentions by user choice' if ENV['NORUBYEXT'] 
     41    require('tmail/tmailscanner') # c extension 
     42    Scanner = TMailScanner 
    4043  rescue LoadError 
    41     Scanner = Scanner_R 
     44    require 'tmail/scanner_r' 
     45    Scanner = TMailScanner 
    4246  end 
    4347end 
  • trunk/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/utils.rb

    r8084 r8620  
    5757  module TextUtils 
    5858    # Defines characters per RFC that are OK for TOKENs, ATOMs, PHRASEs and CONTROL characters. 
    59      
     59 
    6060    aspecial     = '()<>[]:;.\\,"' 
    6161    tspecial     = '()<>[];:\\,"/?=' 
     
    249249      m = RFC2231_ENCODED.match(str) or return str 
    250250      begin 
    251         NKF.nkf(NKF_FLAGS[$KCODE], 
    252         m.post_match.gsub(/%[\da-f]{2}/in) {|s| s[1,2].hex.chr }) 
     251        to_kcode(m.post_match.gsub(/%[\da-f]{2}/in) {|s| s[1,2].hex.chr }) 
    253252      rescue 
    254253        m.post_match.gsub(/%[\da-f]{2}/in, "") 
     
    264263        remainder = $2 
    265264        if remainder =~ /;/ 
    266           remainder =~ /^(.*)(;.*)$/m 
     265          remainder =~ /^(.*?)(;.*)$/m 
    267266          boundary_text = $1 
    268267          post = $2.chomp 
  • trunk/actionmailer/lib/action_mailer/vendor/tmail-1.2.1/tmail/version.rb

    r8233 r8620  
    3131  module VERSION #:nodoc: 
    3232    MAJOR = 1 
    33     MINOR = 1 
    34     TINY  = 1 
     33    MINOR = 2 
     34    TINY  = 0 
    3535 
    3636    STRING = [MAJOR, MINOR, TINY].join('.') 
  • trunk/actionmailer/test/mail_service_test.rb

    r8565 r8620  
    839839    mail = TMail::Mail.parse(fixture) 
    840840    attachment = mail.attachments.last 
    841     assert_equal "01QuienTeDijat.Pitbull.mp3", attachment.original_filename 
     841    assert_equal "01 Quien Te Dij\212at. Pitbull.mp3", attachment.original_filename 
    842842  end 
    843843