Skip to content

Commit e06372c

Browse files
committed
fix: count recipients by Intended Recipient Fingerprints
Fixes <#7987>
1 parent 50cd251 commit e06372c

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

deltachat-rpc-client/tests/test_multitransport.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22

33
from deltachat_rpc_client import EventType
4-
from deltachat_rpc_client.const import DownloadState
4+
from deltachat_rpc_client.const import ChatType, DownloadState
55
from deltachat_rpc_client.rpc import JsonRpcError
66

77

@@ -357,7 +357,7 @@ def test_message_info_imap_urls(acfactory) -> None:
357357
assert f"{new_alice_addr}/INBOX" in msg_info
358358

359359

360-
def test_remove_primary_transport(acfactory) -> None:
360+
def test_remove_primary_transport(acfactory, log) -> None:
361361
"""Test that after removing the primary relay, Alice can still receive messages."""
362362
alice, bob = acfactory.get_online_accounts(2)
363363
qr = acfactory.get_account_qr()
@@ -368,19 +368,21 @@ def test_remove_primary_transport(acfactory) -> None:
368368
bob_chat = bob.create_chat(alice)
369369
alice.create_chat(bob)
370370

371-
# Alice changes the transport.
371+
log.section("Alice sets up second transport")
372372
[transport1, transport2] = alice.list_transports()
373373
alice.set_config("configured_addr", transport2["addr"])
374374

375375
bob_chat.send_text("Hello!")
376376
msg1 = alice.wait_for_incoming_msg().get_snapshot()
377377
assert msg1.text == "Hello!"
378378

379-
# Alice deletes the first transport.
379+
log.section("Alice removes the primary relay")
380380
alice.delete_transport(transport1["addr"])
381381
alice.stop_io()
382382
alice.start_io()
383383

384384
bob_chat.send_text("Hello again!")
385385
msg2 = alice.wait_for_incoming_msg().get_snapshot()
386386
assert msg2.text == "Hello again!"
387+
assert msg2.chat.get_basic_snapshot().chat_type == ChatType.SINGLE
388+
assert msg2.chat == alice.create_chat(bob)

src/receive_imf.rs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,15 +1322,35 @@ async fn decide_chat_assignment(
13221322
// no database row and ChatId yet.
13231323
let mut num_recipients = 0;
13241324
let mut has_self_addr = false;
1325-
for recipient in &mime_parser.recipients {
1326-
has_self_addr |= context.is_self_addr(&recipient.addr).await?;
1327-
if addr_cmp(&recipient.addr, &mime_parser.from.addr) {
1328-
continue;
1325+
1326+
if let Some((sender_fingerprint, intended_recipient_fingerprints)) = mime_parser
1327+
.signature
1328+
.as_ref()
1329+
.filter(|(_sender_fingerprint, fps)| !fps.is_empty())
1330+
{
1331+
// The message is signed and has intended recipient fingerprints.
1332+
1333+
// If the message has intended recipient fingerprint and is not trashed already,
1334+
// then it is intended for us.
1335+
has_self_addr = true;
1336+
1337+
num_recipients = intended_recipient_fingerprints
1338+
.iter()
1339+
.filter(|fp| *fp != sender_fingerprint)
1340+
.count();
1341+
} else {
1342+
// Message has no intended recipient fingerprints
1343+
// or is not signed, count the `To` field recipients.
1344+
for recipient in &mime_parser.recipients {
1345+
has_self_addr |= context.is_self_addr(&recipient.addr).await?;
1346+
if addr_cmp(&recipient.addr, &mime_parser.from.addr) {
1347+
continue;
1348+
}
1349+
num_recipients += 1;
1350+
}
1351+
if from_id != ContactId::SELF && !has_self_addr {
1352+
num_recipients += 1;
13291353
}
1330-
num_recipients += 1;
1331-
}
1332-
if from_id != ContactId::SELF && !has_self_addr {
1333-
num_recipients += 1;
13341354
}
13351355
let mut can_be_11_chat_log = String::new();
13361356
let mut l = |cond: bool, s: String| {

0 commit comments

Comments
 (0)