mirror of
https://github.com/chatmail/core.git
synced 2026-05-01 20:36:31 +03:00
fix: never prepend subject to message text when bot receives it
This commit is contained in:
@@ -662,32 +662,34 @@ impl MimeMessage {
|
|||||||
self.squash_attachment_parts();
|
self.squash_attachment_parts();
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ref subject) = self.get_subject() {
|
if !context.get_config_bool(Config::Bot).await? {
|
||||||
let mut prepend_subject = true;
|
if let Some(ref subject) = self.get_subject() {
|
||||||
if !self.decrypting_failed {
|
let mut prepend_subject = true;
|
||||||
let colon = subject.find(':');
|
if !self.decrypting_failed {
|
||||||
if colon == Some(2)
|
let colon = subject.find(':');
|
||||||
|| colon == Some(3)
|
if colon == Some(2)
|
||||||
|| self.has_chat_version()
|
|| colon == Some(3)
|
||||||
|| subject.contains("Chat:")
|
|| self.has_chat_version()
|
||||||
{
|
|| subject.contains("Chat:")
|
||||||
prepend_subject = false
|
{
|
||||||
|
prepend_subject = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// For mailing lists, always add the subject because sometimes there are different topics
|
// For mailing lists, always add the subject because sometimes there are different topics
|
||||||
// and otherwise it might be hard to keep track:
|
// and otherwise it might be hard to keep track:
|
||||||
if self.is_mailinglist_message() && !self.has_chat_version() {
|
if self.is_mailinglist_message() && !self.has_chat_version() {
|
||||||
prepend_subject = true;
|
prepend_subject = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if prepend_subject && !subject.is_empty() {
|
if prepend_subject && !subject.is_empty() {
|
||||||
let part_with_text = self
|
let part_with_text = self
|
||||||
.parts
|
.parts
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.find(|part| !part.msg.is_empty() && !part.is_reaction);
|
.find(|part| !part.msg.is_empty() && !part.is_reaction);
|
||||||
if let Some(part) = part_with_text {
|
if let Some(part) = part_with_text {
|
||||||
part.msg = format!("{} – {}", subject, part.msg);
|
part.msg = format!("{} – {}", subject, part.msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3933,4 +3935,31 @@ Content-Disposition: reaction\n\
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Tests that subject is not prepended to the message
|
||||||
|
/// when bot receives it.
|
||||||
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
|
async fn test_bot_no_subject() {
|
||||||
|
let context = TestContext::new().await;
|
||||||
|
context.set_config(Config::Bot, Some("1")).await.unwrap();
|
||||||
|
let raw = br#"Message-ID: <foobar@example.org>
|
||||||
|
From: foo <foo@example.org>
|
||||||
|
Subject: Some subject
|
||||||
|
To: bar@example.org
|
||||||
|
MIME-Version: 1.0
|
||||||
|
Content-Type: text/plain; charset=utf-8
|
||||||
|
|
||||||
|
/help
|
||||||
|
"#;
|
||||||
|
|
||||||
|
let message = MimeMessage::from_bytes(&context.ctx, &raw[..], None)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(message.get_subject(), Some("Some subject".to_string()));
|
||||||
|
|
||||||
|
assert_eq!(message.parts.len(), 1);
|
||||||
|
assert_eq!(message.parts[0].typ, Viewtype::Text);
|
||||||
|
// Not "Some subject – /help"
|
||||||
|
assert_eq!(message.parts[0].msg, "/help");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user