diff options
-rw-r--r-- | program/js/app.js | 3 | ||||
-rw-r--r-- | program/lib/Roundcube/rcube_imap.php | 10 | ||||
-rw-r--r-- | program/lib/Roundcube/rcube_result_multifolder.php | 40 | ||||
-rw-r--r-- | program/steps/mail/func.inc | 4 | ||||
-rw-r--r-- | program/steps/mail/list.inc | 2 | ||||
-rw-r--r-- | program/steps/mail/search.inc | 8 |
6 files changed, 56 insertions, 11 deletions
diff --git a/program/js/app.js b/program/js/app.js index 2717e35d5..5eae82351 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -696,6 +696,7 @@ function rcube_webmail() break; case 'list': + // TODO: don't reset search but re-send for the new folder if (props && props != '') this.reset_qsearch(); if (this.env.action == 'compose' && this.env.extwin) @@ -1620,7 +1621,7 @@ function rcube_webmail() var uid = list.get_single_selection(); - if (uid && this.env.mailbox == this.env.drafts_mailbox) + if (uid && (this.env.messages[uid].mbox || this.env.mailbox) == this.env.drafts_mailbox) this.open_compose_step({ _draft_uid: uid, _mbox: this.env.mailbox }); else if (uid) this.show_message(uid, false, false); 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; } diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc index 3848ec540..45d4242f9 100644 --- a/program/steps/mail/func.inc +++ b/program/steps/mail/func.inc @@ -76,9 +76,11 @@ if (($_uid = get_input_value('_uid', RCUBE_INPUT_GPC)) && preg_match('/^\d+-[^, $_REQUEST['_uid'] = $_uid; unset($_uid); - if (empty($_REQUEST['_mbox']) && !empty($mbox)) { + // override mbox + if (!empty($mbox)) { $_GET['_mbox'] = $mbox; $_POST['_mbox'] = $mbox; + $RCMAIL->storage->set_folder(($_SESSION['mbox'] = $mbox)); } } diff --git a/program/steps/mail/list.inc b/program/steps/mail/list.inc index 4b2a955b7..a77d60f32 100644 --- a/program/steps/mail/list.inc +++ b/program/steps/mail/list.inc @@ -90,6 +90,8 @@ if (!empty($_REQUEST['_search']) && isset($_SESSION['search']) if ($header->parent_uid) $header->parent_uid .= '-'.$header->folder; } + + $OUTPUT->command('select_folder', ''); } } // remove old search data diff --git a/program/steps/mail/search.inc b/program/steps/mail/search.inc index 5ce9fe6e2..b45cdc0de 100644 --- a/program/steps/mail/search.inc +++ b/program/steps/mail/search.inc @@ -114,6 +114,10 @@ if ($search_str) { $RCMAIL->storage->search($mboxes, $search_str, $imap_charset, $sort_column); } +// 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'); + // save search results in session if (!is_array($_SESSION['search'])) { $_SESSION['search'] = array(); @@ -125,10 +129,6 @@ if ($search_str) { } $_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']; |