Class: Imap::Backup::Downloader

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

Overview

Downloads as yet undownloaded emails from an account’s server

Defined Under Namespace

Classes: MultiFetchFailedError

Instance Method Summary collapse

Constructor Details

#initialize(folder, serializer, multi_fetch_size: 1, reset_seen_flags_after_fetch: false) ⇒ Downloader

Returns a new instance of Downloader.



11
12
13
14
15
16
17
# File 'lib/imap/backup/downloader.rb', line 11

def initialize(folder, serializer, multi_fetch_size: 1, reset_seen_flags_after_fetch: false)
  @folder = folder
  @serializer = serializer
  @multi_fetch_size = multi_fetch_size
  @reset_seen_flags_after_fetch = reset_seen_flags_after_fetch
  @uids = nil
end

Instance Method Details

#runvoid

This method returns an undefined value.

Runs the downloader



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

def run
  info("#{uids.count} new messages") if uids.any?

  uids.each_slice(multi_fetch_size).with_index do |block, i|
    multifetch_failed = download_block(block, i)
    raise MultiFetchFailedError if multifetch_failed
  end
rescue MultiFetchFailedError
  @count = nil
  @multi_fetch_size = 1
  @uids = nil
  retry
rescue Net::IMAP::ByeResponseError
  folder.client.reconnect
  retry
end