@@ -620,52 +620,26 @@ impl Imap {
620620
621621            // Determine the target folder where the message should be moved to. 
622622            // 
623-             // If we have seen  the message on  the IMAP server before, do not move it . 
623+             // We only move  the messages from  the INBOX and Spam folders . 
624624            // This is required to avoid infinite MOVE loop on IMAP servers 
625625            // that alias `DeltaChat` folder to other names. 
626626            // For example, some Dovecot servers alias `DeltaChat` folder to `INBOX.DeltaChat`. 
627-             // In this case Delta Chat configured with `DeltaChat` as the destination folder 
628-             // would detect messages in the `INBOX.DeltaChat` folder 
629-             // and try to move them to the `DeltaChat` folder. 
630-             // Such move to the same folder results in the messages 
631-             // getting a new UID, so the messages will be detected as new 
627+             // In this case moving from `INBOX.DeltaChat` to `DeltaChat` 
628+             // results in the messages getting a new UID, 
629+             // so the messages will be detected as new 
632630            // in the `INBOX.DeltaChat` folder again. 
633631            let  _target; 
634632            let  target = if  let  Some ( message_id)  = & message_id { 
635633                let  msg_info =
636634                    message:: rfc724_mid_exists_ex ( context,  message_id,  "deleted=1" ) . await ?; 
637-                 let  delete = if  let  Some ( ( _,  _ ,   true ) )  = msg_info { 
635+                 let  delete = if  let  Some ( ( _,  true ) )  = msg_info { 
638636                    info ! ( context,  "Deleting locally deleted message {message_id}." ) ; 
639637                    true 
640-                 }  else  if  let  Some ( ( _,  ts_sent_old,  _) )  = msg_info { 
641-                     let  is_chat_msg = headers. get_header_value ( HeaderDef :: ChatVersion ) . is_some ( ) ; 
642-                     let  ts_sent = headers
643-                         . get_header_value ( HeaderDef :: Date ) 
644-                         . and_then ( |v| mailparse:: dateparse ( & v) . ok ( ) ) 
645-                         . unwrap_or_default ( ) ; 
646-                     let  is_dup = is_dup_msg ( is_chat_msg,  ts_sent,  ts_sent_old) ; 
647-                     if  is_dup { 
648-                         info ! ( context,  "Deleting duplicate message {message_id}." ) ; 
649-                     } 
650-                     is_dup
651638                }  else  { 
652639                    false 
653640                } ; 
654641                if  delete { 
655642                    & delete_target
656-                 }  else  if  context
657-                     . sql 
658-                     . exists ( 
659-                         "SELECT COUNT (*) FROM imap WHERE rfc724_mid=?" , 
660-                         ( message_id, ) , 
661-                     ) 
662-                     . await ?
663-                 { 
664-                     info ! ( 
665-                         context, 
666-                         "Not moving the message {} that we have seen before." ,  & message_id
667-                     ) ; 
668-                     folder
669643                }  else  { 
670644                    _target = target_folder ( context,  folder,  folder_meaning,  & headers) . await ?; 
671645                    & _target
@@ -768,7 +742,6 @@ impl Imap {
768742                        . fetch_many_msgs ( 
769743                            context, 
770744                            folder, 
771-                             uid_validity, 
772745                            uids_fetch_in_batch. split_off ( 0 ) , 
773746                            & uid_message_ids, 
774747                            fetch_partially, 
@@ -1383,12 +1356,10 @@ impl Session {
13831356/// 
13841357/// If the message is incorrect or there is a failure to write a message to the database, 
13851358/// it is skipped and the error is logged. 
1386- #[ expect( clippy:: too_many_arguments) ]  
13871359pub ( crate )  async  fn  fetch_many_msgs ( 
13881360        & mut  self , 
13891361        context :  & Context , 
13901362        folder :  & str , 
1391-         uidvalidity :  u32 , 
13921363        request_uids :  Vec < u32 > , 
13931364        uid_message_ids :  & BTreeMap < u32 ,  String > , 
13941365        fetch_partially :  bool , 
@@ -1514,9 +1485,6 @@ impl Session {
15141485                ) ; 
15151486                let  res = receive_imf_inner ( 
15161487                    context, 
1517-                     folder, 
1518-                     uidvalidity, 
1519-                     request_uid, 
15201488                    rfc724_mid, 
15211489                    body, 
15221490                    is_seen, 
@@ -1530,9 +1498,6 @@ impl Session {
15301498                    } 
15311499                    receive_imf_inner ( 
15321500                        context, 
1533-                         folder, 
1534-                         uidvalidity, 
1535-                         request_uid, 
15361501                        rfc724_mid, 
15371502                        body, 
15381503                        is_seen, 
@@ -2112,7 +2077,9 @@ pub async fn target_folder_cfg(
21122077
21132078    if  folder_meaning == FolderMeaning :: Spam  { 
21142079        spam_target_folder_cfg ( context,  headers) . await 
2115-     }  else  if  needs_move_to_mvbox ( context,  headers) . await ? { 
2080+     }  else  if  folder_meaning == FolderMeaning :: Inbox 
2081+         && needs_move_to_mvbox ( context,  headers) . await ?
2082+     { 
21162083        Ok ( Some ( Config :: ConfiguredMvboxFolder ) ) 
21172084    }  else  { 
21182085        Ok ( None ) 
@@ -2260,7 +2227,9 @@ fn get_folder_meaning_by_name(folder_name: &str) -> FolderMeaning {
22602227    ] ; 
22612228    let  lower = folder_name. to_lowercase ( ) ; 
22622229
2263-     if  SENT_NAMES . iter ( ) . any ( |s| s. to_lowercase ( )  == lower)  { 
2230+     if  lower == "inbox"  { 
2231+         FolderMeaning :: Inbox 
2232+     }  else  if  SENT_NAMES . iter ( ) . any ( |s| s. to_lowercase ( )  == lower)  { 
22642233        FolderMeaning :: Sent 
22652234    }  else  if  SPAM_NAMES . iter ( ) . any ( |s| s. to_lowercase ( )  == lower)  { 
22662235        FolderMeaning :: Spam 
@@ -2416,15 +2385,6 @@ pub(crate) async fn prefetch_should_download(
24162385    Ok ( should_download) 
24172386} 
24182387
2419- /// Returns whether a message is a duplicate (resent message). 
2420- pub ( crate )  fn  is_dup_msg ( is_chat_msg :  bool ,  ts_sent :  i64 ,  ts_sent_old :  i64 )  -> bool  { 
2421-     // If the existing message has timestamp_sent == 0, that means we don't know its actual sent 
2422-     // timestamp, so don't delete the new message. E.g. outgoing messages have zero timestamp_sent 
2423-     // because they are stored to the db before sending. Also consider as duplicates only messages 
2424-     // with greater timestamp to avoid deleting both messages in a multi-device setting. 
2425-     is_chat_msg && ts_sent_old != 0  && ts_sent > ts_sent_old
2426- } 
2427- 
24282388/// Marks messages in `msgs` table as seen, searching for them by UID. 
24292389/// 
24302390/// Returns updated chat ID if any message was marked as seen. 
0 commit comments