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:
iequidoo
2025-11-20 05:15:31 -03:00
committed by iequidoo
parent e7e31d7914
commit 6514b4ca7f
2 changed files with 19 additions and 12 deletions

View File

@@ -1,6 +1,6 @@
//! Internet Message Format reception pipeline.
use std::collections::{BTreeMap, HashSet};
use std::collections::{BTreeMap, BTreeSet, HashSet};
use std::iter;
use std::sync::LazyLock;
@@ -2471,11 +2471,8 @@ async fn lookup_or_create_adhoc_group(
.unwrap_or_else(|| "👥📧".to_string())
});
let to_ids: Vec<ContactId> = to_ids.iter().filter_map(|x| *x).collect();
let mut contact_ids = Vec::with_capacity(to_ids.len() + 1);
contact_ids.extend(&to_ids);
if !contact_ids.contains(&from_id) {
contact_ids.push(from_id);
}
let mut contact_ids = BTreeSet::<ContactId>::from_iter(to_ids.iter().copied());
contact_ids.insert(from_id);
let trans_fn = |t: &mut rusqlite::Transaction| {
t.pragma_update(None, "query_only", "0")?;
t.execute(

View File

@@ -1970,18 +1970,23 @@ Message content",
async fn test_unencrypted_doesnt_goto_self_chat() -> Result<()> {
let mut tcm = TestContextManager::new();
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",
"hidden-recipients:;",
] {
]
.iter()
.enumerate()
{
receive_imf(
t,
format!(
"Subject: s
Chat-Version: 1.0
Message-ID: <foobar@localhost>
Message-ID: <foobar{i}@localhost>
To: {to}
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_eq!(msg.from_id, ContactId::SELF);
assert_eq!(msg.to_id, ContactId::SELF);
let chat = Chat::load_from_db(t, msg.chat_id).await?;
assert_eq!(chat.typ, Chattype::Group);
assert!(!chat.is_encrypted(t).await?);
if let Some(chat_id) = chat_id {
assert_eq!(msg.chat_id, chat_id);
} 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(())
}