Class: Imap::Backup::Serializer::Message
- Inherits:
-
Object
- Object
- Imap::Backup::Serializer::Message
- Extended by:
- Forwardable
- Defined in:
- lib/imap/backup/serializer/message.rb
Overview
Represents a stored message
Instance Attribute Summary collapse
-
#flags ⇒ Array[Symbol]
The message’s flags.
-
#length ⇒ Integer
readonly
The length of the message (as stored on disk).
-
#offset ⇒ Integer
readonly
The start of the message inside the mailbox file.
-
#uid ⇒ Integer
The message’s UID.
Instance Method Summary collapse
-
#initialize(uid:, offset:, length:, mbox:, flags: []) ⇒ Message
constructor
A new instance of Message.
-
#message ⇒ String
Reads the message text and returns the original form.
-
#to_h ⇒ Hash
The message metadata.
Constructor Details
#initialize(uid:, offset:, length:, mbox:, flags: []) ⇒ Message
Returns a new instance of Message.
29 30 31 32 33 34 35 |
# File 'lib/imap/backup/serializer/message.rb', line 29 def initialize(uid:, offset:, length:, mbox:, flags: []) @uid = uid @offset = offset @length = length @mbox = mbox @flags = flags.map(&:to_sym) end |
Instance Attribute Details
#flags ⇒ Array[Symbol]
Returns the message’s flags.
11 12 13 |
# File 'lib/imap/backup/serializer/message.rb', line 11 def flags @flags end |
#length ⇒ Integer (readonly)
Returns the length of the message (as stored on disk).
13 14 15 |
# File 'lib/imap/backup/serializer/message.rb', line 13 def length @length end |
#offset ⇒ Integer (readonly)
Returns the start of the message inside the mailbox file.
15 16 17 |
# File 'lib/imap/backup/serializer/message.rb', line 15 def offset @offset end |
#uid ⇒ Integer
Returns the message’s UID.
17 18 19 |
# File 'lib/imap/backup/serializer/message.rb', line 17 def uid @uid end |
Instance Method Details
#message ⇒ String
Reads the message text and returns the original form
49 50 51 52 53 54 55 |
# File 'lib/imap/backup/serializer/message.rb', line 49 def @message = begin raw = mbox.read(offset, length) Email::Mboxrd::Message.from_serialized(raw) end end |
#to_h ⇒ Hash
Returns the message metadata.
38 39 40 41 42 43 44 45 |
# File 'lib/imap/backup/serializer/message.rb', line 38 def to_h { uid: uid, offset: offset, length: length, flags: flags.map(&:to_s) } end |