Class: Mail::Attachment

Inherits:
Part
  • Object
show all
Defined in:
lib/mail/attachment.rb

Instance Attribute Summary

Attributes inherited from Part

#header

Instance Method Summary collapse

Methods inherited from Part

#empty?, #to_s

Constructor Details

#initialize(str_part) ⇒ Attachment

Returns a new instance of Attachment.



5
6
7
8
# File 'lib/mail/attachment.rb', line 5

def initialize(str_part)
  super(str_part)
  @binary = nil
end

Instance Method Details

#contentObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/mail/attachment.rb', line 14

def content
  unless @binary
    buffer = String.new
    body_found = false
    @part_str.each_line do |line|
      if body_found
        buffer << line
      end
      body_found = true if !body_found && line.strip.empty?
    end
    @binary = Base64.decode64(buffer)
  end
  return @binary
end

#sizeObject



10
11
12
# File 'lib/mail/attachment.rb', line 10

def size
  content.size
end