Class: Mail::Message

Inherits:
Object show all
Defined in:
lib/mail_ext.rb

Overview

– Copyright © 2010 by Mike Mondragon ([email protected])

Please see the LICENSE file for licensing information. ++

Instance Method Summary collapse

Instance Method Details

#filenameObject

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’



26
27
28
29
30
31
32
33
34
# File 'lib/mail_ext.rb', line 26

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

#part_type?Boolean

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

Returns:

  • (Boolean)


13
14
15
16
17
18
19
# File 'lib/mail_ext.rb', line 13

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