Class: Sisimai::Mail::Memory

Inherits:
Object
  • Object
show all
Defined in:
lib/sisimai/mail/memory.rb

Overview

Sisimai::Mail::Memory is a class for reading an email string

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv1) ⇒ Sisimai::Mail::Memory

Constructor of Sisimai::Mail::Memory

Parameters:

  • argv1 (String)

    Entire email string



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/sisimai/mail/memory.rb', line 16

def initialize(argv1)
  raise 'is not a String' if argv1.is_a?(::String) == false
  raise 'is empty'        if argv1.empty?

  @path    = '<MEMORY>'
  @size    = argv1.size
  @payload = []
  @offset  = 0

  if argv1.start_with?('From ')
    # UNIX mbox
    @payload = argv1.scrub().split(/^From /).map! { |e| e = 'From ' + e }
    @payload.shift
  else
    @payload = [argv1]
  end
end

Instance Attribute Details

#offsetObject

Returns the value of attribute offset.



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

def offset
  @offset
end

#pathObject (readonly)

:path [String] Fixed string “<MEMORY>” :size [Integer] data size of the email text :payload [Array] Entire bounce mail message :offset [Integer] Index of “:payload”



9
10
11
# File 'lib/sisimai/mail/memory.rb', line 9

def path
  @path
end

#payloadObject

Returns the value of attribute payload.



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

def payload
  @payload
end

#sizeObject (readonly)

:path [String] Fixed string “<MEMORY>” :size [Integer] data size of the email text :payload [Array] Entire bounce mail message :offset [Integer] Index of “:payload”



9
10
11
# File 'lib/sisimai/mail/memory.rb', line 9

def size
  @size
end

Instance Method Details

#readString

Memory reader, works as an iterator.

Returns:

  • (String)

    Contents of a bounce mail



36
37
38
39
40
# File 'lib/sisimai/mail/memory.rb', line 36

def read
  return nil if self.payload.empty?
  self.offset += 1
  return self.payload.shift
end