mirror of
https://github.com/chatmail/core.git
synced 2026-04-20 23:16:30 +03:00
fix: Ignore hidden headers in IMF section
Hidden headers are nonstandard, so they aren't DKIM-signed by e.g. OpenDKIM if they appear in IMF section.
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
use mailparse::ParsedMail;
|
||||
use std::mem;
|
||||
|
||||
use super::*;
|
||||
use crate::{
|
||||
chat,
|
||||
chatlist::Chatlist,
|
||||
constants::{Blocked, DC_DESIRED_TEXT_LEN, DC_ELLIPSIS},
|
||||
constants::{self, Blocked, DC_DESIRED_TEXT_LEN, DC_ELLIPSIS},
|
||||
message::{MessageState, MessengerMessage},
|
||||
receive_imf::receive_imf,
|
||||
test_utils::{TestContext, TestContextManager},
|
||||
@@ -1916,3 +1917,45 @@ This is the epilogue. It is also to be ignored.";
|
||||
"This is explicitly typed plain US-ASCII text.\r\nIt DOES end with a linebreak.\r\n"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn test_chat_edit_imf_header() -> Result<()> {
|
||||
let mut tcm = TestContextManager::new();
|
||||
let alice = &tcm.alice().await;
|
||||
let bob = &tcm.bob().await;
|
||||
let alice_chat = alice.create_email_chat(bob).await;
|
||||
|
||||
// Alice sends a message, then sends an invalid edit request.
|
||||
let sent1 = alice.send_text(alice_chat.id, "foo").await;
|
||||
let alice_msg = sent1.load_from_db().await;
|
||||
assert_eq!(alice_chat.id.get_msg_cnt(alice).await?, 1);
|
||||
|
||||
chat::send_edit_request(alice, alice_msg.id, "bar".to_string()).await?;
|
||||
let mut sent2 = alice.pop_sent_msg().await;
|
||||
let mut s0 = String::new();
|
||||
let mut s1 = String::new();
|
||||
for l in sent2.payload.lines() {
|
||||
if l.starts_with("Chat-Edit:") {
|
||||
s1 += l;
|
||||
s1 += "\n";
|
||||
continue;
|
||||
}
|
||||
s0 += l;
|
||||
s0 += "\n";
|
||||
if l.starts_with("Message-ID:") && s1.is_empty() {
|
||||
s1 = mem::take(&mut s0);
|
||||
}
|
||||
}
|
||||
sent2.payload = s1 + &s0;
|
||||
|
||||
// Bob receives both messages, the edit request with "Chat-Edit" in IMF headers is
|
||||
// received as text message.
|
||||
let bob_msg = bob.recv_msg(&sent1).await;
|
||||
assert_eq!(bob_msg.text, "foo");
|
||||
assert_eq!(bob_msg.chat_id.get_msg_cnt(bob).await?, 1);
|
||||
let bob_msg = bob.recv_msg(&sent2).await;
|
||||
assert_eq!(bob_msg.text, constants::EDITED_PREFIX.to_string() + "bar");
|
||||
assert_eq!(bob_msg.chat_id.get_msg_cnt(bob).await?, 2);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user