diff --git a/src/message.rs b/src/message.rs index ab8efed4b3..4d65433ba4 100644 --- a/src/message.rs +++ b/src/message.rs @@ -2707,6 +2707,29 @@ mod tests { async fn test_is_bot() -> Result<()> { let alice = TestContext::new_alice().await; + // Alice receives an auto-generated non-chat message. + // + // This could be a holiday notice, + // in which case the message should be marked as bot-generated, + // but the contact should not. + receive_imf( + &alice, + b"From: Claire \n\ + To: alice@example.org\n\ + Message-ID: <789@example.com>\n\ + Auto-Submitted: auto-generated\n\ + Date: Fri, 29 Jan 2021 21:37:55 +0000\n\ + \n\ + hello\n", + false, + ) + .await?; + let msg = alice.get_last_msg().await; + assert_eq!(msg.get_text(), "hello".to_string()); + assert!(msg.is_bot()); + let contact = Contact::get_by_id(&alice, msg.from_id).await?; + assert!(!contact.is_bot()); + // Alice receives a message from Bob the bot. receive_imf( &alice, diff --git a/src/mimeparser.rs b/src/mimeparser.rs index b8c2358ba9..92a7d397dc 100644 --- a/src/mimeparser.rs +++ b/src/mimeparser.rs @@ -116,7 +116,15 @@ pub(crate) struct MimeMessage { /// Hop info for debugging. pub(crate) hop_info: String, - /// Whether the contact sending this should be marked as bot or non-bot. + /// Whether the message is auto-generated. + /// + /// If chat message (with `Chat-Version` header) is auto-generated, + /// the contact sending this should be marked as bot. + /// + /// If non-chat message is auto-generated, + /// it could be a holiday notice auto-reply, + /// in which case the message should be marked as bot-generated, + /// but the contact should not be. pub(crate) is_bot: Option, /// When the message was received, in secs since epoch. @@ -563,10 +571,8 @@ impl MimeMessage { }; if parser.mdn_reports.is_empty() && parser.webxdc_status_update.is_none() { - // "Auto-Submitted" is also set by holiday-notices so we also check "chat-version". - let is_bot = parser.headers.get("auto-submitted") - == Some(&"auto-generated".to_string()) - && parser.headers.contains_key("chat-version"); + let is_bot = + parser.headers.get("auto-submitted") == Some(&"auto-generated".to_string()); parser.is_bot = Some(is_bot); } parser.maybe_remove_bad_parts(); diff --git a/src/receive_imf.rs b/src/receive_imf.rs index 27b27c7b87..f61fa54db3 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -621,7 +621,11 @@ pub(crate) async fn receive_imf_inner( .await; if let Some(is_bot) = mime_parser.is_bot { - from_id.mark_bot(context, is_bot).await?; + // If the message is auto-generated and was generated by Delta Chat, + // mark the contact as a bot. + if mime_parser.get_header(HeaderDef::ChatVersion).is_some() { + from_id.mark_bot(context, is_bot).await?; + } } Ok(Some(received_msg))