Make message pagenav (prev/next) work with sorted multi-folder search results

pull/193/head
Thomas Bruederli 11 years ago
parent 2baeac116a
commit 2c33c7e38b

@ -696,6 +696,7 @@ function rcube_webmail()
break; break;
case 'list': case 'list':
// TODO: don't reset search but re-send for the new folder
if (props && props != '') if (props && props != '')
this.reset_qsearch(); this.reset_qsearch();
if (this.env.action == 'compose' && this.env.extwin) if (this.env.action == 'compose' && this.env.extwin)
@ -1620,7 +1621,7 @@ function rcube_webmail()
var uid = list.get_single_selection(); 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 }); this.open_compose_step({ _draft_uid: uid, _mbox: this.env.mailbox });
else if (uid) else if (uid)
this.show_message(uid, false, false); this.show_message(uid, false, false);

@ -973,6 +973,9 @@ class rcube_imap extends rcube_storage
$a_msg_headers = $this->conn->sortHeaders($a_msg_headers, $sort_field, $this->sort_order); $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 // only return the requested part of the set
$slice_length = min($page_size, $cnt - ($to > $cnt ? $from : $to)); $slice_length = min($page_size, $cnt - ($to > $cnt ? $from : $to));
$a_msg_headers = array_slice(array_values($a_msg_headers), $from, $slice_length); $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'); 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? // 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->sort_field && !$this->search_sorted) ||
($this->search_sorted && $this->search_sort_field == $this->sort_field)) ($this->search_sorted && $this->search_sort_field == $this->sort_field))
) { ) {

@ -28,8 +28,11 @@ class rcube_result_multifolder
{ {
public $multi = true; public $multi = true;
public $sets = array(); public $sets = array();
public $folder;
protected $meta = array(); protected $meta = array();
protected $index = array();
protected $sorting;
protected $order = 'ASC'; protected $order = 'ASC';
@ -53,6 +56,19 @@ class rcube_result_multifolder
$this->meta['count'] += $result->count(); $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 * Checks the result from IMAP command
@ -119,7 +135,10 @@ class rcube_result_multifolder
*/ */
public function exists($msgid, $get_index = false) 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() public function get()
{ {
return array(); return $this->index;
} }
@ -179,9 +198,13 @@ class rcube_result_multifolder
* *
* @return int Element value * @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) public function get_parameters($param=null)
{ {
$params = array(
'SORT' => $this->sorting,
'ORDER' => $this->order,
);
if ($param !== null) {
return $params[$param];
}
return $params; return $params;
} }

@ -76,9 +76,11 @@ if (($_uid = get_input_value('_uid', RCUBE_INPUT_GPC)) && preg_match('/^\d+-[^,
$_REQUEST['_uid'] = $_uid; $_REQUEST['_uid'] = $_uid;
unset($_uid); unset($_uid);
if (empty($_REQUEST['_mbox']) && !empty($mbox)) { // override mbox
if (!empty($mbox)) {
$_GET['_mbox'] = $mbox; $_GET['_mbox'] = $mbox;
$_POST['_mbox'] = $mbox; $_POST['_mbox'] = $mbox;
$RCMAIL->storage->set_folder(($_SESSION['mbox'] = $mbox));
} }
} }

@ -90,6 +90,8 @@ if (!empty($_REQUEST['_search']) && isset($_SESSION['search'])
if ($header->parent_uid) if ($header->parent_uid)
$header->parent_uid .= '-'.$header->folder; $header->parent_uid .= '-'.$header->folder;
} }
$OUTPUT->command('select_folder', '');
} }
} }
// remove old search data // remove old search data

@ -114,6 +114,10 @@ if ($search_str) {
$RCMAIL->storage->search($mboxes, $search_str, $imap_charset, $sort_column); $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 // save search results in session
if (!is_array($_SESSION['search'])) { if (!is_array($_SESSION['search'])) {
$_SESSION['search'] = array(); $_SESSION['search'] = array();
@ -125,10 +129,6 @@ if ($search_str) {
} }
$_SESSION['search_request'] = $search_request; $_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 // Add 'folder' column to list
if ($_SESSION['search'][1]->multi) { if ($_SESSION['search'][1]->multi) {
$a_show_cols = $_SESSION['list_attrib']['columns'] ? $_SESSION['list_attrib']['columns'] : (array)$CONFIG['list_cols']; $a_show_cols = $_SESSION['list_attrib']['columns'] ? $_SESSION['list_attrib']['columns'] : (array)$CONFIG['list_cols'];

Loading…
Cancel
Save