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
permalink #initialize(uid:, offset:, length:, mbox:, flags: []) ⇒ Message
Returns a new instance of Message.
31 32 33 34 35 36 37 |
# File 'lib/imap/backup/serializer/message.rb', line 31 def initialize(uid:, offset:, length:, mbox:, flags: []) @uid = uid @offset = offset @length = length @mbox = mbox @flags = flags.map(&:to_sym) end |
Instance Attribute Details
permalink #flags ⇒ Array[Symbol]
Returns the message’s flags.
13 14 15 |
# File 'lib/imap/backup/serializer/message.rb', line 13 def flags @flags end |
permalink #length ⇒ Integer (readonly)
Returns the length of the message (as stored on disk).
15 16 17 |
# File 'lib/imap/backup/serializer/message.rb', line 15 def length @length end |
permalink #offset ⇒ Integer (readonly)
Returns the start of the message inside the mailbox file.
17 18 19 |
# File 'lib/imap/backup/serializer/message.rb', line 17 def offset @offset end |
permalink #uid ⇒ Integer
Returns the message’s UID.
19 20 21 |
# File 'lib/imap/backup/serializer/message.rb', line 19 def uid @uid end |
Instance Method Details
permalink #message ⇒ String
Reads the message text and returns the original form
51 52 53 54 55 56 57 |
# File 'lib/imap/backup/serializer/message.rb', line 51 def @message = begin raw = mbox.read(offset, length) Email::Mboxrd::Message.from_serialized(raw) end end |
permalink #to_h ⇒ Hash
Returns the message metadata.
40 41 42 43 44 45 46 47 |
# File 'lib/imap/backup/serializer/message.rb', line 40 def to_h { uid: uid, offset: offset, length: length, flags: flags.map(&:to_s) } end |