Class: Email::Mboxrd::Message

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/email/mboxrd/message.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(supplied_body) ⇒ Message

Returns a new instance of Message.


29
30
31
# File 'lib/email/mboxrd/message.rb', line 29

def initialize(supplied_body)
  @supplied_body = supplied_body.clone
end

Instance Attribute Details

#supplied_bodyObject (readonly)

Returns the value of attribute supplied_body.


11
12
13
# File 'lib/email/mboxrd/message.rb', line 11

def supplied_body
  @supplied_body
end

Class Method Details

.clean_serialized(serialized) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
# File 'lib/email/mboxrd/message.rb', line 13

def self.clean_serialized(serialized)
  cleaned = serialized.gsub(/^>(>*From)/, "\\1")
  # Serialized messages in this format *should* start with a line
  #   From xxx yy zz
  # rubocop:disable Style/IfUnlessModifier
  if cleaned.start_with?("From ")
    cleaned = cleaned.sub(/^From .*[\r\n]*/, "")
  end
  # rubocop:enable Style/IfUnlessModifier
  cleaned
end

.from_serialized(serialized) ⇒ Object


25
26
27
# File 'lib/email/mboxrd/message.rb', line 25

def self.from_serialized(serialized)
  new(clean_serialized(serialized))
end

Instance Method Details

#dateObject


37
38
39
40
41
# File 'lib/email/mboxrd/message.rb', line 37

def date
  parsed.date
rescue StandardError
  nil
end

#imap_bodyObject


43
44
45
# File 'lib/email/mboxrd/message.rb', line 43

def imap_body
  supplied_body.gsub(/(?<!\r)\n/, "\r\n")
end

#to_serializedObject


33
34
35
# File 'lib/email/mboxrd/message.rb', line 33

def to_serialized
  "From #{from}\n" + mboxrd_body
end