summaryrefslogtreecommitdiff
path: root/program/lib
diff options
context:
space:
mode:
authorThomas Bruederli <thomas@roundcube.net>2014-01-16 15:41:19 +0100
committerThomas Bruederli <thomas@roundcube.net>2014-01-16 15:41:19 +0100
commit2c33c7e38bc767330b4eebdc9e4d234caca72966 (patch)
tree4dc81413ed6366c0c942fb67ca8aa7e39d049647 /program/lib
parent2baeac116abef9d5bcb748c687577d16dce868a0 (diff)
Make message pagenav (prev/next) work with sorted multi-folder search results
Diffstat (limited to 'program/lib')
-rw-r--r--program/lib/Roundcube/rcube_imap.php10
-rw-r--r--program/lib/Roundcube/rcube_result_multifolder.php40
2 files changed, 45 insertions, 5 deletions
diff --git a/program/lib/Roundcube/rcube_imap.php b/program/lib/Roundcube/rcube_imap.php
index e265946f2..847bcfa70 100644
--- a/program/lib/Roundcube/rcube_imap.php
+++ b/program/lib/Roundcube/rcube_imap.php
@@ -973,6 +973,9 @@ class rcube_imap extends rcube_storage
$a_msg_headers = $this->conn->sortHeaders($a_msg_headers, $sort_field, $this->sort_order);
}
+ // store (sorted) message index
+ $search_set->set_message_index($a_msg_headers, $sort_field, $this->sort_order);
+
// only return the requested part of the set
$slice_length = min($page_size, $cnt - ($to > $cnt ? $from : $to));
$a_msg_headers = array_slice(array_values($a_msg_headers), $from, $slice_length);
@@ -1279,8 +1282,13 @@ class rcube_imap extends rcube_storage
return new rcube_result_index($folder, '* SORT');
}
+ if ($this->search_set instanceof rcube_result_multifolder) {
+ $index = $this->search_set;
+ $index->folder = $folder;
+ // TODO: handle changed sorting
+ }
// search result is an index with the same sorting?
- if (($this->search_set instanceof rcube_result_index)
+ else if (($this->search_set instanceof rcube_result_index)
&& ((!$this->sort_field && !$this->search_sorted) ||
($this->search_sorted && $this->search_sort_field == $this->sort_field))
) {
diff --git a/program/lib/Roundcube/rcube_result_multifolder.php b/program/lib/Roundcube/rcube_result_multifolder.php
index 8d7ae5de8..277a6d1ea 100644
--- a/program/lib/Roundcube/rcube_result_multifolder.php
+++ b/program/lib/Roundcube/rcube_result_multifolder.php
@@ -28,8 +28,11 @@ class rcube_result_multifolder
{
public $multi = true;
public $sets = array();
+ public $folder;
protected $meta = array();
+ protected $index = array();
+ protected $sorting;
protected $order = 'ASC';
@@ -53,6 +56,19 @@ class rcube_result_multifolder
$this->meta['count'] += $result->count();
}
+ /**
+ * Store a global index of (sorted) message UIDs
+ */
+ public function set_message_index($headers, $sort_field, $sort_order)
+ {
+ $this->index = array();
+ foreach ($headers as $header) {
+ $this->index[] = $header->uid . '-' . $header->folder;
+ }
+
+ $this->sorting = $sort_field;
+ $this->order = $sort_order;
+ }
/**
* Checks the result from IMAP command
@@ -119,7 +135,10 @@ class rcube_result_multifolder
*/
public function exists($msgid, $get_index = false)
{
- return false;
+ if (!empty($this->folder)) {
+ $msgid .= '-' . $this->folder;
+ }
+ return array_search($msgid, $this->index);
}
@@ -157,7 +176,7 @@ class rcube_result_multifolder
*/
public function get()
{
- return array();
+ return $this->index;
}
@@ -179,9 +198,13 @@ class rcube_result_multifolder
*
* @return int Element value
*/
- public function get_element($index)
+ public function get_element($idx)
{
- return null;
+ switch ($idx) {
+ case 'FIRST': return $this->index[0];
+ case 'LAST': return end($this->index);
+ default: return $this->index[$idx];
+ }
}
@@ -195,6 +218,15 @@ class rcube_result_multifolder
*/
public function get_parameters($param=null)
{
+ $params = array(
+ 'SORT' => $this->sorting,
+ 'ORDER' => $this->order,
+ );
+
+ if ($param !== null) {
+ return $params[$param];
+ }
+
return $params;
}