mirror of
https://github.com/chatmail/core.git
synced 2026-05-19 14:56:33 +03:00
fix: mark holiday notice messages as bot-generated
This commit is contained in:
@@ -2707,6 +2707,29 @@ mod tests {
|
|||||||
async fn test_is_bot() -> Result<()> {
|
async fn test_is_bot() -> Result<()> {
|
||||||
let alice = TestContext::new_alice().await;
|
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 <claire@example.com>\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.
|
// Alice receives a message from Bob the bot.
|
||||||
receive_imf(
|
receive_imf(
|
||||||
&alice,
|
&alice,
|
||||||
|
|||||||
@@ -116,7 +116,15 @@ pub(crate) struct MimeMessage {
|
|||||||
/// Hop info for debugging.
|
/// Hop info for debugging.
|
||||||
pub(crate) hop_info: String,
|
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<bool>,
|
pub(crate) is_bot: Option<bool>,
|
||||||
|
|
||||||
/// When the message was received, in secs since epoch.
|
/// 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() {
|
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 =
|
||||||
let is_bot = parser.headers.get("auto-submitted")
|
parser.headers.get("auto-submitted") == Some(&"auto-generated".to_string());
|
||||||
== Some(&"auto-generated".to_string())
|
|
||||||
&& parser.headers.contains_key("chat-version");
|
|
||||||
parser.is_bot = Some(is_bot);
|
parser.is_bot = Some(is_bot);
|
||||||
}
|
}
|
||||||
parser.maybe_remove_bad_parts();
|
parser.maybe_remove_bad_parts();
|
||||||
|
|||||||
@@ -621,7 +621,11 @@ pub(crate) async fn receive_imf_inner(
|
|||||||
.await;
|
.await;
|
||||||
|
|
||||||
if let Some(is_bot) = mime_parser.is_bot {
|
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))
|
Ok(Some(received_msg))
|
||||||
|
|||||||
Reference in New Issue
Block a user