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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

TODO: delegate to Mboxrd::Message


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

def initialize(uid:, offset:, length:, mbox:, flags: [])
  @uid = uid
  @offset = offset
  @length = length
  @mbox = mbox
  @flags = flags.map(&:to_sym)
end

Instance Attribute Details

#flagsObject

Returns the value of attribute flags.


6
7
8
# File 'lib/imap/backup/serializer/message.rb', line 6

def flags
  @flags
end

#lengthObject (readonly)

Returns the value of attribute length.


8
9
10
# File 'lib/imap/backup/serializer/message.rb', line 8

def length
  @length
end

#mboxObject (readonly)

Returns the value of attribute mbox.


9
10
11
# File 'lib/imap/backup/serializer/message.rb', line 9

def mbox
  @mbox
end

#offsetObject (readonly)

Returns the value of attribute offset.


7
8
9
# File 'lib/imap/backup/serializer/message.rb', line 7

def offset
  @offset
end

#uidObject

Returns the value of attribute uid.


5
6
7
# File 'lib/imap/backup/serializer/message.rb', line 5

def uid
  @uid
end

Instance Method Details

#bodyObject


38
39
40
# File 'lib/imap/backup/serializer/message.rb', line 38

def body
  @body ||= message.supplied_body
end

#dateObject


46
47
48
# File 'lib/imap/backup/serializer/message.rb', line 46

def date
  @date ||= message.date
end

#imap_bodyObject


42
43
44
# File 'lib/imap/backup/serializer/message.rb', line 42

def imap_body
  @imap_body ||= message.imap_body
end

#messageObject


30
31
32
33
34
35
36
# File 'lib/imap/backup/serializer/message.rb', line 30

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

#subjectObject


50
51
52
# File 'lib/imap/backup/serializer/message.rb', line 50

def subject
  @subject ||= message.subject
end

#to_hObject


21
22
23
24
25
26
27
28
# File 'lib/imap/backup/serializer/message.rb', line 21

def to_h
  {
    uid: uid,
    offset: offset,
    length: length,
    flags: flags.map(&:to_s)
  }
end