+ /* If autoexpunge is turned on, then do it now. */
+ $mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox);
+ $srt = $sort;
+ /* If autoexpunge is turned on, then do it now. */
+ if ($auto_expunge == true) {
+ $exp_cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, false, '');
+ $mbxresponse['EXISTS'] = $mbxresponse['EXISTS'] - $exp_cnt;
+ $num_msgs = $mbxresponse['EXISTS'];
+ }
+
+ if ($mbxresponse['EXISTS']>0) {
+ /* 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
+ * SM internal sorting
+ */
+
+ if ($thread_sort_messages == 1) {
+ $mode = 'thread';
+ } elseif ($allow_server_sort == 1) {
+ $mode = 'serversort';
+ } else {
+ $mode = '';
+ }
+
+ switch ($mode) {
+ case 'thread':
+ session_unregister('msort');
+ session_unregister('msgs');
+ $msgs = getThreadMessages($imapConnection, $start_msg, $show_num,
+ $num_msgs);
+ if ($msgs === false) {
+ 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;
+ $msort = $msgs = array();
+ session_register('msort');
+ session_register('msgs');
+ } else {
+ $msort= $msgs;
+ $sort = 6;
+ session_register('msort');
+ session_register('msgs');
+ }
+
+ break;
+ case 'serversort':
+ $msgs = getServerSortMessages($imapConnection, $start_msg, $show_num,
+ $num_msgs, $sort, $mbxresponse);
+ if ($msgs === false) {
+ echo '<b><small><center><font color=red>' .
+ _( "Server-side sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
+ '</center></small></b>';
+ $sort = $server_sort_order;
+ $allow_server_sort = FALSE;
+ $msort = $msgs = array();
+ session_register('msort');
+ session_register('msgs');
+ $id = array();
+ } else {
+ $sort = 6;
+ $msort = $msgs;
+ session_register('msort');
+ session_register('msgs');
+ }
+ break;
+ default:
+ if (!$use_cache) {
+ session_unregister('msgs');
+ session_unregister('msort');
+ $msgs= getSelfSortMessages($imapConnection, $start_msg, $show_num,
+ $num_msgs, $sort, $mbxresponse);
+ $msort = calc_msort($msgs, $sort);
+ session_register('msort');
+ session_register('msgs');
+ } /* !use cache */
+ break;
+ } // switch
+ } /* if exists > 0 */
+
+ $res = getEndMessage($start_msg, $show_num, $num_msgs);
+ $start_msg = $res[0];
+ $end_msg = $res[1];
+
+ $paginator_str = get_paginator_str($mailbox, $start_msg, $end_msg,
+ $num_msgs, $show_num, $sort);
+
+ $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);