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.
20 21 22 23 24 25 26 |
# File 'lib/imap/backup/downloader.rb', line 20 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.
7 8 9 |
# File 'lib/imap/backup/downloader.rb', line 7 def folder @folder end |
#multi_fetch_size ⇒ Object (readonly)
Returns the value of attribute multi_fetch_size.
9 10 11 |
# File 'lib/imap/backup/downloader.rb', line 9 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).
18 19 20 |
# File 'lib/imap/backup/downloader.rb', line 18 def reset_seen_flags_after_fetch @reset_seen_flags_after_fetch end |
#serializer ⇒ Object (readonly)
Returns the value of attribute serializer.
8 9 10 |
# File 'lib/imap/backup/downloader.rb', line 8 def serializer @serializer end |
Instance Method Details
#run ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/imap/backup/downloader.rb', line 28 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 |