Class: RMail::Serialize

Inherits:
Object
  • Object
show all
Defined in:
lib/rmail/serialize.rb

Overview

The RMail::Serialize class writes an RMail::Message object into an IO object or string. The result is a standard mail message in text form.

To do this, you pass the RMail::Message object to the RMail::Serialize object. RMail::Serialize can write into any object supporting the << method.

As a convenience, RMail::Serialize.write is a class method you can use directly:

# Write to a file
File.open('my-message', 'w') { |f|
  RMail::Serialize.write(f, message)
}

# Write to a new string string = RMail::Serialize.write('', message)

Constant Summary collapse

@@boundary_count =
0

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output, escape_from = nil) ⇒ Serialize

Initialize this Serialize object with an output stream. If escape_from is not nil, lines with a leading From are escaped.


55
56
57
58
# File 'lib/rmail/serialize.rb', line 55

def initialize(output, escape_from = nil)
  @output = output
  @escape_from = escape_from
end

Class Method Details

.write(output, message) ⇒ Object

Serialize a message into a given output object. The output object must support the << method in the same way that an IO or String object does.


69
70
71
# File 'lib/rmail/serialize.rb', line 69

def Serialize.write(output, message)
  Serialize.new(output).serialize(message)
end

Instance Method Details

#serialize(message) ⇒ Object

Serialize a given message into this object's output object.


61
62
63
64
# File 'lib/rmail/serialize.rb', line 61

def serialize(message)
  calculate_boundaries(message) if message.multipart?
  serialize_low(message)
end