From 0ae8663eed561161fb3fd2a6b166b001be49f63c Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Thu, 9 Jul 2020 23:32:50 +0300 Subject: [PATCH] imap: call dc_receive_imf sequentially Parallel processing of messages results in bugs such as messages sent by a new member being processed before the message that adds this member to the chat, even when it has lower UID. In this case, messages are shown as "[Unknown sender for this chat. See 'info' for more details.]", while there is a message "Member ... added" right before, because writing the information about new member to the database takes longer then reading old index from the database. --- src/imap/mod.rs | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/src/imap/mod.rs b/src/imap/mod.rs index bac253058..493e8bd0c 100644 --- a/src/imap/mod.rs +++ b/src/imap/mod.rs @@ -781,7 +781,6 @@ impl Imap { let mut last_uid = None; let mut count = 0; - let mut tasks = Vec::with_capacity(server_uids.len()); while let Some(Ok(msg)) = msgs.next().await { let server_uid = msg.uid.unwrap_or_default(); @@ -801,31 +800,17 @@ impl Imap { let context = context.clone(); let folder = folder.clone(); - let task = async_std::task::spawn(async move { - // safe, as we checked above that there is a body. - let body = msg.body().unwrap(); - let is_seen = msg.flags().any(|flag| flag == Flag::Seen); + // safe, as we checked above that there is a body. + let body = msg.body().unwrap(); + let is_seen = msg.flags().any(|flag| flag == Flag::Seen); - match dc_receive_imf(&context, &body, &folder, server_uid, is_seen).await { - Ok(_) => Some(server_uid), - Err(err) => { - warn!(context, "dc_receive_imf error: {}", err); - None - } - } - }); - tasks.push(task); - } - - for task in futures::future::join_all(tasks).await { - match task { - Some(uid) => { - last_uid = Some(uid); - } - None => { + match dc_receive_imf(&context, &body, &folder, server_uid, is_seen).await { + Ok(_) => last_uid = Some(server_uid), + Err(err) => { + warn!(context, "dc_receive_imf error: {}", err); read_errors += 1; } - } + }; } if count != server_uids.len() {