Class: Mbox::Mail::File

Inherits:
Object
  • Object
show all
Defined in:
lib/mbox/mail/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(headers, content) ⇒ File



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/mbox/mail/file.rb', line 27

def initialize (headers, content)
  if headers[:content_type] && headers[:content_type].charset
    begin
      content.force_encoding headers[:content_type].charset
    rescue
      content.force_encoding 'BINARY'
    end
  end

  if headers[:content_transfer_encoding] == 'base64'
    content = Base64.decode64(content)
  end

  if matches = headers[:content_disposition].match(/filename="(.*?)"/) rescue nil
    @name = matches[1]
  end

  @headers = headers
  @content = content
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content



25
26
27
# File 'lib/mbox/mail/file.rb', line 25

def content
  @content
end

#headersObject (readonly)

Returns the value of attribute headers



25
26
27
# File 'lib/mbox/mail/file.rb', line 25

def headers
  @headers
end

#nameObject (readonly)

Returns the value of attribute name



25
26
27
# File 'lib/mbox/mail/file.rb', line 25

def name
  @name
end

Instance Method Details

#inspectObject



54
55
56
# File 'lib/mbox/mail/file.rb', line 54

def inspect
  "#<File:#{name}>"
end

#to_sObject Also known as: to_str



48
49
50
# File 'lib/mbox/mail/file.rb', line 48

def to_s
  @content
end