From 2baeac116abef9d5bcb748c687577d16dce868a0 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli <thomas@roundcube.net> Date: Thu, 16 Jan 2014 08:17:08 -0500 Subject: [PATCH] Fix sorting and paging in cross-folder searches --- program/steps/mail/list.inc | 16 ++++++++ program/steps/mail/search.inc | 42 ++++++--------------- program/lib/Roundcube/rcube_imap.php | 4 +- 3 files changed, 30 insertions(+), 32 deletions(-) diff --git a/program/lib/Roundcube/rcube_imap.php b/program/lib/Roundcube/rcube_imap.php index 0cf34b2..e265946 100644 --- a/program/lib/Roundcube/rcube_imap.php +++ b/program/lib/Roundcube/rcube_imap.php @@ -952,7 +952,7 @@ $search_set = $this->search_set; $this->sort_field = null; - $this->page_size = 100; // limit to 100 messages per folder + $this->page_size = 1000; // fetch up to 1000 matching messages per folder $a_msg_headers = array(); foreach ($search_set->sets as $resultset) { @@ -970,7 +970,7 @@ // sort headers if (!$this->threading && !empty($a_msg_headers)) { - $a_msg_headers = $this->conn->sortHeaders($a_msg_headers, $this->sort_field, $this->sort_order); + $a_msg_headers = $this->conn->sortHeaders($a_msg_headers, $sort_field, $this->sort_order); } // only return the requested part of the set diff --git a/program/steps/mail/list.inc b/program/steps/mail/list.inc index 277564c..4b2a955 100644 --- a/program/steps/mail/list.inc +++ b/program/steps/mail/list.inc @@ -75,6 +75,22 @@ && $_SESSION['search_request'] == $_REQUEST['_search'] ) { $_SESSION['search'] = $RCMAIL->storage->get_search_set(); + + // multi-folder search + if ($_SESSION['search'][1]->multi) { + if (empty($cols)) + $cols = $_SESSION['list_attrib']['columns'] ? $_SESSION['list_attrib']['columns'] : (array)$CONFIG['list_cols']; + if (!in_array('folder', $cols)) + $cols[] = 'folder'; // Add 'folder' column to list + + // make message UIDs unique by appending the folder name + foreach ($a_headers as $i => $header) { + $header->uid .= '-'.$header->folder; + $header->flags['skip_mbox_check'] = true; + if ($header->parent_uid) + $header->parent_uid .= '-'.$header->folder; + } + } } // remove old search data else if (empty($_REQUEST['_search']) && isset($_SESSION['search'])) { diff --git a/program/steps/mail/search.inc b/program/steps/mail/search.inc index 67fee75..5ce9fe6 100644 --- a/program/steps/mail/search.inc +++ b/program/steps/mail/search.inc @@ -111,7 +111,7 @@ // execute IMAP search if ($search_str) { - $RCMAIL->storage->search($mbox, $search_str, $imap_charset, $sort_column); + $RCMAIL->storage->search($mboxes, $search_str, $imap_charset, $sort_column); } // save search results in session @@ -125,43 +125,25 @@ } $_SESSION['search_request'] = $search_request; - // Get the headers $result_h = $RCMAIL->storage->list_messages($mbox, 1, $sort_column, rcmail_sort_order()); $count = $RCMAIL->storage->count($mbox, $RCMAIL->storage->get_threading() ? 'THREADS' : 'ALL'); // Add 'folder' column to list if ($_SESSION['search'][1]->multi) { - $a_show_cols = $_SESSION['list_attrib']['columns'] ? $_SESSION['list_attrib']['columns'] : (array)$CONFIG['list_cols']; - if (!in_array('folder', $a_show_cols)) - $a_show_cols[] = 'folder'; + $a_show_cols = $_SESSION['list_attrib']['columns'] ? $_SESSION['list_attrib']['columns'] : (array)$CONFIG['list_cols']; + if (!in_array('folder', $a_show_cols)) + $a_show_cols[] = 'folder'; - // make message UIDs unique by appending the folder name - foreach ($result_h as $i => $header) { - $header->uid .= '-'.$header->folder; - $header->flags['skip_mbox_check'] = true; - if ($header->parent_uid) - $header->parent_uid .= '-'.$header->folder; - } + // make message UIDs unique by appending the folder name + foreach ($result_h as $i => $header) { + $header->uid .= '-'.$header->folder; + $header->flags['skip_mbox_check'] = true; + if ($header->parent_uid) + $header->parent_uid .= '-'.$header->folder; + } - $OUTPUT->command('select_folder', ''); -} - -// Add 'folder' column to list -if ($_SESSION['search'][1]->multi) { - $a_show_cols = $_SESSION['list_attrib']['columns'] ? $_SESSION['list_attrib']['columns'] : (array)$CONFIG['list_cols']; - if (!in_array('folder', $a_show_cols)) - $a_show_cols[] = 'folder'; - - // make message UIDs unique by appending the folder name - foreach ($result_h as $i => $header) { - $header->uid .= '-'.$header->folder; - $header->flags['skip_mbox_check'] = true; - if ($header->parent_uid) - $header->parent_uid .= '-'.$header->folder; - } - - $OUTPUT->command('select_folder', ''); + $OUTPUT->command('select_folder', ''); } // Make sure we got the headers -- Gitblit v1.9.1