From 55c89d1166d1215e30e2cfde4c02949ba37b0919 Mon Sep 17 00:00:00 2001 From: Hocuri Date: Thu, 18 Dec 2025 16:35:39 +0100 Subject: [PATCH 1/6] fix: Don't ignore post-messages that we have seen referenced by pre-message before --- src/imap.rs | 6 +----- src/message.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/imap.rs b/src/imap.rs index e7283b8c93..41c68c8f6f 100644 --- a/src/imap.rs +++ b/src/imap.rs @@ -2284,11 +2284,7 @@ pub(crate) async fn prefetch_should_download( message_id: &str, mut flags: impl Iterator>, ) -> Result { - if message::rfc724_mid_exists(context, message_id) - .await? - .is_some() - { - markseen_on_imap_table(context, message_id).await?; + if message::downloaded_rfc724_mid_exists(context, message_id).await? { return Ok(false); } diff --git a/src/message.rs b/src/message.rs index b06fdf6087..7065be5ef5 100644 --- a/src/message.rs +++ b/src/message.rs @@ -2176,6 +2176,36 @@ pub(crate) async fn rfc724_mid_exists_ex( Ok(res) } +/// Returns [MsgId] of the most recent message with given `rfc724_mid` +/// (Message-ID header) and bool `expr` result if such messages exists in the db. +/// +/// * `expr`: SQL expression additionally passed into `SELECT`. Evaluated to `true` iff it is true +/// for all messages with the given `rfc724_mid`. +pub(crate) async fn downloaded_rfc724_mid_exists( + context: &Context, + rfc724_mid: &str, +) -> Result { + let rfc724_mid = rfc724_mid.trim_start_matches('<').trim_end_matches('>'); + if rfc724_mid.is_empty() { + warn!( + context, + "Empty rfc724_mid passed to downloaded_rfc724_mid_exists" + ); + return Ok(false); + } + + let res = context + .sql + .exists( + "SELECT COUNT(*) FROM msgs + WHERE rfc724_mid=? AND download_state<>?", + (rfc724_mid, DownloadState::Available), + ) + .await?; + + Ok(res) +} + /// Given a list of Message-IDs, returns the most relevant message found in the database. /// /// Relevance here is `(download_state == Done, index)`, where `index` is an index of Message-ID in From d8d516b6b74e09f4c91e2917153b9f6c62e4bf14 Mon Sep 17 00:00:00 2001 From: Hocuri Date: Thu, 18 Dec 2025 18:07:57 +0100 Subject: [PATCH 2/6] Update src/message.rs --- src/message.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/message.rs b/src/message.rs index 7065be5ef5..a1a3f8344f 100644 --- a/src/message.rs +++ b/src/message.rs @@ -2176,11 +2176,10 @@ pub(crate) async fn rfc724_mid_exists_ex( Ok(res) } -/// Returns [MsgId] of the most recent message with given `rfc724_mid` -/// (Message-ID header) and bool `expr` result if such messages exists in the db. -/// -/// * `expr`: SQL expression additionally passed into `SELECT`. Evaluated to `true` iff it is true -/// for all messages with the given `rfc724_mid`. +/// Returns `true` iff there is a message +/// with the given `rfc724_mid` +/// and a download state other than `DownloadState::Available` +/// (i.e. a download state where it was already tried to download the message). pub(crate) async fn downloaded_rfc724_mid_exists( context: &Context, rfc724_mid: &str, From b7bf4ea1f4fe36cf0700ba9edf6f2641214372b5 Mon Sep 17 00:00:00 2001 From: Hocuri Date: Fri, 19 Dec 2025 18:24:38 +0100 Subject: [PATCH 3/6] Fix test --- deltachat-rpc-client/tests/test_something.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/deltachat-rpc-client/tests/test_something.py b/deltachat-rpc-client/tests/test_something.py index 9f9a40e325..2a9ce407af 100644 --- a/deltachat-rpc-client/tests/test_something.py +++ b/deltachat-rpc-client/tests/test_something.py @@ -979,5 +979,7 @@ def test_large_message(acfactory) -> None: ) msg = bob.wait_for_incoming_msg() + msgs_changed_event = bob.wait_for_msgs_changed_event() + assert msg.id == msgs_changed_event.msg_id snapshot = msg.get_snapshot() assert snapshot.text == "Hello World, this message is bigger than 5 bytes" From 7ac464ef1cf2bb8865e6422eacfaf3e14edf7b89 Mon Sep 17 00:00:00 2001 From: Hocuri Date: Fri, 19 Dec 2025 18:25:21 +0100 Subject: [PATCH 4/6] refactor: Rename downloaded_rfc724_mid_exists->rfc724_mid_download_tried --- src/imap.rs | 2 +- src/message.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/imap.rs b/src/imap.rs index 41c68c8f6f..a42eba0af2 100644 --- a/src/imap.rs +++ b/src/imap.rs @@ -2284,7 +2284,7 @@ pub(crate) async fn prefetch_should_download( message_id: &str, mut flags: impl Iterator>, ) -> Result { - if message::downloaded_rfc724_mid_exists(context, message_id).await? { + if message::rfc724_mid_download_tried(context, message_id).await? { return Ok(false); } diff --git a/src/message.rs b/src/message.rs index a1a3f8344f..ee8f178b3e 100644 --- a/src/message.rs +++ b/src/message.rs @@ -2180,7 +2180,7 @@ pub(crate) async fn rfc724_mid_exists_ex( /// with the given `rfc724_mid` /// and a download state other than `DownloadState::Available` /// (i.e. a download state where it was already tried to download the message). -pub(crate) async fn downloaded_rfc724_mid_exists( +pub(crate) async fn rfc724_mid_download_tried( context: &Context, rfc724_mid: &str, ) -> Result { @@ -2188,7 +2188,7 @@ pub(crate) async fn downloaded_rfc724_mid_exists( if rfc724_mid.is_empty() { warn!( context, - "Empty rfc724_mid passed to downloaded_rfc724_mid_exists" + "Empty rfc724_mid passed to rfc724_mid_download_tried" ); return Ok(false); } From 71dc241640a168480286ee02fc151c7462b98ac8 Mon Sep 17 00:00:00 2001 From: Hocuri Date: Fri, 19 Dec 2025 18:47:53 +0100 Subject: [PATCH 5/6] python lint --- deltachat-rpc-client/tests/test_something.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deltachat-rpc-client/tests/test_something.py b/deltachat-rpc-client/tests/test_something.py index 2a9ce407af..2caa133923 100644 --- a/deltachat-rpc-client/tests/test_something.py +++ b/deltachat-rpc-client/tests/test_something.py @@ -10,7 +10,7 @@ import pytest from deltachat_rpc_client import EventType, events -from deltachat_rpc_client.const import MessageState, DownloadState +from deltachat_rpc_client.const import MessageState from deltachat_rpc_client.pytestplugin import E2EE_INFO_MSGS from deltachat_rpc_client.rpc import JsonRpcError From 50b019922534c6f33266ce83ff15b678363875d9 Mon Sep 17 00:00:00 2001 From: Hocuri Date: Fri, 19 Dec 2025 21:33:51 +0100 Subject: [PATCH 6/6] cargo fmt --- src/message.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/message.rs b/src/message.rs index ee8f178b3e..9515b9180d 100644 --- a/src/message.rs +++ b/src/message.rs @@ -2180,10 +2180,7 @@ pub(crate) async fn rfc724_mid_exists_ex( /// with the given `rfc724_mid` /// and a download state other than `DownloadState::Available` /// (i.e. a download state where it was already tried to download the message). -pub(crate) async fn rfc724_mid_download_tried( - context: &Context, - rfc724_mid: &str, -) -> Result { +pub(crate) async fn rfc724_mid_download_tried(context: &Context, rfc724_mid: &str) -> Result { let rfc724_mid = rfc724_mid.trim_start_matches('<').trim_end_matches('>'); if rfc724_mid.is_empty() { warn!(