Class: Imap::Backup::Downloader
- Inherits:
-
Object
- Object
- Imap::Backup::Downloader
- Defined in:
- lib/imap/backup/downloader.rb
Instance Attribute Summary collapse
-
#folder ⇒ Object
readonly
Returns the value of attribute folder.
-
#multi_fetch_size ⇒ Object
readonly
Returns the value of attribute multi_fetch_size.
-
#reset_seen_flags_after_fetch ⇒ Object
readonly
Some IMAP providers, notably Apple Mail, set the ‘Seen’ flag on emails when they are fetched.
-
#serializer ⇒ Object
readonly
Returns the value of attribute serializer.
Instance Method Summary collapse
-
#initialize(folder, serializer, multi_fetch_size: 1, reset_seen_flags_after_fetch: false) ⇒ Downloader
constructor
A new instance of Downloader.
- #run ⇒ Object
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
#folder ⇒ Object (readonly)
Returns the value of attribute folder.
5 6 7 |
# File 'lib/imap/backup/downloader.rb', line 5 def folder @folder end |
#multi_fetch_size ⇒ Object (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_fetch ⇒ Object (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 |
#serializer ⇒ Object (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
#run ⇒ Object
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 |