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

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

Overview

Checks that both the mailbox and its associated metadata file match

Instance Method Summary collapse

Constructor Details

#initialize(imap:, mbox:) ⇒ IntegrityChecker

Returns a new instance of IntegrityChecker.

Parameters:



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

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

Instance Method Details

#runvoid

This method returns an undefined value.

Runs the integrity check

Raises:



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
47
48
49
50
51
# File 'lib/imap/backup/serializer/integrity_checker.rb', line 22

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