From 718ac726473ea1eeceebea6c8b68cc71324b7791 Mon Sep 17 00:00:00 2001 From: jikstra Date: Mon, 8 Jul 2019 20:48:38 +0200 Subject: [PATCH] Get body size on imap prefetches --- src/dc_job.rs | 1 + src/imap.rs | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/dc_job.rs b/src/dc_job.rs index b665b1acd..0cbbbccb4 100644 --- a/src/dc_job.rs +++ b/src/dc_job.rs @@ -1023,6 +1023,7 @@ pub unsafe fn dc_perform_imap_fetch(context: &Context) { ); return; } + println!("Test123"); dc_log_info( context, 0i32, diff --git a/src/imap.rs b/src/imap.rs index 0e436d985..2e8067807 100644 --- a/src/imap.rs +++ b/src/imap.rs @@ -19,7 +19,7 @@ pub const DC_ALREADY_DONE: usize = 2; pub const DC_RETRY_LATER: usize = 1; pub const DC_FAILED: usize = 0; -const PREFETCH_FLAGS: &'static str = "(UID ENVELOPE)"; +const PREFETCH_FLAGS: &'static str = "(UID ENVELOPE RFC822.SIZE)"; const BODY_FLAGS: &'static str = "(FLAGS BODY.PEEK[])"; const FETCH_FLAGS: &'static str = "(FLAGS)"; @@ -609,10 +609,12 @@ impl Imap { // get any more. if IDLE is called directly after, there is only a small chance that // messages are missed and delayed until the next IDLE call loop { + println!("xxx"); if self.fetch_from_single_folder(context, watch_folder) == 0 { break; } } + println!("xxx2"); 1 } else { 0 @@ -713,6 +715,7 @@ impl Imap { } fn fetch_from_single_folder>(&self, context: &Context, folder: S) -> usize { + println!("fetch_from_single_folder"); if !self.is_connected() { info!( context, @@ -786,7 +789,6 @@ impl Imap { } else { return 0; }; - last_seen_uid = list[0].uid.unwrap_or_else(|| 0); // if the UIDVALIDITY has _changed_, decrease lastseenuid by one to avoid gaps (well add 1 below @@ -810,6 +812,7 @@ impl Imap { let mut read_errors = 0; let mut new_last_seen_uid = 0; + println!("hereee!"); let list = if let Some(ref mut session) = self.session.lock().unwrap().0 { // fetch messages with larger UID than the last one seen // (`UID FETCH lastseenuid+1:*)`, see RFC 4549 @@ -827,6 +830,8 @@ impl Imap { // go through all mails in folder (this is typically _fast_ as we already have the whole list) for msg in &list { + let size = msg.size.unwrap_or_else(|| 0); + println!("size: {}", size); let cur_uid = msg.uid.unwrap_or_else(|| 0); if cur_uid > last_seen_uid { read_cnt += 1; @@ -935,6 +940,7 @@ impl Imap { let set = format!("{}", server_uid); let msgs = if let Some(ref mut session) = self.session.lock().unwrap().0 { + match session.uid_fetch(set, BODY_FLAGS) { Ok(msgs) => msgs, Err(err) => {