Class: Imap::Backup::Migrator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(serializer, folder, reset: false) ⇒ Migrator

Returns a new instance of Migrator.


7
8
9
10
11
# File 'lib/imap/backup/migrator.rb', line 7

def initialize(serializer, folder, reset: false)
  @folder = folder
  @reset = reset
  @serializer = serializer
end

Instance Attribute Details

#folderObject (readonly)

Returns the value of attribute folder.


3
4
5
# File 'lib/imap/backup/migrator.rb', line 3

def folder
  @folder
end

#resetObject (readonly)

Returns the value of attribute reset.


4
5
6
# File 'lib/imap/backup/migrator.rb', line 4

def reset
  @reset
end

#serializerObject (readonly)

Returns the value of attribute serializer.


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

def serializer
  @serializer
end

Instance Method Details

#runObject


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/imap/backup/migrator.rb', line 13

def run
  count = serializer.uids.count
  folder.create
  ensure_destination_empty!

  Logger.logger.debug "[#{folder.name}] #{count} to migrate"
  serializer.each_message(serializer.uids).with_index do |(uid, message), i|
    next if message.nil?

    log_prefix = "[#{folder.name}] uid: #{uid} (#{i + 1}/#{count}) -"
    Logger.logger.debug(
      "#{log_prefix} #{message.supplied_body.size} bytes"
    )

    begin
      folder.append(message)
    rescue StandardError => e
      Logger.logger.warn "#{log_prefix} append error: #{e}"
    end
  end
end