Skip to content

Commit 58b14ed

Browse files
committed
fix: mark holiday notice messages as bot-generated
1 parent 779635d commit 58b14ed

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

src/message.rs

+23
Original file line numberDiff line numberDiff line change
@@ -2707,6 +2707,29 @@ mod tests {
27072707
async fn test_is_bot() -> Result<()> {
27082708
let alice = TestContext::new_alice().await;
27092709

2710+
// Alice receives an auto-generated non-chat message.
2711+
//
2712+
// This could be a holiday notice,
2713+
// in which case the message should be marked as bot-generated,
2714+
// but the contact should not.
2715+
receive_imf(
2716+
&alice,
2717+
b"From: Claire <[email protected]>\n\
2718+
2719+
Message-ID: <[email protected]>\n\
2720+
Auto-Submitted: auto-generated\n\
2721+
Date: Fri, 29 Jan 2021 21:37:55 +0000\n\
2722+
\n\
2723+
hello\n",
2724+
false,
2725+
)
2726+
.await?;
2727+
let msg = alice.get_last_msg().await;
2728+
assert_eq!(msg.get_text(), "hello".to_string());
2729+
assert!(msg.is_bot());
2730+
let contact = Contact::get_by_id(&alice, msg.from_id).await?;
2731+
assert!(!contact.is_bot());
2732+
27102733
// Alice receives a message from Bob the bot.
27112734
receive_imf(
27122735
&alice,

src/mimeparser.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,15 @@ pub(crate) struct MimeMessage {
116116
/// Hop info for debugging.
117117
pub(crate) hop_info: String,
118118

119-
/// Whether the contact sending this should be marked as bot or non-bot.
119+
/// Whether the message is auto-generated.
120+
///
121+
/// If chat message (with `Chat-Version` header) is auto-generated,
122+
/// the contact sending this should be marked as bot.
123+
///
124+
/// If non-chat message is auto-generated,
125+
/// it could be a holiday notice auto-reply,
126+
/// in which case the message should be marked as bot-generated,
127+
/// but the contact should not be.
120128
pub(crate) is_bot: Option<bool>,
121129

122130
/// When the message was received, in secs since epoch.
@@ -563,10 +571,8 @@ impl MimeMessage {
563571
};
564572

565573
if parser.mdn_reports.is_empty() && parser.webxdc_status_update.is_none() {
566-
// "Auto-Submitted" is also set by holiday-notices so we also check "chat-version".
567-
let is_bot = parser.headers.get("auto-submitted")
568-
== Some(&"auto-generated".to_string())
569-
&& parser.headers.contains_key("chat-version");
574+
let is_bot =
575+
parser.headers.get("auto-submitted") == Some(&"auto-generated".to_string());
570576
parser.is_bot = Some(is_bot);
571577
}
572578
parser.maybe_remove_bad_parts();

src/receive_imf.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,11 @@ pub(crate) async fn receive_imf_inner(
621621
.await;
622622

623623
if let Some(is_bot) = mime_parser.is_bot {
624-
from_id.mark_bot(context, is_bot).await?;
624+
// If the message is auto-generated and was generated by Delta Chat,
625+
// mark the contact as a bot.
626+
if mime_parser.get_header(HeaderDef::ChatVerified).is_some() {
627+
from_id.mark_bot(context, is_bot).await?;
628+
}
625629
}
626630

627631
Ok(Some(received_msg))

0 commit comments

Comments
 (0)