fix: trash early MDNs that reference no message

A report referencing no message can never be applied to one,
so it must not create a contact, a chat or a `last_seen` update
on its way to the trash.
This commit is contained in:
holger krekel
2026-08-22 02:49:03 +02:00
parent 08b2374fcf
commit 370cc5c1fd
3 changed files with 62 additions and 0 deletions

View File

@@ -506,6 +506,18 @@ pub(crate) async fn receive_imf_inner(
Ok(mime_parser) => mime_parser,
};
if !mime_parser.mdn_reports.is_empty()
&& mime_parser.mdn_reports.iter().all(|report| {
report.original_message_id.is_none() && report.additional_message_ids.is_empty()
})
{
// A report naming no message can never be applied to one,
// and nothing else should come out of it: no contact, no chat,
// and no `last_seen` update lighting up an online dot.
info!(context, "Report without message reference (TRASH).");
return trash().await;
}
if !mime_parser.was_encrypted()
&& mime_parser.get_header(HeaderDef::SecureJoin).is_none()
&& context.get_config_bool(Config::ForceEncryption).await?

View File

@@ -271,6 +271,33 @@ async fn test_mdn_and_alias() -> Result<()> {
Ok(())
}
/// Tests that an MDN referencing no message is trashed early:
/// there is nothing it could ever be applied to,
/// so it must not create a contact or a chat on the way.
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_mdn_without_message_reference() -> Result<()> {
let alice = TestContext::new_alice().await;
alice
.set_config_bool(Config::ForceEncryption, false)
.await?;
let contacts = Contact::get_real_cnt(&alice).await?;
let chatlist_len = Chatlist::try_load(&alice, 0, None, None).await?.len();
receive_imf(
&alice,
include_bytes!("../../test-data/message/mdn_without_message_reference.eml"),
false,
)
.await?;
assert_eq!(Contact::get_real_cnt(&alice).await?, contacts);
assert_eq!(
Chatlist::try_load(&alice, 0, None, None).await?.len(),
chatlist_len
);
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_no_from() {
// if there is no from given, from_id stays 0 which is just fine. These messages

View File

@@ -0,0 +1,23 @@
From: bob@example.net
To: alice@example.org
Subject: message opened
Date: Sun, 22 Mar 2020 23:37:57 +0000
Message-ID: <aranudiaerudiaduiaertd@example.com>
Content-Type: multipart/report; report-type=disposition-notification; boundary="SNIPP"
--SNIPP
Content-Type: text/plain; charset=utf-8
Read receipts do not guarantee sth. was read.
--SNIPP
Content-Type: message/disposition-notification
Original-Recipient: rfc822;bob@example.net
Final-Recipient: rfc822;bob@example.net
Disposition: automatic-action/MDN-sent-automatically; processed
--SNIPP--