Skip to content

Commit 074f5f2

Browse files
committed
fix: Keep email email contact in 1:1 chat if PGP contact has a different addr
If a contact did AEAP in the past, then it can happen that there are multiple contacts with the same email address but different keys. In this case, we should make sure that we don't send messages to a different email address all of a sudden, and that there aren't two 1:1 chats with the same contact. Therefore, if the PGP contact has a different email address than the email contact, we keep the email contact in 1:1 chats.
1 parent 19cb8b2 commit 074f5f2

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/sql/migrations.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1583,6 +1583,8 @@ fn migrate_pgp_contacts(
15831583

15841584
let mut update_member_stmt = transaction
15851585
.prepare("UPDATE chats_contacts SET contact_id=? WHERE contact_id=? AND chat_id=?")?;
1586+
let mut addr_cmp_stmt = transaction
1587+
.prepare("SELECT c.addr=d.addr FROM contacts c, contacts d WHERE c.id=? AND d.id=?")?;
15861588
for chat in all_chats {
15871589
let (chat_id, typ, grpid, protected) = chat.context("Step 24")?;
15881590
// In groups, this also contains past members
@@ -1601,7 +1603,8 @@ fn migrate_pgp_contacts(
16011603

16021604
let old_and_new_members = match typ {
16031605
// 1:1 chats retain:
1604-
// - email-contact if peerstate is in the "reset" state.
1606+
// - email-contact if peerstate is in the "reset" state,
1607+
// or if there is no PGP-contact that has the right email address.
16051608
// - PGP-contact identified by the Autocrypt key if Autocrypt key does not match the verified key.
16061609
// - PGP-contact identified by the verified key if peerstate Autocrypt key matches the Verified key.
16071610
// Since the autocrypt and verified PGP contact are identital in this case, we can add the AutocryptPgp contact,
@@ -1615,6 +1618,12 @@ fn migrate_pgp_contacts(
16151618
keep_email_contacts("No peerstate, or peerstate in 'reset' state");
16161619
continue;
16171620
};
1621+
if !addr_cmp_stmt
1622+
.query_row((old_member, new_contact), |row| row.get::<_, bool>(0))?
1623+
{
1624+
keep_email_contacts("PGP contact has different email");
1625+
continue;
1626+
}
16181627
vec![(*old_member, Some(new_contact))]
16191628
}
16201629

0 commit comments

Comments
 (0)