Class: Imap::Backup::Email::Mboxrd::Message
- Inherits:
-
Object
- Object
- Imap::Backup::Email::Mboxrd::Message
- Defined in:
- lib/imap/backup/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.
- #subject ⇒ Object
- #to_serialized ⇒ Object
Constructor Details
#initialize(supplied_body) ⇒ Message
Returns a new instance of Message.
28 29 30 |
# File 'lib/imap/backup/email/mboxrd/message.rb', line 28 def initialize(supplied_body) @supplied_body = supplied_body.clone end |
Instance Attribute Details
#supplied_body ⇒ Object (readonly)
Returns the value of attribute supplied_body.
26 27 28 |
# File 'lib/imap/backup/email/mboxrd/message.rb', line 26 def supplied_body @supplied_body end |
Class Method Details
.clean_serialized(serialized) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/imap/backup/email/mboxrd/message.rb', line 10 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
22 23 24 |
# File 'lib/imap/backup/email/mboxrd/message.rb', line 22 def self.from_serialized(serialized) new(clean_serialized(serialized)) end |
Instance Method Details
#date ⇒ Object
38 39 40 41 42 |
# File 'lib/imap/backup/email/mboxrd/message.rb', line 38 def date parsed.date rescue StandardError nil end |
#imap_body ⇒ Object
48 49 50 |
# File 'lib/imap/backup/email/mboxrd/message.rb', line 48 def imap_body supplied_body.gsub(/(?<!\r)\n/, "\r\n") end |
#subject ⇒ Object
44 45 46 |
# File 'lib/imap/backup/email/mboxrd/message.rb', line 44 def subject parsed.subject end |
#to_serialized ⇒ Object
32 33 34 35 36 |
# File 'lib/imap/backup/email/mboxrd/message.rb', line 32 def to_serialized from_line = "From #{from}\n" body = mboxrd_body.dup.force_encoding(Encoding::UTF_8) from_line + body end |