Class: Email::Mboxrd::Message
- Inherits:
-
Object
- Object
- Email::Mboxrd::Message
- Defined in:
- lib/email/mboxrd/message.rb
Instance Attribute Summary collapse
-
#supplied_body ⇒ Object
readonly
Returns the value of attribute supplied_body.
Class Method Summary collapse
Instance Method Summary collapse
- #date ⇒ Object
- #imap_body ⇒ Object
-
#initialize(supplied_body) ⇒ Message
constructor
A new instance of Message.
- #parsed ⇒ Object
- #to_serialized ⇒ Object
Constructor Details
#initialize(supplied_body) ⇒ Message
Returns a new instance of Message.
21 22 23 |
# File 'lib/email/mboxrd/message.rb', line 21 def initialize(supplied_body) @supplied_body = supplied_body.clone end |
Instance Attribute Details
#supplied_body ⇒ Object (readonly)
Returns the value of attribute supplied_body.
7 8 9 |
# File 'lib/email/mboxrd/message.rb', line 7 def supplied_body @supplied_body end |
Class Method Details
.from_serialized(serialized) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/email/mboxrd/message.rb', line 9 def self.from_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 new(cleaned) end |
Instance Method Details
#date ⇒ Object
29 30 31 32 33 |
# File 'lib/email/mboxrd/message.rb', line 29 def date parsed.date rescue StandardError nil end |
#imap_body ⇒ Object
35 36 37 |
# File 'lib/email/mboxrd/message.rb', line 35 def imap_body supplied_body.gsub(/(?<!\r)\n/, "\r\n") end |
#parsed ⇒ Object
39 40 41 |
# File 'lib/email/mboxrd/message.rb', line 39 def parsed @parsed ||= Mail.new(supplied_body) end |
#to_serialized ⇒ Object
25 26 27 |
# File 'lib/email/mboxrd/message.rb', line 25 def to_serialized "From #{from}\n" + mboxrd_body end |