mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 01:16:31 +03:00
fix: never prepend subject to message text when bot receives it
This commit is contained in:
@@ -662,6 +662,7 @@ impl MimeMessage {
|
||||
self.squash_attachment_parts();
|
||||
}
|
||||
|
||||
if !context.get_config_bool(Config::Bot).await? {
|
||||
if let Some(ref subject) = self.get_subject() {
|
||||
let mut prepend_subject = true;
|
||||
if !self.decrypting_failed {
|
||||
@@ -691,6 +692,7 @@ impl MimeMessage {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if self.is_forwarded {
|
||||
for part in &mut self.parts {
|
||||
@@ -3933,4 +3935,31 @@ Content-Disposition: reaction\n\
|
||||
|
||||
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