Class: Imap::Backup::Email::Mboxrd::Message
- Inherits:
-
Object
- Object
- Imap::Backup::Email::Mboxrd::Message
- Defined in:
- lib/imap/backup/email/mboxrd/message.rb
Overview
Handles serialization and deserialization of messages
Instance Attribute Summary collapse
-
#supplied_body ⇒ String
readonly
The original message body.
Class Method Summary collapse
-
.clean_serialized(serialized) ⇒ String
The message without the initial ‘From ’ line and with one level of ‘>’ quoting removed from other lines that start with ‘From’.
-
.from_serialized(serialized) ⇒ Message
The original message.
Instance Method Summary collapse
-
#date ⇒ Date?
The date of the message.
-
#imap_body ⇒ String
The original message ready for transmission to an IMAP server.
-
#initialize(supplied_body) ⇒ Message
constructor
A new instance of Message.
-
#subject ⇒ String
The message’s subject line.
-
#to_serialized ⇒ String
The message with an initial ‘From ADDRESS’ line.
Constructor Details
#initialize(supplied_body) ⇒ Message
Returns a new instance of Message.
38 39 40 |
# File 'lib/imap/backup/email/mboxrd/message.rb', line 38 def initialize(supplied_body) @supplied_body = supplied_body.clone end |
Instance Attribute Details
#supplied_body ⇒ String (readonly)
Returns the original message body.
36 37 38 |
# File 'lib/imap/backup/email/mboxrd/message.rb', line 36 def supplied_body @supplied_body end |
Class Method Details
.clean_serialized(serialized) ⇒ String
Returns The message without the initial ‘From ’ line and with one level of ‘>’ quoting removed from other lines that start with ‘From’.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/imap/backup/email/mboxrd/message.rb', line 16 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) ⇒ Message
Returns the original message.
31 32 33 |
# File 'lib/imap/backup/email/mboxrd/message.rb', line 31 def self.from_serialized(serialized) new(clean_serialized(serialized)) end |
Instance Method Details
#date ⇒ Date?
Returns the date of the message.
50 51 52 53 54 |
# File 'lib/imap/backup/email/mboxrd/message.rb', line 50 def date parsed.date rescue StandardError nil end |
#imap_body ⇒ String
Returns the original message ready for transmission to an IMAP server.
62 63 64 |
# File 'lib/imap/backup/email/mboxrd/message.rb', line 62 def imap_body supplied_body.gsub(/(?<!\r)\n/, "\r\n") end |
#subject ⇒ String
Returns the message’s subject line.
57 58 59 |
# File 'lib/imap/backup/email/mboxrd/message.rb', line 57 def subject parsed.subject end |
#to_serialized ⇒ String
Returns the message with an initial ‘From ADDRESS’ line.
43 44 45 46 47 |
# File 'lib/imap/backup/email/mboxrd/message.rb', line 43 def to_serialized from_line = "From #{from}\n" body = mboxrd_body.dup.force_encoding(Encoding::UTF_8) from_line + body end |