11//! Internet Message Format reception pipeline.
22
3- use std:: collections:: { HashMap , HashSet } ;
3+ use std:: collections:: { BTreeMap , HashSet } ;
44use std:: iter;
55use std:: sync:: LazyLock ;
66
@@ -28,14 +28,14 @@ use crate::events::EventType;
2828use crate :: headerdef:: { HeaderDef , HeaderDefMap } ;
2929use crate :: imap:: { GENERATED_PREFIX , markseen_on_imap_table} ;
3030use crate :: key:: self_fingerprint_opt;
31- use crate :: key:: { DcKey , Fingerprint , SignedPublicKey } ;
31+ use crate :: key:: { DcKey , Fingerprint } ;
3232use crate :: log:: LogExt ;
3333use crate :: log:: { info, warn} ;
3434use crate :: logged_debug_assert;
3535use crate :: message:: {
3636 self , Message , MessageState , MessengerMessage , MsgId , Viewtype , rfc724_mid_exists,
3737} ;
38- use crate :: mimeparser:: { AvatarAction , MimeMessage , SystemMessage , parse_message_ids} ;
38+ use crate :: mimeparser:: { AvatarAction , GossipedKey , MimeMessage , SystemMessage , parse_message_ids} ;
3939use crate :: param:: { Param , Params } ;
4040use crate :: peer_channels:: { add_gossip_peer_from_header, insert_topic_stub} ;
4141use crate :: reaction:: { Reaction , set_msg_reaction} ;
@@ -835,7 +835,7 @@ pub(crate) async fn receive_imf_inner(
835835 context
836836 . sql
837837 . transaction ( move |transaction| {
838- let fingerprint = gossiped_key. dc_fingerprint ( ) . hex ( ) ;
838+ let fingerprint = gossiped_key. public_key . dc_fingerprint ( ) . hex ( ) ;
839839 transaction. execute (
840840 "INSERT INTO gossip_timestamp (chat_id, fingerprint, timestamp)
841841 VALUES (?, ?, ?)
@@ -2917,7 +2917,7 @@ async fn apply_group_changes(
29172917 // highest `add_timestamp` to disambiguate.
29182918 // The result of the error is that info message
29192919 // may contain display name of the wrong contact.
2920- let fingerprint = key. dc_fingerprint ( ) . hex ( ) ;
2920+ let fingerprint = key. public_key . dc_fingerprint ( ) . hex ( ) ;
29212921 if let Some ( contact_id) =
29222922 lookup_key_contact_by_fingerprint ( context, & fingerprint) . await ?
29232923 {
@@ -3659,10 +3659,28 @@ async fn mark_recipients_as_verified(
36593659 to_ids : & [ Option < ContactId > ] ,
36603660 mimeparser : & MimeMessage ,
36613661) -> Result < ( ) > {
3662+ let verifier_id = Some ( from_id) . filter ( |& id| id != ContactId :: SELF ) ;
3663+ for gossiped_key in mimeparser
3664+ . gossiped_keys
3665+ . values ( )
3666+ . filter ( |gossiped_key| gossiped_key. verified )
3667+ {
3668+ let fingerprint = gossiped_key. public_key . dc_fingerprint ( ) . hex ( ) ;
3669+ let Some ( to_id) = lookup_key_contact_by_fingerprint ( context, & fingerprint) . await ? else {
3670+ continue ;
3671+ } ;
3672+
3673+ if to_id == ContactId :: SELF || to_id == from_id {
3674+ continue ;
3675+ }
3676+
3677+ mark_contact_id_as_verified ( context, to_id, verifier_id) . await ?;
3678+ ChatId :: set_protection_for_contact ( context, to_id, mimeparser. timestamp_sent ) . await ?;
3679+ }
3680+
36623681 if mimeparser. get_header ( HeaderDef :: ChatVerified ) . is_none ( ) {
36633682 return Ok ( ( ) ) ;
36643683 }
3665- let verifier_id = Some ( from_id) . filter ( |& id| id != ContactId :: SELF ) ;
36663684 for to_id in to_ids. iter ( ) . filter_map ( |& x| x) {
36673685 if to_id == ContactId :: SELF || to_id == from_id {
36683686 continue ;
@@ -3755,7 +3773,7 @@ async fn add_or_lookup_contacts_by_address_list(
37553773async fn add_or_lookup_key_contacts (
37563774 context : & Context ,
37573775 address_list : & [ SingleInfo ] ,
3758- gossiped_keys : & HashMap < String , SignedPublicKey > ,
3776+ gossiped_keys : & BTreeMap < String , GossipedKey > ,
37593777 fingerprints : & [ Fingerprint ] ,
37603778 origin : Origin ,
37613779) -> Result < Vec < Option < ContactId > > > {
@@ -3771,7 +3789,7 @@ async fn add_or_lookup_key_contacts(
37713789 // Iterator has not ran out of fingerprints yet.
37723790 fp. hex ( )
37733791 } else if let Some ( key) = gossiped_keys. get ( addr) {
3774- key. dc_fingerprint ( ) . hex ( )
3792+ key. public_key . dc_fingerprint ( ) . hex ( )
37753793 } else if context. is_self_addr ( addr) . await ? {
37763794 contact_ids. push ( Some ( ContactId :: SELF ) ) ;
37773795 continue ;
0 commit comments