diff --git a/deltachat-rpc-client/tests/test_multitransport.py b/deltachat-rpc-client/tests/test_multitransport.py index 291dbc76a..e23abab48 100644 --- a/deltachat-rpc-client/tests/test_multitransport.py +++ b/deltachat-rpc-client/tests/test_multitransport.py @@ -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) diff --git a/src/receive_imf.rs b/src/receive_imf.rs index f11526257..756a9009c 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -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| {