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.



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

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

Instance Attribute Details

#folderObject (readonly)

Returns the value of attribute folder.



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

def folder
  @folder
end

#resetObject (readonly)

Returns the value of attribute reset.



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

def reset
  @reset
end

#serializerObject (readonly)

Returns the value of attribute serializer.



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

def serializer
  @serializer
end

Instance Method Details

#runObject



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

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