From 9424cc71b3c71ee408795669c9cac04985dc5a25 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Sat, 15 Nov 2008 10:30:19 -0500
Subject: [PATCH] - fix

---
 program/include/rcube_imap.php |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php
index 3fe651d..5764a1f 100644
--- a/program/include/rcube_imap.php
+++ b/program/include/rcube_imap.php
@@ -673,11 +673,12 @@
       return array_values($a_msg_headers);
       }
     else { // SEARCH searching result, need sorting
-      if ($cnt > $this->pagesize * 2) {
+      $cnt = count($msgs);
+      if ($cnt > 300) { // experimantal best result
         // use memory less expensive (and quick) method for big result set
 	$a_index = $this->message_index($mailbox, $this->sort_field, $this->sort_order);
         // get messages uids for one page...
-        $msgs = array_slice(array_keys($a_index), $start_msg, min(count($msgs)-$start_msg, $this->page_size));
+        $msgs = array_slice(array_keys($a_index), $start_msg, min($cnt-$start_msg, $this->page_size));
 	// ...and fetch headers
         $this->_fetch_headers($mailbox, join(',', $msgs), $a_msg_headers, NULL);
 
@@ -703,7 +704,7 @@
         $a_msg_headers = iil_SortHeaders($a_msg_headers, $this->sort_field, $this->sort_order);
       
         // only return the requested part of the set
-        return array_slice(array_values($a_msg_headers), $start_msg, min(count($msgs)-$start_msg, $this->page_size));
+        return array_slice(array_values($a_msg_headers), $start_msg, min($cnt-$start_msg, $this->page_size));
         }
       }
     }

--
Gitblit v1.9.1