فهرست منبع

fallback to client side sorting if server side sorting is selected but not supported by the IMAP server.

jmunro 23 سال پیش
والد
کامیت
73c456a9ee
2فایلهای تغییر یافته به همراه43 افزوده شده و 17 حذف شده
  1. 9 2
      functions/imap_messages.php
  2. 34 15
      functions/mailbox_display.php

+ 9 - 2
functions/imap_messages.php

@@ -128,7 +128,7 @@ function sqimap_get_sort_order ($imap_stream, $sort) {
     if (!empty($sort_on[$sort])) {
         $sort_query = "$sid SORT ($sort_on[$sort]) ".strtoupper($default_charset)." ALL\r\n";
         fputs($imap_stream, $sort_query);
-        $sort_test = sqimap_read_data($imap_stream, $sid, true, $response, $message);
+        $sort_test = sqimap_read_data($imap_stream, $sid, false, $response, $message);
     }
     if (preg_match("/^\* SORT (.+)$/", $sort_test[0], $regs)) {
         $server_sort_array = preg_split("/ /", trim($regs[1]));
@@ -136,6 +136,9 @@ function sqimap_get_sort_order ($imap_stream, $sort) {
     if ($sort == 0 || $sort == 2 || $sort == 4) {
        $server_sort_array = array_reverse($server_sort_array);
     }
+    if (!preg_match("/OK/", $response)) {
+	   $server_sort_array = 'no';
+	}
     session_register('server_sort_array');
     return $server_sort_array;
 }
@@ -236,13 +239,17 @@ function get_thread_sort ($imap_stream) {
     }
     $thread_query = "$sid THREAD $sort_type ".strtoupper($default_charset)." ALL\r\n";
     fputs($imap_stream, $thread_query);
-    $thread_test = sqimap_read_data($imap_stream, $sid, true, $response, $message);
+    $thread_test = sqimap_read_data($imap_stream, $sid, false, $response, $message);
     if (preg_match("/^\* THREAD (.+)$/", $thread_test[0], $regs)) {
        $thread_list = trim($regs[1]);
     }
     else {
        $thread_list = "";
     }
+    if (!preg_match("/OK/", $response)) {
+	   $server_sort_array = 'no';
+	   return $server_sort_array;
+	}
     $thread_temp = preg_split("//", $thread_list, -1, PREG_SPLIT_NO_EMPTY);
     $char_count = count($thread_temp);
     $counter = 0;

+ 34 - 15
functions/mailbox_display.php

@@ -236,27 +236,46 @@ function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
    */
   if ($thread_sort_messages == 1) {
     $id = get_thread_sort($imapConnection);
-    $sort = 6;
-    if ($start_msg + ($show_num - 1) < $num_msgs) {
-      $end_msg = $start_msg + ($show_num-1);
-    } 
-	else {
-      $end_msg = $num_msgs;
-    }
-    $id = array_slice($id, ($start_msg-1), ($end_msg));
+  if ($id == 'no') {
+      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; 
+    $id = array();
+  }
+  else {
+      $sort = 6;
+      if ($start_msg + ($show_num - 1) < $num_msgs) {
+        $end_msg = $start_msg + ($show_num-1);
+      } 
+      else {
+        $end_msg = $num_msgs;
+      }
+      $id = array_slice($id, ($start_msg-1), ($end_msg));
+      }
   }
 
   if ($allow_server_sort == TRUE && $thread_sort_messages != 1) {
     $server_sort_order = $sort;
     $id = sqimap_get_sort_order($imapConnection, $server_sort_order);
-    $sort = 6;
-    if ($start_msg + ($show_num - 1) < $num_msgs) {
-      $end_msg = $start_msg + ($show_num-1);
-    } 
+  if ($id == 'no') {
+    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;
+	  $id = array();
+	}
 	else {
-      $end_msg = $num_msgs;
-    }
-    $id = array_slice($id, ($start_msg-1), ($end_msg));
+      $sort = 6;
+      if ($start_msg + ($show_num - 1) < $num_msgs) {
+        $end_msg = $start_msg + ($show_num-1);
+      } 
+	  else {
+        $end_msg = $num_msgs;
+      }
+      $id = array_slice($id, ($start_msg-1), ($end_msg));
+	}
   }
 
   /* If autoexpunge is turned on, then do it now. */