Class: Imap::Backup::Downloader

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

Instance Attribute Summary collapse

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.



18
19
20
21
22
23
24
# File 'lib/imap/backup/downloader.rb', line 18

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 Attribute Details

#folderObject (readonly)

Returns the value of attribute folder.



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

def folder
  @folder
end

#multi_fetch_sizeObject (readonly)

Returns the value of attribute multi_fetch_size.



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

def multi_fetch_size
  @multi_fetch_size
end

#reset_seen_flags_after_fetchObject (readonly)

Some IMAP providers, notably Apple Mail, set the ‘Seen’ flag on emails when they are fetched. By setting ‘:reset_seen_flags_after_fetch`, a workaround is activated which checks which emails are ’unseen’ before and after the fetch, and removes the ‘Seen’ flag from those which have changed. As this check is susceptible to ‘race conditions’, i.e. when a different client sets the ‘Seen’ flag while imap-backup is fetching, it is best to only use it when required (i.e. for IMAP providers which always mark messages as ‘Seen’ when accessed).



16
17
18
# File 'lib/imap/backup/downloader.rb', line 16

def reset_seen_flags_after_fetch
  @reset_seen_flags_after_fetch
end

#serializerObject (readonly)

Returns the value of attribute serializer.



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

def serializer
  @serializer
end

Instance Method Details

#runObject



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/imap/backup/downloader.rb', line 26

def run
  debug "#{uids.count} new messages"

  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
end