fix: count recipients by Intended Recipient Fingerprints

Fixes <https://github.com/chatmail/core/issues/7987>
This commit is contained in:
link2xt
2026-03-15 23:01:40 +00:00
committed by l
parent 50cd2514cd
commit e06372c954
2 changed files with 34 additions and 12 deletions

View File

@@ -1,7 +1,7 @@
import pytest
from deltachat_rpc_client import EventType
from deltachat_rpc_client.const import DownloadState
from deltachat_rpc_client.const import ChatType, DownloadState
from deltachat_rpc_client.rpc import JsonRpcError
@@ -357,7 +357,7 @@ def test_message_info_imap_urls(acfactory) -> None:
assert f"{new_alice_addr}/INBOX" in msg_info
def test_remove_primary_transport(acfactory) -> None:
def test_remove_primary_transport(acfactory, log) -> None:
"""Test that after removing the primary relay, Alice can still receive messages."""
alice, bob = acfactory.get_online_accounts(2)
qr = acfactory.get_account_qr()
@@ -368,7 +368,7 @@ def test_remove_primary_transport(acfactory) -> None:
bob_chat = bob.create_chat(alice)
alice.create_chat(bob)
# Alice changes the transport.
log.section("Alice sets up second transport")
[transport1, transport2] = alice.list_transports()
alice.set_config("configured_addr", transport2["addr"])
@@ -376,7 +376,7 @@ def test_remove_primary_transport(acfactory) -> None:
msg1 = alice.wait_for_incoming_msg().get_snapshot()
assert msg1.text == "Hello!"
# Alice deletes the first transport.
log.section("Alice removes the primary relay")
alice.delete_transport(transport1["addr"])
alice.stop_io()
alice.start_io()
@@ -384,3 +384,5 @@ def test_remove_primary_transport(acfactory) -> None:
bob_chat.send_text("Hello again!")
msg2 = alice.wait_for_incoming_msg().get_snapshot()
assert msg2.text == "Hello again!"
assert msg2.chat.get_basic_snapshot().chat_type == ChatType.SINGLE
assert msg2.chat == alice.create_chat(bob)

View File

@@ -1322,15 +1322,35 @@ async fn decide_chat_assignment(
// no database row and ChatId yet.
let mut num_recipients = 0;
let mut has_self_addr = false;
for recipient in &mime_parser.recipients {
has_self_addr |= context.is_self_addr(&recipient.addr).await?;
if addr_cmp(&recipient.addr, &mime_parser.from.addr) {
continue;
if let Some((sender_fingerprint, intended_recipient_fingerprints)) = mime_parser
.signature
.as_ref()
.filter(|(_sender_fingerprint, fps)| !fps.is_empty())
{
// The message is signed and has intended recipient fingerprints.
// If the message has intended recipient fingerprint and is not trashed already,
// then it is intended for us.
has_self_addr = true;
num_recipients = intended_recipient_fingerprints
.iter()
.filter(|fp| *fp != sender_fingerprint)
.count();
} else {
// Message has no intended recipient fingerprints
// or is not signed, count the `To` field recipients.
for recipient in &mime_parser.recipients {
has_self_addr |= context.is_self_addr(&recipient.addr).await?;
if addr_cmp(&recipient.addr, &mime_parser.from.addr) {
continue;
}
num_recipients += 1;
}
if from_id != ContactId::SELF && !has_self_addr {
num_recipients += 1;
}
num_recipients += 1;
}
if from_id != ContactId::SELF && !has_self_addr {
num_recipients += 1;
}
let mut can_be_11_chat_log = String::new();
let mut l = |cond: bool, s: String| {