From 0131980372eb4199d0c3fb9c66fd0cba6fe36cf7 Mon Sep 17 00:00:00 2001 From: Hocuri Date: Thu, 23 Jul 2020 11:57:54 +0200 Subject: [PATCH] Fix #1739 LastSubject should not be updated for read receipt (#1744) * Fix #1739 LastSubject should not be updated for read receipt * . --- src/dc_receive_imf.rs | 20 +++++++++-------- src/mimefactory.rs | 50 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 10 deletions(-) diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index d18269e64..17a6c6751 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -867,15 +867,17 @@ async fn add_parts( chat.update_param(context).await?; Ok(()) } - update_last_subject(context, chat_id, mime_parser) - .await - .unwrap_or_else(|e| { - warn!( - context, - "Could not update LastSubject of chat: {}", - e.to_string() - ) - }); + if !is_mdn { + update_last_subject(context, chat_id, mime_parser) + .await + .unwrap_or_else(|e| { + warn!( + context, + "Could not update LastSubject of chat: {}", + e.to_string() + ) + }); + } Ok(()) } diff --git a/src/mimefactory.rs b/src/mimefactory.rs index bac979fc4..55ca51ee9 100644 --- a/src/mimefactory.rs +++ b/src/mimefactory.rs @@ -1417,6 +1417,54 @@ mod tests { .as_bytes(), ) .await; + + // 5. Receive an mdn (read receipt) and make sure the mdn's subject is not used + let t = TestContext::new_alice().await; + dc_receive_imf( + &t.ctx, + b"From: alice@example.com\n\ + To: Charlie \n\ + Subject: Hello, Charlie\n\ + Chat-Version: 1.0\n\ + Message-ID: <2893@example.com>\n\ + Date: Sun, 22 Mar 2020 22:37:56 +0000\n\ + \n\ + hello\n", + "INBOX", + 1, + false, + ) + .await + .unwrap(); + let new_msg = incoming_msg_to_reply_msg(b"From: charlie@example.com\n\ + To: alice@example.com\n\ + Subject: message opened\n\ + Date: Sun, 22 Mar 2020 23:37:57 +0000\n\ + Chat-Version: 1.0\n\ + Message-ID: \n\ + Content-Type: multipart/report; report-type=disposition-notification; boundary=\"SNIPP\"\n\ + \n\ + \n\ + --SNIPP\n\ + Content-Type: text/plain; charset=utf-8\n\ + \n\ + Read receipts do not guarantee sth. was read.\n\ + \n\ + \n\ + --SNIPP\n\ + Content-Type: message/disposition-notification\n\ + \n\ + Reporting-UA: Delta Chat 1.28.0\n\ + Original-Recipient: rfc822;charlie@example.com\n\ + Final-Recipient: rfc822;charlie@example.com\n\ + Original-Message-ID: <2893@example.com>\n\ + Disposition: manual-action/MDN-sent-automatically; displayed\n\ + \n", &t.ctx).await; + let mf = MimeFactory::from_msg(&t.ctx, &new_msg, false) + .await + .unwrap(); + // The subject string should not be "Re: message opened" + assert_eq!("Re: Hello, Charlie", mf.subject_str().await); } async fn first_subject_str(t: TestContext) -> String { @@ -1453,7 +1501,7 @@ mod tests { mf.subject_str().await } - // Creates a mimefactory for a message that replies "Hi" to the incoming message in `imf_raw`. + // Creates a `Message` that replies "Hi" to the incoming email in `imf_raw`. async fn incoming_msg_to_reply_msg(imf_raw: &[u8], context: &Context) -> Message { context .set_config(Config::ShowEmails, Some("2"))