Class: Imap::Backup::Serializer::IntegrityChecker

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(imap:, mbox:) ⇒ IntegrityChecker

Returns a new instance of IntegrityChecker.



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

def initialize(imap:, mbox:)
  @imap = imap
  @mbox = mbox
end

Instance Attribute Details

#imapObject (readonly)

Returns the value of attribute imap.



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

def imap
  @imap
end

#mboxObject (readonly)

Returns the value of attribute mbox.



10
11
12
# File 'lib/imap/backup/serializer/integrity_checker.rb', line 10

def mbox
  @mbox
end

Instance Method Details

#runObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/imap/backup/serializer/integrity_checker.rb', line 17

def run
  Logger.logger.debug(
    "[IntegrityChecker] checking '#{imap.pathname}' against '#{mbox.pathname}'"
  )
  if !imap.valid?
    message = ".imap file '#{imap.pathname}' is corrupt"
    raise Serializer::FolderIntegrityError, message
  end

  if !mbox.exist?
    message = ".mbox file '#{mbox.pathname}' is missing"
    raise Serializer::FolderIntegrityError, message
  end

  if imap.messages.empty?
    if mbox.length.positive?
      message =
        ".imap file '#{imap.pathname}' lists no messages, " \
        "but .mbox file '#{mbox.pathname}' is not empty"
      raise Serializer::FolderIntegrityError, message
    end
    return
  end

  check_offset_ordering!
  check_mbox_length!
  check_message_starts!

  nil
end