@@ -715,7 +715,9 @@ pub(crate) async fn receive_imf_inner(
715715 mark_recipients_as_verified ( context, from_id, & mime_parser) . await ?;
716716 }
717717
718+ let is_old_contact_request;
718719 let received_msg = if let Some ( received_msg) = received_msg {
720+ is_old_contact_request = false ;
719721 received_msg
720722 } else {
721723 let is_dc_message = if mime_parser. has_chat_version ( ) {
@@ -754,9 +756,9 @@ pub(crate) async fn receive_imf_inner(
754756 to_ids. first ( ) . copied ( ) . flatten ( ) . unwrap_or ( ContactId :: SELF )
755757 } ;
756758
757- let ( chat_id, chat_id_blocked) = do_chat_assignment (
759+ let ( chat_id, chat_id_blocked, is_created ) = do_chat_assignment (
758760 context,
759- chat_assignment,
761+ & chat_assignment,
760762 from_id,
761763 & to_ids,
762764 & past_ids,
@@ -767,6 +769,7 @@ pub(crate) async fn receive_imf_inner(
767769 parent_message,
768770 )
769771 . await ?;
772+ is_old_contact_request = chat_id_blocked == Blocked :: Request && !is_created;
770773
771774 // Add parts
772775 add_parts (
@@ -984,8 +987,9 @@ pub(crate) async fn receive_imf_inner(
984987 let fresh = received_msg. state == MessageState :: InFresh
985988 && mime_parser. is_system_message != SystemMessage :: CallAccepted
986989 && mime_parser. is_system_message != SystemMessage :: CallEnded ;
990+ let important = mime_parser. incoming && fresh && !is_old_contact_request;
987991 for msg_id in & received_msg. msg_ids {
988- chat_id. emit_msg_event ( context, * msg_id, mime_parser . incoming && fresh ) ;
992+ chat_id. emit_msg_event ( context, * msg_id, important ) ;
989993 }
990994 }
991995 context. new_msgs_notify . notify_one ( ) ;
@@ -1279,10 +1283,15 @@ async fn decide_chat_assignment(
12791283/// Assigns the message to a chat.
12801284///
12811285/// Creates a new chat if necessary.
1286+ ///
1287+ /// Returns the chat ID,
1288+ /// whether it is blocked
1289+ /// and if the chat was created by this function
1290+ /// (as opposed to being looked up among existing chats).
12821291#[ expect( clippy:: too_many_arguments) ]
12831292async fn do_chat_assignment (
12841293 context : & Context ,
1285- chat_assignment : ChatAssignment ,
1294+ chat_assignment : & ChatAssignment ,
12861295 from_id : ContactId ,
12871296 to_ids : & [ Option < ContactId > ] ,
12881297 past_ids : & [ Option < ContactId > ] ,
@@ -1291,11 +1300,12 @@ async fn do_chat_assignment(
12911300 mime_parser : & mut MimeMessage ,
12921301 is_partial_download : Option < u32 > ,
12931302 parent_message : Option < Message > ,
1294- ) -> Result < ( ChatId , Blocked ) > {
1303+ ) -> Result < ( ChatId , Blocked , bool ) > {
12951304 let is_bot = context. get_config_bool ( Config :: Bot ) . await ?;
12961305
12971306 let mut chat_id = None ;
12981307 let mut chat_id_blocked = Blocked :: Not ;
1308+ let mut chat_created = false ;
12991309
13001310 if mime_parser. incoming {
13011311 let test_normal_chat = ChatIdBlocked :: lookup_by_contact ( context, from_id) . await ?;
@@ -1350,12 +1360,13 @@ async fn do_chat_assignment(
13501360 {
13511361 chat_id = Some ( new_chat_id) ;
13521362 chat_id_blocked = new_chat_id_blocked;
1363+ chat_created = true ;
13531364 }
13541365 }
13551366 }
13561367 ChatAssignment :: MailingListOrBroadcast => {
13571368 if let Some ( mailinglist_header) = mime_parser. get_mailinglist_header ( ) {
1358- if let Some ( ( new_chat_id, new_chat_id_blocked) ) =
1369+ if let Some ( ( new_chat_id, new_chat_id_blocked, new_chat_created ) ) =
13591370 create_or_lookup_mailinglist_or_broadcast (
13601371 context,
13611372 allow_creation,
@@ -1367,6 +1378,7 @@ async fn do_chat_assignment(
13671378 {
13681379 chat_id = Some ( new_chat_id) ;
13691380 chat_id_blocked = new_chat_id_blocked;
1381+ chat_created = new_chat_created;
13701382
13711383 apply_mailinglist_changes ( context, mime_parser, new_chat_id) . await ?;
13721384 }
@@ -1380,18 +1392,20 @@ async fn do_chat_assignment(
13801392 chat_id_blocked = * new_chat_id_blocked;
13811393 }
13821394 ChatAssignment :: AdHocGroup => {
1383- if let Some ( ( new_chat_id, new_chat_id_blocked) ) = lookup_or_create_adhoc_group (
1384- context,
1385- mime_parser,
1386- to_ids,
1387- allow_creation || test_normal_chat. is_some ( ) ,
1388- create_blocked,
1389- is_partial_download. is_some ( ) ,
1390- )
1391- . await ?
1395+ if let Some ( ( new_chat_id, new_chat_id_blocked, new_created) ) =
1396+ lookup_or_create_adhoc_group (
1397+ context,
1398+ mime_parser,
1399+ to_ids,
1400+ allow_creation || test_normal_chat. is_some ( ) ,
1401+ create_blocked,
1402+ is_partial_download. is_some ( ) ,
1403+ )
1404+ . await ?
13921405 {
13931406 chat_id = Some ( new_chat_id) ;
13941407 chat_id_blocked = new_chat_id_blocked;
1408+ chat_created = new_created;
13951409 }
13961410 }
13971411 ChatAssignment :: OneOneChat => { }
@@ -1427,6 +1441,7 @@ async fn do_chat_assignment(
14271441 . context ( "Failed to get (new) chat for contact" ) ?;
14281442 chat_id = Some ( chat. id ) ;
14291443 chat_id_blocked = chat. blocked ;
1444+ chat_created = true ;
14301445 }
14311446
14321447 if let Some ( chat_id) = chat_id {
@@ -1479,6 +1494,7 @@ async fn do_chat_assignment(
14791494 {
14801495 chat_id = Some ( new_chat_id) ;
14811496 chat_id_blocked = new_chat_id_blocked;
1497+ chat_created = true ;
14821498 }
14831499 }
14841500 }
@@ -1499,6 +1515,7 @@ async fn do_chat_assignment(
14991515 {
15001516 id
15011517 } else {
1518+ chat_created = true ;
15021519 let name =
15031520 compute_mailinglist_name ( mailinglist_header, & listid, mime_parser) ;
15041521 chat:: create_broadcast_ex ( context, Nosync , listid, name) . await ?
@@ -1507,18 +1524,20 @@ async fn do_chat_assignment(
15071524 }
15081525 }
15091526 ChatAssignment :: AdHocGroup => {
1510- if let Some ( ( new_chat_id, new_chat_id_blocked) ) = lookup_or_create_adhoc_group (
1511- context,
1512- mime_parser,
1513- to_ids,
1514- allow_creation,
1515- Blocked :: Not ,
1516- is_partial_download. is_some ( ) ,
1517- )
1518- . await ?
1527+ if let Some ( ( new_chat_id, new_chat_id_blocked, new_chat_created) ) =
1528+ lookup_or_create_adhoc_group (
1529+ context,
1530+ mime_parser,
1531+ to_ids,
1532+ allow_creation,
1533+ Blocked :: Not ,
1534+ is_partial_download. is_some ( ) ,
1535+ )
1536+ . await ?
15191537 {
15201538 chat_id = Some ( new_chat_id) ;
15211539 chat_id_blocked = new_chat_id_blocked;
1540+ chat_created = new_chat_created;
15221541 }
15231542 }
15241543 ChatAssignment :: OneOneChat => { }
@@ -1538,6 +1557,7 @@ async fn do_chat_assignment(
15381557 let chat = ChatIdBlocked :: get_for_contact ( context, to_id, Blocked :: Not ) . await ?;
15391558 chat_id = Some ( chat. id ) ;
15401559 chat_id_blocked = chat. blocked ;
1560+ chat_created = true ;
15411561 }
15421562 }
15431563 if chat_id. is_none ( ) && mime_parser. has_chat_version ( ) {
@@ -1575,7 +1595,7 @@ async fn do_chat_assignment(
15751595 info ! ( context, "No chat id for message (TRASH)." ) ;
15761596 DC_CHAT_ID_TRASH
15771597 } ) ;
1578- Ok ( ( chat_id, chat_id_blocked) )
1598+ Ok ( ( chat_id, chat_id_blocked, chat_created ) )
15791599}
15801600
15811601/// Creates a `ReceivedMsg` from given parts which might consist of
@@ -2402,7 +2422,7 @@ async fn lookup_or_create_adhoc_group(
24022422 allow_creation : bool ,
24032423 create_blocked : Blocked ,
24042424 is_partial_download : bool ,
2405- ) -> Result < Option < ( ChatId , Blocked ) > > {
2425+ ) -> Result < Option < ( ChatId , Blocked , bool ) > > {
24062426 // Partial download may be an encrypted message with protected Subject header. We do not want to
24072427 // create a group with "..." or "Encrypted message" as a subject. The same is for undecipherable
24082428 // messages. Instead, assign the message to 1:1 chat with the sender.
@@ -2492,12 +2512,12 @@ async fn lookup_or_create_adhoc_group(
24922512 context,
24932513 "Assigning message to ad-hoc group {chat_id} with matching name and members."
24942514 ) ;
2495- return Ok ( Some ( ( chat_id, blocked) ) ) ;
2515+ return Ok ( Some ( ( chat_id, blocked, false ) ) ) ;
24962516 }
24972517 if !allow_creation {
24982518 return Ok ( None ) ;
24992519 }
2500- create_adhoc_group (
2520+ Ok ( create_adhoc_group (
25012521 context,
25022522 mime_parser,
25032523 create_blocked,
@@ -2506,7 +2526,8 @@ async fn lookup_or_create_adhoc_group(
25062526 & grpname,
25072527 )
25082528 . await
2509- . context ( "Could not create ad hoc group" )
2529+ . context ( "Could not create ad hoc group" ) ?
2530+ . map ( |( chat_id, blocked) | ( chat_id, blocked, true ) ) )
25102531}
25112532
25122533/// If this method returns true, the message shall be assigned to the 1:1 chat with the sender.
@@ -3146,17 +3167,22 @@ fn mailinglist_header_listid(list_id_header: &str) -> Result<String> {
31463167///
31473168/// `mime_parser` is the corresponding message
31483169/// and is used to figure out the mailing list name from different header fields.
3170+ ///
3171+ /// Returns the chat ID,
3172+ /// whether it is blocked
3173+ /// and if the chat was created by this function
3174+ /// (as opposed to being looked up among existing chats).
31493175async fn create_or_lookup_mailinglist_or_broadcast (
31503176 context : & Context ,
31513177 allow_creation : bool ,
31523178 list_id_header : & str ,
31533179 from_id : ContactId ,
31543180 mime_parser : & MimeMessage ,
3155- ) -> Result < Option < ( ChatId , Blocked ) > > {
3181+ ) -> Result < Option < ( ChatId , Blocked , bool ) > > {
31563182 let listid = mailinglist_header_listid ( list_id_header) ?;
31573183
31583184 if let Some ( ( chat_id, blocked) ) = chat:: get_chat_id_by_grpid ( context, & listid) . await ? {
3159- return Ok ( Some ( ( chat_id, blocked) ) ) ;
3185+ return Ok ( Some ( ( chat_id, blocked, false ) ) ) ;
31603186 }
31613187
31623188 let chattype = if mime_parser. was_encrypted ( ) {
@@ -3220,7 +3246,7 @@ async fn create_or_lookup_mailinglist_or_broadcast(
32203246 )
32213247 . await ?;
32223248 }
3223- Ok ( Some ( ( chat_id, blocked) ) )
3249+ Ok ( Some ( ( chat_id, blocked, true ) ) )
32243250 } else {
32253251 info ! ( context, "Creating list forbidden by caller." ) ;
32263252 Ok ( None )
0 commit comments