Class: Imap::Backup::Serializer::Message

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/imap/backup/serializer/message.rb

Overview

Represents a stored message

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uid:, offset:, length:, mbox:, flags: []) ⇒ Message

Returns a new instance of Message.

Parameters:

  • uid (Integer)

    the message’s UID

  • offset (Integer)

    the start of the message inside the mailbox file

  • length (Integer)

    the length of the message (as stored on disk)

  • mbox (Serializer::Mbox)

    the mailbox containing the message

  • flags (Array[Symbol]) (defaults to: [])

    the message’s flags



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

#flagsArray[Symbol]

Returns the message’s flags.

Returns:

  • (Array[Symbol])

    the message’s flags



13
14
15
# File 'lib/imap/backup/serializer/message.rb', line 13

def flags
  @flags
end

#lengthInteger (readonly)

Returns the length of the message (as stored on disk).

Returns:

  • (Integer)

    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

#offsetInteger (readonly)

Returns the start of the message inside the mailbox file.

Returns:

  • (Integer)

    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

#uidInteger

Returns the message’s UID.

Returns:

  • (Integer)

    the message’s UID



19
20
21
# File 'lib/imap/backup/serializer/message.rb', line 19

def uid
  @uid
end

Instance Method Details

#messageString

Reads the message text and returns the original form

Returns:

  • (String)

    the message



51
52
53
54
55
56
57
# File 'lib/imap/backup/serializer/message.rb', line 51

def message
  @message =
    begin
      raw = mbox.read(offset, length)
      Email::Mboxrd::Message.from_serialized(raw)
    end
end

#to_hHash

Returns the message metadata.

Returns:

  • (Hash)

    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