diff --git a/deltachat-rpc-client/tests/test_something.py b/deltachat-rpc-client/tests/test_something.py index 9f9a40e325..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 @@ -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" diff --git a/src/imap.rs b/src/imap.rs index e7283b8c93..a42eba0af2 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::rfc724_mid_download_tried(context, message_id).await? { return Ok(false); } diff --git a/src/message.rs b/src/message.rs index b06fdf6087..9515b9180d 100644 --- a/src/message.rs +++ b/src/message.rs @@ -2176,6 +2176,32 @@ pub(crate) async fn rfc724_mid_exists_ex( Ok(res) } +/// 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 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!( + context, + "Empty rfc724_mid passed to rfc724_mid_download_tried" + ); + 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