mirror of
https://github.com/chatmail/core.git
synced 2026-05-16 13:26:38 +03:00
feat: Don't create ad-hoc group on a member removal message (#5618)
The "Chat-Group-Member-Removed" header is added to ad-hoc group messages as well, so we should check for its presense before creating an ad-hoc group as we do for DC-style groups.
This commit is contained in:
@@ -1824,7 +1824,7 @@ async fn lookup_chat_or_create_adhoc_group(
|
|||||||
Ok(Some((new_chat_id, new_chat_id_blocked)))
|
Ok(Some((new_chat_id, new_chat_id_blocked)))
|
||||||
} else if allow_creation {
|
} else if allow_creation {
|
||||||
// Try to create an ad hoc group.
|
// Try to create an ad hoc group.
|
||||||
if let Some(new_chat_id) = create_adhoc_group(
|
create_adhoc_group(
|
||||||
context,
|
context,
|
||||||
mime_parser,
|
mime_parser,
|
||||||
create_blocked,
|
create_blocked,
|
||||||
@@ -1833,12 +1833,7 @@ async fn lookup_chat_or_create_adhoc_group(
|
|||||||
is_partial_download,
|
is_partial_download,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.context("Could not create ad hoc group")?
|
.context("Could not create ad hoc group")
|
||||||
{
|
|
||||||
Ok(Some((new_chat_id, create_blocked)))
|
|
||||||
} else {
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
@@ -2512,7 +2507,7 @@ async fn create_adhoc_group(
|
|||||||
from_id: ContactId,
|
from_id: ContactId,
|
||||||
to_ids: &[ContactId],
|
to_ids: &[ContactId],
|
||||||
is_partial_download: bool,
|
is_partial_download: bool,
|
||||||
) -> Result<Option<ChatId>> {
|
) -> Result<Option<(ChatId, Blocked)>> {
|
||||||
if is_partial_download {
|
if is_partial_download {
|
||||||
// Partial download may be an encrypted message with protected Subject header.
|
// Partial download may be an encrypted message with protected Subject header.
|
||||||
//
|
//
|
||||||
@@ -2551,7 +2546,16 @@ async fn create_adhoc_group(
|
|||||||
);
|
);
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
if mime_parser
|
||||||
|
.get_header(HeaderDef::ChatGroupMemberRemoved)
|
||||||
|
.is_some()
|
||||||
|
{
|
||||||
|
info!(
|
||||||
|
context,
|
||||||
|
"Message removes member from unknown ad-hoc group (TRASH)."
|
||||||
|
);
|
||||||
|
return Ok(Some((DC_CHAT_ID_TRASH, Blocked::Not)));
|
||||||
|
}
|
||||||
if member_ids.len() < 3 {
|
if member_ids.len() < 3 {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
@@ -2583,7 +2587,7 @@ async fn create_adhoc_group(
|
|||||||
chatlist_events::emit_chatlist_changed(context);
|
chatlist_events::emit_chatlist_changed(context);
|
||||||
chatlist_events::emit_chatlist_item_changed(context, new_chat_id);
|
chatlist_events::emit_chatlist_item_changed(context, new_chat_id);
|
||||||
|
|
||||||
Ok(Some(new_chat_id))
|
Ok(Some((new_chat_id, create_blocked)))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
|
|||||||
@@ -4658,6 +4658,33 @@ async fn test_protected_group_add_remove_member_missing_key() -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
|
async fn test_dont_create_adhoc_group_on_member_removal() -> Result<()> {
|
||||||
|
let mut tcm = TestContextManager::new();
|
||||||
|
let bob = &tcm.bob().await;
|
||||||
|
async fn get_chat_cnt(ctx: &Context) -> Result<usize> {
|
||||||
|
ctx.sql
|
||||||
|
.count("SELECT COUNT(*) FROM chats WHERE id>9", ())
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
let chat_cnt = get_chat_cnt(bob).await?;
|
||||||
|
receive_imf(
|
||||||
|
bob,
|
||||||
|
b"From: Alice <alice@example.org>\n\
|
||||||
|
To: <bob@example.net>, <charlie@example.com>\n\
|
||||||
|
Chat-Version: 1.0\n\
|
||||||
|
Subject: subject\n\
|
||||||
|
Message-ID: <first@example.org>\n\
|
||||||
|
Date: Sun, 14 Nov 2021 00:10:00 +0000\
|
||||||
|
Content-Type: text/plain
|
||||||
|
Chat-Group-Member-Removed: charlie@example.com",
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
assert_eq!(get_chat_cnt(bob).await?, chat_cnt);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
async fn test_forged_from() -> Result<()> {
|
async fn test_forged_from() -> Result<()> {
|
||||||
let mut tcm = TestContextManager::new();
|
let mut tcm = TestContextManager::new();
|
||||||
|
|||||||
Reference in New Issue
Block a user