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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(folder_path) ⇒ Version2Migrator

Returns a new instance of Version2Migrator.


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

def initialize(folder_path)
  @folder_path = folder_path
end

Instance Attribute Details

#folder_pathObject (readonly)

Returns the value of attribute folder_path.


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

def folder_path
  @folder_path
end

Instance Method Details

#required?Boolean

Returns:

  • (Boolean)

11
12
13
14
15
16
17
18
19
20
# File 'lib/imap/backup/serializer/version2_migrator.rb', line 11

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

#runObject


22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/imap/backup/serializer/version2_migrator.rb', line 22

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