Fixing #550595, start_msg needs to be readjusted if all messages on the
[squirrelmail.git] / functions / mailbox_display.php
index 1e1fd41763b7ee9365a13bb341661ec421e6e789..6e6692f993c0208d78d2bcb66dc4d1db5a5c8146 100644 (file)
@@ -231,6 +231,17 @@ function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
     $auto_expunge, $thread_sort_messages, $allow_server_sort,
     $data_dir, $username, $server_sort_order;
 
+   /* if $start_msg is lower than $num_msgs, we probably deleted all messages
+    * in the last page. We need to re-adjust the start_msg
+    */
+
+   if($start_msg > $num_msgs) {
+       $start_msg -= $show_num;
+       if($start_msg < 1) {
+         $start_msg = 1;
+       }
+   }
+
   /* This code and the next if() block check for
    * server-side sorting methods. The $id array is
    * formatted and $sort is set to 6 to disable 
@@ -242,7 +253,7 @@ function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
       echo '<b><small><center><font color=red>Thread sorting is not'.
              ' supported by your IMAP server.<br>Please report this'.
              'to the system administrator.</center></small></b>';
-     $thread_sort_messages == 0; 
+     $thread_sort_messages = 0; 
     $id = array();
   }
   else {