From 26eca02ee4efc0a305d406537441169f0842ca2d Mon Sep 17 00:00:00 2001 From: jmunro Date: Wed, 3 Apr 2002 15:43:55 +0000 Subject: [PATCH] fallback to client side sorting if server side sorting is selected but not supported by the IMAP server. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@2675 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/imap_messages.php | 11 ++++++-- functions/mailbox_display.php | 49 ++++++++++++++++++++++++----------- 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/functions/imap_messages.php b/functions/imap_messages.php index 18b89234..2ca805e6 100755 --- a/functions/imap_messages.php +++ b/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; diff --git a/functions/mailbox_display.php b/functions/mailbox_display.php index 649497ef..b727d456 100644 --- a/functions/mailbox_display.php +++ b/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 '
Thread sorting is not'. + ' supported by your IMAP server.
Please report this'. + 'to the system administrator.
'; + $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 '
Server-side sorting '. + 'is not supported by your IMAP server.
Please report this'. + ' to the system administrator.
'; + $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. */ -- 2.25.1