Class: Imap::Backup::Migrator

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

Overview

Copies a folder of backed-up emails to an online folder

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Migrator.



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

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

Instance Method Details

#runvoid

This method returns an undefined value.

Runs the migration



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

def run
  count = serializer.uids.count
  folder.create
  folder.clear if reset

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

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

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