Class: Imap::Backup::Serializer::Version2Migrator

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

Overview

Migrates serialized folder metadata from the version 2 format to the version 3 format

Instance Method Summary collapse

Constructor Details

#initialize(folder_path) ⇒ Version2Migrator

Returns a new instance of Version2Migrator.

Parameters:

  • folder_path (String)

    the base pathv(without extension) of the folder backup



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

def initialize(folder_path)
  @folder_path = folder_path
end

Instance Method Details

#required?Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
25
26
# File 'lib/imap/backup/serializer/version2_migrator.rb', line 17

def required?
  return false if !mbox_exists?
  return false if !imap_exists?
  return false if !imap_data
  return false if imap_data[:version] != 2
  return false if !imap_data[:uid_validity]
  return false if !uids.is_a?(Array)

  true
end

#runBoolean

Runs the migration

Returns:

  • (Boolean)

    whether the migration was run



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/imap/backup/serializer/version2_migrator.rb', line 30

def run
  return false if !required?

  messages = message_uids_and_lengths

  return false if !messages

  imap.delete
  imap.uid_validity = imap_data[:uid_validity]
  messages.map { |m| imap.append(m[:uid], m[:length]) }

  true
end