Skip to content

Commit 67a75a4

Browse files
committed
fix: Fail receive_imf to not tombstone self-MDN if original message isn't found
1 parent d014255 commit 67a75a4

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

src/receive_imf.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,6 +2031,7 @@ async fn add_parts(
20312031
}
20322032
}
20332033
if !mime_parser.incoming && !context.get_config_bool(Config::TeamProfile).await? {
2034+
let mut missing_rfc724_mid = None;
20342035
let mut updated_chats = BTreeMap::new();
20352036
let mut archived_chats_maybe_noticed = false;
20362037
for report in &mime_parser.mdn_reports {
@@ -2040,6 +2041,7 @@ async fn add_parts(
20402041
.chain(&report.additional_message_ids)
20412042
{
20422043
let Some(msg_id) = rfc724_mid_exists(context, msg_rfc724_mid).await? else {
2044+
missing_rfc724_mid.get_or_insert(msg_rfc724_mid.as_str());
20432045
continue;
20442046
};
20452047
let Some(msg) = Message::load_from_db_optional(context, msg_id).await? else {
@@ -2098,6 +2100,11 @@ chat_id=? AND
20982100
if archived_chats_maybe_noticed {
20992101
context.on_archived_chats_maybe_noticed();
21002102
}
2103+
ensure!(
2104+
missing_rfc724_mid.is_none(),
2105+
"Self-MDN: {} not found (SKIP_DEVICE_MSG)",
2106+
missing_rfc724_mid.unwrap_or(""),
2107+
);
21012108
}
21022109

21032110
let hidden = mime_parser.parts.iter().all(|part| part.is_reaction);

src/receive_imf/receive_imf_tests.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ use crate::contact;
1414
use crate::imap::prefetch_should_download;
1515
use crate::imex::{ImexMode, imex};
1616
use crate::key;
17+
use crate::message::markseen_msgs;
1718
use crate::securejoin::get_securejoin_qr;
19+
use crate::smtp;
1820
use crate::test_utils::{
1921
TestContext, TestContextManager, alice_keypair, get_chat_msg, mark_as_verified,
2022
};
@@ -2655,6 +2657,32 @@ async fn test_read_receipts_dont_unmark_bots() -> Result<()> {
26552657
Ok(())
26562658
}
26572659

2660+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
2661+
async fn test_self_mdn_before_msg() -> Result<()> {
2662+
let mut tcm = TestContextManager::new();
2663+
let alice = &tcm.alice().await;
2664+
let bob = &tcm.bob().await;
2665+
let bob2 = &tcm.bob().await;
2666+
let alice_chat = alice.create_chat(bob).await;
2667+
2668+
let sent = alice.send_text(alice_chat.id, "hi").await;
2669+
let msg = bob.recv_msg(&sent).await;
2670+
msg.chat_id.accept(bob).await?;
2671+
markseen_msgs(bob, vec![msg.id]).await?;
2672+
smtp::queue_mdn(bob).await?;
2673+
let sent_mdn = bob.pop_sent_msg().await;
2674+
2675+
let Err(err) = receive_imf(bob2, sent_mdn.payload().as_bytes(), false).await else {
2676+
unreachable!();
2677+
};
2678+
assert!(format!("{err:#}").contains("(SKIP_DEVICE_MSG)"));
2679+
let msg = bob2.recv_msg(&sent).await;
2680+
assert_eq!(msg.get_state(), MessageState::InFresh);
2681+
bob2.recv_msg_trash(&sent_mdn).await;
2682+
assert_eq!(msg.id.get_state(bob2).await?, MessageState::InSeen);
2683+
Ok(())
2684+
}
2685+
26582686
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
26592687
async fn test_gmx_forwarded_msg() -> Result<()> {
26602688
let t = TestContext::new_alice().await;

0 commit comments

Comments
 (0)