Sha256: c7a1e6804d488c8b0e0a2b715aaa330030c3501f0a436585eb116a2758e16bbc

Contents?: true

Size: 1018 Bytes

Versions: 16

Compression:

Stored size: 1018 Bytes

Contents

#--
# Copyright (c) 2010 by Mike Mondragon (mikemondragon@gmail.com)
#
# Please see the LICENSE file for licensing information.
#++

class Mail::Message

    ##
    # Generically determines the mime-type of a message used in mms2r processing.
    # Guarantees a type is returned.

    def part_type?
      if self.content_type
        self.content_type.split(';').first.downcase
      else
        'text/plain'
      end
    end

    ##
    # override #filename to account for the true filename in the content_type
    # returns foo.jpg #content_type is 'image/jpeg; filename="foo.jpg"; name="foo.jpg"'
    # returns foo.jpg #content_type is 'image/jpeg;Name=foo.jpg'

    def filename
      if self.content_type && names = Hash[self.content_type.split(';').map{|t| t.strip.split('=')}]
        if name = names.detect{|key,val| key.downcase == 'filename'} || names.detect{|key,val| key.downcase == 'name'}
          return (name.last.match(/^"?(.+?)"?$/))[1]
        end
      end

      find_attachment
    end


end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
mms2r-3.7.0 lib/ext/mail.rb
mms2r-3.6.4 lib/ext/mail.rb
mms2r-3.6.3 lib/ext/mail.rb
mms2r-3.6.2 lib/ext/mail.rb
mms2r-3.6.1 lib/ext/mail.rb
mms2r-3.6.0 lib/ext/mail.rb
mms2r-3.5.1 lib/ext/mail.rb
mms2r-3.5.0 lib/ext/mail.rb
mms2r-3.4.1 lib/ext/mail.rb
mms2r-3.4.0 lib/ext/mail.rb
mms2r-3.3.1 lib/mail_ext.rb
mms2r-3.3.0 lib/mail_ext.rb
mms2r-3.2.0 lib/mail_ext.rb
mms2r-3.1.0 lib/mail_ext.rb
mms2r-3.0.1 lib/mail_ext.rb
mms2r-3.0.0 lib/mail_ext.rb