Class: Cabbage::MimePart

Inherits:
Object
  • Object
show all
Defined in:
lib/cabbage/email/mime_part.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_part) ⇒ MimePart

Returns a new instance of MimePart.



4
5
6
7
8
9
10
# File 'lib/cabbage/email/mime_part.rb', line 4

def initialize(raw_part)
  @raw_source = raw_part
  @header = raw_part[:header]
  @original_keys = raw_part[:original_keys]
  @body = raw_part[:body]
  @content_type = @header[:content_type].split(";")[0].strip
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



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

def method_missing(m, *args, &block)
  if @header.keys.include?(m.intern)
    @header[m.intern]
  else
    raise "undefined method in Cabbage::MimePart"
  end
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



11
12
13
# File 'lib/cabbage/email/mime_part.rb', line 11

def body
  @body
end

#content_typeObject

Returns the value of attribute content_type.



11
12
13
# File 'lib/cabbage/email/mime_part.rb', line 11

def content_type
  @content_type
end

#headerObject

Returns the value of attribute header.



11
12
13
# File 'lib/cabbage/email/mime_part.rb', line 11

def header
  @header
end

#original_keysObject

Returns the value of attribute original_keys.



11
12
13
# File 'lib/cabbage/email/mime_part.rb', line 11

def original_keys
  @original_keys
end

#raw_sourceObject

Returns the value of attribute raw_source.



11
12
13
# File 'lib/cabbage/email/mime_part.rb', line 11

def raw_source
  @raw_source
end

Instance Method Details

#[](key) ⇒ Object



21
22
23
# File 'lib/cabbage/email/mime_part.rb', line 21

def [](key)
  @header[key]
end

#attachment?Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
# File 'lib/cabbage/email/mime_part.rb', line 29

def attachment?
  if @header.has_key?(:content_disposition) && @header[:content_disposition].start_with?("attachment")
    true
  else
    false
  end
end

#keysObject



25
26
27
# File 'lib/cabbage/email/mime_part.rb', line 25

def keys
  @header.keys
end