Class: BulkMail::Message
- Inherits:
-
Object
- Object
- BulkMail::Message
- Defined in:
- lib/bulkmail/message.rb
Overview
Direct Known Subclasses
Defined Under Namespace
Classes: MultiPart
Constant Summary collapse
- DEFAULT_HEADERS =
{ :mime_version => '1.0' }
- PLAIN =
'text/plain; charset=UTF-8'.freeze
- HTML =
'text/html; charset=UTF-8'.freeze
- LINE_BREAK =
"\r\n"
- HEADER_FMT =
"%s: %s\r\n".freeze
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#headers ⇒ Object
Returns the value of attribute headers.
Class Method Summary collapse
-
.format_headers(headers) ⇒ Object
Formats the message headers into a string.
Instance Method Summary collapse
-
#initialize(headers, body) ⇒ Message
constructor
Creates a new message, including the default headers in the message headers.
-
#to_s ⇒ Object
Composes the header and body into a message string.
Constructor Details
#initialize(headers, body) ⇒ Message
Creates a new message, including the default headers in the message headers.
33 34 35 36 |
# File 'lib/bulkmail/message.rb', line 33 def initialize(headers, body) @headers = DEFAULT_HEADERS.merge(headers) @body = body end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
23 24 25 |
# File 'lib/bulkmail/message.rb', line 23 def body @body end |
#headers ⇒ Object
Returns the value of attribute headers.
23 24 25 |
# File 'lib/bulkmail/message.rb', line 23 def headers @headers end |
Class Method Details
.format_headers(headers) ⇒ Object
Formats the message headers into a string.
42 43 44 45 46 47 48 49 50 |
# File 'lib/bulkmail/message.rb', line 42 def self.format_headers(headers) headers.inject('') do |m, kv| if kv[1] m << (HEADER_FMT % [kv[0].to_header, kv[1]]) else m end end end |
Instance Method Details
#to_s ⇒ Object
Composes the header and body into a message string.
53 54 55 56 57 58 |
# File 'lib/bulkmail/message.rb', line 53 def to_s msg = Message.format_headers(@headers) msg << LINE_BREAK msg << body msg end |