mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 01:16:31 +03:00
fix: Look up or create ad-hoc group if there are duplicate addresses in "To"
Fix `test_unencrypted_doesnt_goto_self_chat` as well, it was only testing the first message because of using the same Message-ID for all messages.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
//! Internet Message Format reception pipeline.
|
//! Internet Message Format reception pipeline.
|
||||||
|
|
||||||
use std::collections::{BTreeMap, HashSet};
|
use std::collections::{BTreeMap, BTreeSet, HashSet};
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::sync::LazyLock;
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
@@ -2471,11 +2471,8 @@ async fn lookup_or_create_adhoc_group(
|
|||||||
.unwrap_or_else(|| "👥📧".to_string())
|
.unwrap_or_else(|| "👥📧".to_string())
|
||||||
});
|
});
|
||||||
let to_ids: Vec<ContactId> = to_ids.iter().filter_map(|x| *x).collect();
|
let to_ids: Vec<ContactId> = to_ids.iter().filter_map(|x| *x).collect();
|
||||||
let mut contact_ids = Vec::with_capacity(to_ids.len() + 1);
|
let mut contact_ids = BTreeSet::<ContactId>::from_iter(to_ids.iter().copied());
|
||||||
contact_ids.extend(&to_ids);
|
contact_ids.insert(from_id);
|
||||||
if !contact_ids.contains(&from_id) {
|
|
||||||
contact_ids.push(from_id);
|
|
||||||
}
|
|
||||||
let trans_fn = |t: &mut rusqlite::Transaction| {
|
let trans_fn = |t: &mut rusqlite::Transaction| {
|
||||||
t.pragma_update(None, "query_only", "0")?;
|
t.pragma_update(None, "query_only", "0")?;
|
||||||
t.execute(
|
t.execute(
|
||||||
|
|||||||
@@ -1970,18 +1970,23 @@ Message content",
|
|||||||
async fn test_unencrypted_doesnt_goto_self_chat() -> Result<()> {
|
async fn test_unencrypted_doesnt_goto_self_chat() -> Result<()> {
|
||||||
let mut tcm = TestContextManager::new();
|
let mut tcm = TestContextManager::new();
|
||||||
let t = &tcm.alice().await;
|
let t = &tcm.alice().await;
|
||||||
|
let mut chat_id = None;
|
||||||
|
|
||||||
for to in [
|
for (i, to) in [
|
||||||
|
"<alice@example.org>",
|
||||||
"<alice@example.org>",
|
"<alice@example.org>",
|
||||||
"alice@example.org, alice@example.org",
|
"alice@example.org, alice@example.org",
|
||||||
"hidden-recipients:;",
|
"hidden-recipients:;",
|
||||||
] {
|
]
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
{
|
||||||
receive_imf(
|
receive_imf(
|
||||||
t,
|
t,
|
||||||
format!(
|
format!(
|
||||||
"Subject: s
|
"Subject: s
|
||||||
Chat-Version: 1.0
|
Chat-Version: 1.0
|
||||||
Message-ID: <foobar@localhost>
|
Message-ID: <foobar{i}@localhost>
|
||||||
To: {to}
|
To: {to}
|
||||||
From: <alice@example.org>
|
From: <alice@example.org>
|
||||||
|
|
||||||
@@ -1996,9 +2001,14 @@ Your server is hacked. Have a nice day!"
|
|||||||
assert_ne!(msg.chat_id, t.get_self_chat().await.id);
|
assert_ne!(msg.chat_id, t.get_self_chat().await.id);
|
||||||
assert_eq!(msg.from_id, ContactId::SELF);
|
assert_eq!(msg.from_id, ContactId::SELF);
|
||||||
assert_eq!(msg.to_id, ContactId::SELF);
|
assert_eq!(msg.to_id, ContactId::SELF);
|
||||||
let chat = Chat::load_from_db(t, msg.chat_id).await?;
|
if let Some(chat_id) = chat_id {
|
||||||
assert_eq!(chat.typ, Chattype::Group);
|
assert_eq!(msg.chat_id, chat_id);
|
||||||
assert!(!chat.is_encrypted(t).await?);
|
} else {
|
||||||
|
chat_id = Some(msg.chat_id);
|
||||||
|
let chat = Chat::load_from_db(t, msg.chat_id).await?;
|
||||||
|
assert_eq!(chat.typ, Chattype::Group);
|
||||||
|
assert!(!chat.is_encrypted(t).await?);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user