mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
add a test that fails if 'References:'-header is missing
This commit is contained in:
62
src/chat.rs
62
src/chat.rs
@@ -3072,6 +3072,7 @@ mod tests {
|
||||
use crate::chatlist::Chatlist;
|
||||
use crate::constants::{DC_GCL_ARCHIVED_ONLY, DC_GCL_NO_SPECIALS};
|
||||
use crate::contact::Contact;
|
||||
use crate::dc_receive_imf::dc_receive_imf;
|
||||
use crate::test_utils::TestContext;
|
||||
|
||||
#[async_std::test]
|
||||
@@ -3844,4 +3845,65 @@ mod tests {
|
||||
assert!(chat_id.is_self_talk(&ctx).await.unwrap());
|
||||
assert_eq!(blocked, Blocked::Not);
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn test_group_with_removed_message_id() {
|
||||
// Alice creates a group with Bob, sends a message to bob
|
||||
let alice = TestContext::new_alice().await;
|
||||
let bob = TestContext::new_bob().await;
|
||||
alice
|
||||
.set_config(Config::ShowEmails, Some("2"))
|
||||
.await
|
||||
.unwrap();
|
||||
bob.set_config(Config::ShowEmails, Some("2")).await.unwrap();
|
||||
|
||||
let (contact_id, _) =
|
||||
Contact::add_or_lookup(&alice, "", "bob@example.net", Origin::ManuallyCreated)
|
||||
.await
|
||||
.unwrap();
|
||||
let alice_chat_id = create_group_chat(&alice, ProtectionStatus::Unprotected, "grp")
|
||||
.await
|
||||
.unwrap();
|
||||
let alice_chat = Chat::load_from_db(&alice, alice_chat_id).await.unwrap();
|
||||
add_contact_to_chat(&alice, alice_chat_id, contact_id).await;
|
||||
assert_eq!(get_chat_contacts(&alice, alice_chat_id).await.len(), 2);
|
||||
send_text_msg(&alice, alice_chat_id, "hi!".to_string())
|
||||
.await
|
||||
.ok();
|
||||
assert_eq!(get_chat_msgs(&alice, alice_chat_id, 0, None).await.len(), 1);
|
||||
|
||||
// Alice has an SMTP-server replacing the `Message-ID:`-header (as done eg. by outlook.com).
|
||||
let msg = alice.pop_sent_msg().await.payload();
|
||||
assert_eq!(msg.match_indices("Gr.").count(), 2);
|
||||
let msg = msg.replace("Message-ID: <Gr.", "Message-ID: <XXX");
|
||||
assert_eq!(msg.match_indices("Gr.").count(), 1);
|
||||
|
||||
// Bob receives this message, he may detect group by `References:`- or `Chat-Group:`-header
|
||||
dc_receive_imf(&bob, msg.as_bytes(), "INBOX", 1, false)
|
||||
.await
|
||||
.unwrap();
|
||||
let msg = bob.get_last_msg().await;
|
||||
|
||||
let bob_chat = Chat::load_from_db(&bob, msg.chat_id).await.unwrap();
|
||||
assert_eq!(bob_chat.grpid, alice_chat.grpid);
|
||||
|
||||
// Bob answers - simulate a normal MUA by not setting `Chat-*`-headers;
|
||||
// moreover, Bob's SMTP-server also replaces the `Message-ID:`-header
|
||||
send_text_msg(&bob, bob_chat.id, "ho!".to_string())
|
||||
.await
|
||||
.ok();
|
||||
let msg = bob.pop_sent_msg().await.payload();
|
||||
let msg = msg.replace("Message-ID: <Gr.", "Message-ID: <XXX");
|
||||
let msg = msg.replace("Chat-", "XXXX-");
|
||||
assert_eq!(msg.match_indices("Chat-").count(), 0);
|
||||
|
||||
// Alice receives this message - she can still detect the group by the `References:`-header
|
||||
dc_receive_imf(&alice, msg.as_bytes(), "INBOX", 2, false)
|
||||
.await
|
||||
.unwrap();
|
||||
let msg = alice.get_last_msg().await;
|
||||
assert_eq!(msg.chat_id, alice_chat_id);
|
||||
assert_eq!(msg.text, Some("ho!".to_string()));
|
||||
assert_eq!(get_chat_msgs(&alice, alice_chat_id, 0, None).await.len(), 2);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user