From 0fa90a81e50098f36d9836d68d8bd4ba0447c97c Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Wed, 17 Feb 2021 17:20:38 +0100 Subject: [PATCH] prefer X-Microsoft-Original-Message-ID, if set outlooks SMTP-server change the Message-ID of messages and put the original Message-ID to X-Microsoft-Original-Message-ID. the changed Message-ID has some issues: - outgoing messages with bcc_self enabled are shown twice as the self-copy got the changed Message-ID while the database uses the original one - read receipts do not work as they refer to the changed message id - in general, sender and recipient see different Message-IDs the issues can be fixed by (1) let all receivers use the original Message-ID this is what this pr is doing and this should fix all issues with delta-to-delta communication, including groups, group-images etc. there may be issues left in communication with other MUAs as they are using another Message-ID. (2) ftr: updating the Message-ID in the database of the sender to the new one this requires bcc_self always enabled (which is not the case) and may also result easily in race conditions (Bob answers before Alice sees its self-sent message), however, has the advantage of better compatibility with other MUA. if needed, the compatibility with other MUA could be improved by remembering both Messages-IDs, maybe we could treat the modified as References or so, however, i think, this could be part of another PR if we know better about real, in the wild issues. --- src/headerdef.rs | 9 +++++++++ src/mimefactory.rs | 6 ------ src/mimeparser.rs | 26 +++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/headerdef.rs b/src/headerdef.rs index c899ac57f..28fb4877d 100644 --- a/src/headerdef.rs +++ b/src/headerdef.rs @@ -11,11 +11,20 @@ pub enum HeaderDef { To, Cc, Disposition, + + /// Used in the "Body Part Header" of MDNs as of RFC 8098. + /// Indicates the Message-ID of the message for which the MDN is being issued. OriginalMessageId, /// Delta Chat extension for message IDs in combined MDNs AdditionalMessageIds, + /// Outlook-SMTP-server replace the `Message-ID:`-header + /// and write the original ID to `X-Microsoft-Original-Message-ID`. + /// To sort things correctly and to not show outgoing messages twice, + /// we need to check that header as well. + XMicrosoftOriginalMessageId, + ListId, References, InReplyTo, diff --git a/src/mimefactory.rs b/src/mimefactory.rs index b89e981fd..06d8a6973 100644 --- a/src/mimefactory.rs +++ b/src/mimefactory.rs @@ -514,12 +514,6 @@ impl<'a> MimeFactory<'a> { )); } - // we could also store the message-id in the protected headers - // which would probably help to survive providers like - // Outlook.com or hotmail which mangle the Message-ID. - // but they also strip the Autocrypt header so we probably - // never get a chance to tunnel our protected headers in a - // cryptographic payload. unprotected_headers.push(Header::new( "Message-ID".into(), render_rfc724_mid(&rfc724_mid), diff --git a/src/mimeparser.rs b/src/mimeparser.rs index 93966bd60..dfe3d4986 100644 --- a/src/mimeparser.rs +++ b/src/mimeparser.rs @@ -950,7 +950,8 @@ impl MimeMessage { } pub fn get_rfc724_mid(&self) -> Option { - self.get(HeaderDef::MessageId) + self.get(HeaderDef::XMicrosoftOriginalMessageId) + .or_else(|| self.get(HeaderDef::MessageId)) .and_then(|msgid| parse_message_id(msgid).ok()) } @@ -2749,4 +2750,27 @@ On 2020-10-25, Bob wrote: "mime-modified test – mime-modified *set*; simplify is always regarded as lossy." ); } + + #[async_std::test] + async fn test_x_microsoft_original_message_id() { + let t = TestContext::new().await; + let message = MimeMessage::from_bytes(&t, b"Date: Wed, 17 Feb 2021 15:45:15 +0000\n\ + Chat-Version: 1.0\n\ + Message-ID: \n\ + To: Bob \n\ + From: Alice \n\ + Subject: Message from Alice\n\ + Content-Type: text/plain\n\ + X-Microsoft-Original-Message-ID: \n\ + MIME-Version: 1.0\n\ + \n\ + Does it work with outlook now?\n\ + ") + .await + .unwrap(); + assert_eq!( + message.get_rfc724_mid(), + Some("Mr.6Dx7ITn4w38.n9j7epIcuQI@outlook.com".to_string()) + ); + } }