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

Returns a new instance of File.



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

def initialize (headers, content)
	if headers[:content_type]
		content.force_encoding headers[:content_type].charset
	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



50
51
52
# File 'lib/mbox/mail/file.rb', line 50

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

#to_sObject Also known as: to_str



44
45
46
# File 'lib/mbox/mail/file.rb', line 44

def to_s
	@content
end