Class: Juno::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/juno/message.rb

Instance Method Summary collapse

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

#bodyObject



13
14
15
# File 'lib/juno/message.rb', line 13

def body
  @body
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/juno/message.rb', line 46

def eql?(other)
  self == other
end

#hashObject



42
43
44
# File 'lib/juno/message.rb', line 42

def hash
  to_s.hash
end

#headersObject



9
10
11
# File 'lib/juno/message.rb', line 9

def headers
  @headers
end

#to_emlObject



17
18
19
# File 'lib/juno/message.rb', line 17

def to_eml
  [@headers.join(?/), @body].join(?/)
end

#to_mboxObject



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_sObject



21
22
23
# File 'lib/juno/message.rb', line 21

def to_s
  to_eml
end