From 2dd7ee346fdc014b536de8cbbfe7630bac73a43b Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Wed, 10 Jun 2009 08:07:55 -0400
Subject: [PATCH] - Fixed many 'skip_deleted' issues (#1485634) - Fixed messages list sorting on servers without SORT capability - some preformance improvements

---
 program/steps/mail/show.inc |   28 ++++++++++++++--------------
 1 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/program/steps/mail/show.inc b/program/steps/mail/show.inc
index 9beb425..6ab5ba8 100644
--- a/program/steps/mail/show.inc
+++ b/program/steps/mail/show.inc
@@ -98,20 +98,8 @@
     {
     $next = $prev = $first = $last = -1;
 
-    if ((!($_SESSION['sort_col'] == 'date' && $_SESSION['sort_order'] == 'DESC') &&
-      $IMAP->get_capability('sort')) || !empty($_REQUEST['_search']))
-      {
-      // Only if we use custom sorting
-      $a_msg_index = $IMAP->message_index(NULL, $_SESSION['sort_col'], $_SESSION['sort_order']);
-
-      $MESSAGE->index = array_search($IMAP->get_id($MESSAGE->uid), $a_msg_index);
-
-      $prev = isset($a_msg_index[$MESSAGE->index-1]) ? $IMAP->get_uid($a_msg_index[$MESSAGE->index-1]) : -1 ;
-      $first = count($a_msg_index)>0 ? $IMAP->get_uid($a_msg_index[0]) : -1;
-      $next = isset($a_msg_index[$MESSAGE->index+1]) ? $IMAP->get_uid($a_msg_index[$MESSAGE->index+1]) : -1 ;
-      $last = count($a_msg_index)>0 ? $IMAP->get_uid($a_msg_index[count($a_msg_index)-1]) : -1;
-      }
-    else
+    if ($_SESSION['sort_col'] == 'date' && $_SESSION['sort_order'] != 'DESC'
+	&& empty($_REQUEST['_search']) && !$IMAP->skip_deleted)
       {
       // this assumes that we are sorted by date_DESC
       $cnt = $IMAP->messagecount();
@@ -123,6 +111,18 @@
       $next = $IMAP->get_uid($seq - 1);
       $last = $IMAP->get_uid(1);
       }
+    else 
+      {
+      // Only if we use custom sorting
+      $a_msg_index = $IMAP->message_index(NULL, $_SESSION['sort_col'], $_SESSION['sort_order']);
+
+      $MESSAGE->index = array_search($IMAP->get_id($MESSAGE->uid), $a_msg_index);
+
+      $prev = isset($a_msg_index[$MESSAGE->index-1]) ? $IMAP->get_uid($a_msg_index[$MESSAGE->index-1]) : -1 ;
+      $first = count($a_msg_index)>0 ? $IMAP->get_uid($a_msg_index[0]) : -1;
+      $next = isset($a_msg_index[$MESSAGE->index+1]) ? $IMAP->get_uid($a_msg_index[$MESSAGE->index+1]) : -1 ;
+      $last = count($a_msg_index)>0 ? $IMAP->get_uid($a_msg_index[count($a_msg_index)-1]) : -1;
+      }
 
     if ($prev > 0)
       $OUTPUT->set_env('prev_uid', $prev);

--
Gitblit v1.9.1