Class: Juno::Message
- Inherits:
-
Object
- Object
- Juno::Message
- Defined in:
- lib/juno/message.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
- #body ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
- #headers ⇒ Object
-
#initialize(headers, body) ⇒ Message
constructor
A new instance of Message.
- #to_eml ⇒ Object
- #to_mbox ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(headers, body) ⇒ Message
Returns a new instance of Message.
4 5 6 7 |
# File 'lib/juno/message.rb', line 4 def initialize(headers, body) @headers = headers @body = body end |
Instance Method Details
#==(other) ⇒ Object
38 39 40 |
# File 'lib/juno/message.rb', line 38 def ==(other) self.headers == other.headers && self.body == other.body end |
#body ⇒ Object
13 14 15 |
# File 'lib/juno/message.rb', line 13 def body @body end |
#eql?(other) ⇒ Boolean
46 47 48 |
# File 'lib/juno/message.rb', line 46 def eql?(other) self == other end |
#hash ⇒ Object
42 43 44 |
# File 'lib/juno/message.rb', line 42 def hash to_s.hash end |
#headers ⇒ Object
9 10 11 |
# File 'lib/juno/message.rb', line 9 def headers @headers end |
#to_eml ⇒ Object
17 18 19 |
# File 'lib/juno/message.rb', line 17 def to_eml [@headers.join(?/), @body].join(?/) end |
#to_mbox ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/juno/message.rb', line 25 def to_mbox # a message in mbox is delineated by a line that starts with "From " from_line = headers.detect{|f| f.match(/^From:/)}.sub(/^From:\s+/, 'From ') # We need to escape any lines that start with "From " in the body, # so that they aren't mistaken for the start of a new message. # To prevent ambiguity, we also alter any body lines that start # with ">From" to ">>From". escaped_body = body.gsub(/^(>?From )/, '>\1') [from_line, headers.join($/), escaped_body].join($/) end |
#to_s ⇒ Object
21 22 23 |
# File 'lib/juno/message.rb', line 21 def to_s to_eml end |