From 628706acdcb973154161b5862c30ce706a08455a Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 9 Oct 2013 12:04:17 +0200 Subject: Prepare message list to display IMAP folder --- program/lib/Roundcube/rcube_imap.php | 1 + program/lib/Roundcube/rcube_message_header.php | 9 +++++++++ 2 files changed, 10 insertions(+) (limited to 'program/lib/Roundcube') diff --git a/program/lib/Roundcube/rcube_imap.php b/program/lib/Roundcube/rcube_imap.php index 432227091..adac77b23 100644 --- a/program/lib/Roundcube/rcube_imap.php +++ b/program/lib/Roundcube/rcube_imap.php @@ -1111,6 +1111,7 @@ class rcube_imap extends rcube_storage } foreach ($headers as $h) { + $h->folder = $folder; $a_msg_headers[$h->uid] = $h; } diff --git a/program/lib/Roundcube/rcube_message_header.php b/program/lib/Roundcube/rcube_message_header.php index 2c5e2b6c8..2bda930eb 100644 --- a/program/lib/Roundcube/rcube_message_header.php +++ b/program/lib/Roundcube/rcube_message_header.php @@ -166,6 +166,13 @@ class rcube_message_header */ public $mdn_to; + /** + * IMAP folder this message is stored in + * + * @var string + */ + public $folder; + /** * Other message headers * @@ -189,6 +196,8 @@ class rcube_message_header 'reply-to' => 'replyto', 'cc' => 'cc', 'bcc' => 'bcc', + 'mbox' => 'folder', + 'folder' => 'folder', 'content-transfer-encoding' => 'encoding', 'in-reply-to' => 'in_reply_to', 'content-type' => 'ctype', -- cgit v1.2.3 From 566747af00ae413c942a7c6702e24c044af36f17 Mon Sep 17 00:00:00 2001 From: Thomas Date: Mon, 14 Oct 2013 21:57:53 +0200 Subject: First attempt to search in multiple folders; do it multi-threaded using pthreads if available --- program/lib/Roundcube/rcube_imap.php | 80 ++++- program/lib/Roundcube/rcube_imap_search.php | 327 +++++++++++++++++++++ program/lib/Roundcube/rcube_result_multifolder.php | 211 +++++++++++++ program/steps/mail/search.inc | 10 +- 4 files changed, 619 insertions(+), 9 deletions(-) create mode 100644 program/lib/Roundcube/rcube_imap_search.php create mode 100644 program/lib/Roundcube/rcube_result_multifolder.php (limited to 'program/lib/Roundcube') diff --git a/program/lib/Roundcube/rcube_imap.php b/program/lib/Roundcube/rcube_imap.php index adac77b23..db94e7678 100644 --- a/program/lib/Roundcube/rcube_imap.php +++ b/program/lib/Roundcube/rcube_imap.php @@ -945,6 +945,50 @@ class rcube_imap extends rcube_storage return array(); } + // gather messages from a multi-folder search + if ($this->search_set->multi) { + $page_size = $this->page_size; + $sort_field = $this->sort_field; + $search_set = $this->search_set; + + $this->sort_field = null; + $this->page_size = 100; // limit to 100 messages per folder + + $a_msg_headers = array(); + foreach ($search_set->sets as $resultset) { + if (!$resultset->is_empty()) { + $this->search_set = $resultset; + $this->search_threads = $resultset instanceof rcube_result_thread; + $a_msg_headers = array_merge($a_msg_headers, $this->list_search_messages($resultset->get_parameters('MAILBOX'), 1)); + } + } + + // do sorting and paging + $cnt = $search_set->count(); + $from = ($page-1) * $page_size; + $to = $from + $page_size; + + // sort headers + if (!$this->threading) { + $a_msg_headers = $this->conn->sortHeaders($a_msg_headers, $this->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); + + if ($slice) { + $a_msg_headers = array_slice($a_msg_headers, -$slice, $slice); + } + + // restore members + $this->sort_field = $sort_field; + $this->page_size = $page_size; + $this->search_set = $search_set; + + return $a_msg_headers; + } + // use saved messages from searching if ($this->threading) { return $this->list_search_thread_messages($folder, $page, $slice); @@ -1423,11 +1467,33 @@ class rcube_imap extends rcube_storage $str = 'ALL'; } - if (!strlen($folder)) { + if (empty($folder)) { $folder = $this->folder; } - $results = $this->search_index($folder, $str, $charset, $sort_field); + // multi-folder search + if (is_array($folder) && count($folder) > 1 && $str != 'ALL') { + new rcube_result_index; // trigger autoloader and make these classes available for threaded context + new rcube_result_thread; + + // connect IMAP + if (!defined('PTHREADS_INHERIT_ALL')) { + $this->check_connection(); + } + + $searcher = new rcube_imap_search($this->options, $this->conn); + $results = $searcher->exec( + $folder, + $str, + $charset ? $charset : $this->default_charset, + $sort_field && $this->get_capability('SORT') ? $sort_field : null, + $this->threading + ); + } + else { + $folder = is_array($folder) ? $folder[0] : $folder; + $results = $this->search_index($folder, $str, $charset, $sort_field); + } $this->set_search_set(array($str, $results, $charset, $sort_field, $this->threading || $this->search_sorted ? true : false)); @@ -1501,7 +1567,7 @@ class rcube_imap extends rcube_storage // but I've seen that Courier doesn't support UTF-8) if ($threads->is_error() && $charset && $charset != 'US-ASCII') { $threads = $this->conn->thread($folder, $this->threading, - $this->convert_criteria($criteria, $charset), true, 'US-ASCII'); + self::convert_criteria($criteria, $charset), true, 'US-ASCII'); } return $threads; @@ -1515,7 +1581,7 @@ class rcube_imap extends rcube_storage // but I've seen Courier with disabled UTF-8 support) if ($messages->is_error() && $charset && $charset != 'US-ASCII') { $messages = $this->conn->sort($folder, $sort_field, - $this->convert_criteria($criteria, $charset), true, 'US-ASCII'); + self::convert_criteria($criteria, $charset), true, 'US-ASCII'); } if (!$messages->is_error()) { @@ -1530,7 +1596,7 @@ class rcube_imap extends rcube_storage // Error, try with US-ASCII (some servers may support only US-ASCII) if ($messages->is_error() && $charset && $charset != 'US-ASCII') { $messages = $this->conn->search($folder, - $this->convert_criteria($criteria, $charset), true); + self::convert_criteria($criteria, $charset), true); } $this->search_sorted = false; @@ -1548,7 +1614,7 @@ class rcube_imap extends rcube_storage * * @return string Search string */ - protected function convert_criteria($str, $charset, $dest_charset='US-ASCII') + public static function convert_criteria($str, $charset, $dest_charset='US-ASCII') { // convert strings to US_ASCII if (preg_match_all('/\{([0-9]+)\}\r\n/', $str, $matches, PREG_OFFSET_CAPTURE)) { @@ -2410,7 +2476,7 @@ class rcube_imap extends rcube_storage $this->refresh_search(); } else { - $this->search_set->filter(explode(',', $uids)); + $this->search_set->filter(explode(',', $uids), $this->folder); } } diff --git a/program/lib/Roundcube/rcube_imap_search.php b/program/lib/Roundcube/rcube_imap_search.php new file mode 100644 index 000000000..ed4face98 --- /dev/null +++ b/program/lib/Roundcube/rcube_imap_search.php @@ -0,0 +1,327 @@ + | + +-----------------------------------------------------------------------+ +*/ + +// create classes defined by the pthreads module if that isn't installed +if (!defined('PTHREADS_INHERIT_ALL')) { + class Worker { } + class Stackable { } +} + +/** + * Class to control search jobs on multiple IMAP folders. + * This implement a simple threads pool using the pthreads extension. + * + * @package Framework + * @subpackage Storage + * @author Thomas Bruederli + */ +class rcube_imap_search +{ + public $options = array(); + + private $size = 10; + private $next = 0; + private $workers = array(); + private $states = array(); + private $jobs = array(); + private $conn; + + /** + * Default constructor + */ + public function __construct($options, $conn) + { + $this->options = $options; + $this->conn = $conn; + } + + /** + * Invoke search request to IMAP server + * + * @param array $folders List of IMAP folders to search in + * @param string $str Search criteria + * @param string $charset Search charset + * @param string $sort_field Header field to sort by + * @param boolean $threading True if threaded listing is active + */ + public function exec($folders, $str, $charset = null, $sort_field = null, $threading=null) + { + $pthreads = defined('PTHREADS_INHERIT_ALL'); + + // start a search job for every folder to search in + foreach ($folders as $folder) { + $job = new rcube_imap_search_job($folder, $str, $charset, $sort_field, $threading); + if ($pthreads && $this->submit($job)) { + $this->jobs[] = $job; + } + else { + $job->worker = $this; + $job->run(); + $this->jobs[] = $job; + } + } + + // wait for all workers to be done + $this->shutdown(); + + // gather results + $results = new rcube_result_multifolder; + foreach ($this->jobs as $job) { + $results->add($job->get_result()); + } + + return $results; + } + + /** + * Assign the given job object to one of the worker threads for execution + */ + public function submit(Stackable $job) + { + if (count($this->workers) < $this->size) { + $id = count($this->workers); + $this->workers[$id] = new rcube_imap_search_worker($id, $this->options); + $this->workers[$id]->start(PTHREADS_INHERIT_ALL); + + if ($this->workers[$id]->stack($job)) { + return $job; + } + else { + // trigger_error(sprintf("Failed to push Stackable onto %s", $id), E_USER_WARNING); + } + } + if (($worker = $this->workers[$this->next])) { + $this->next = ($this->next+1) % $this->size; + if ($worker->stack($job)) { + return $job; + } + else { + // trigger_error(sprintf("Failed to stack onto selected worker %s", $worker->id), E_USER_WARNING); + } + } + else { + // trigger_error(sprintf("Failed to select a worker for Stackable"), E_USER_WARNING); + } + + return false; + } + + /** + * Shutdown the pool of threads cleanly, retaining exit status locally + */ + public function shutdown() + { + foreach ($this->workers as $worker) { + $this->states[$worker->getThreadId()] = $worker->shutdown(); + $worker->close(); + } + + # console('shutdown', $this->states); + } + + /** + * Get connection to the IMAP server + * (used for single-thread mode) + */ + public function get_imap() + { + return $this->conn; + } +} + + +/** + * Stackable item to run the search on a specific IMAP folder + */ +class rcube_imap_search_job extends Stackable +{ + private $folder; + private $search; + private $charset; + private $sort_field; + private $threading; + private $searchset; + private $result; + private $pagesize = 100; + + public function __construct($folder, $str, $charset = null, $sort_field = null, $threading=false) + { + $this->folder = $folder; + $this->search = $str; + $this->charset = $charset; + $this->sort_field = $sort_field; + $this->threading = $threading; + } + + public function run() + { + #trigger_error("Start search $this->folder", E_USER_NOTICE); + $this->result = $this->search_index(); + #trigger_error("End search $this->folder: " . $this->result->count(), E_USER_NOTICE); + } + + /** + * Copy of rcube_imap::search_index() + */ + protected function search_index() + { + $criteria = $this->search; + $charset = $this->charset; + + $imap = $this->worker->get_imap(); + + if (!$imap->connected()) { + if ($this->threading) { + return new rcube_result_thread(); + } + else { + return new rcube_result_index(); + } + } + + if ($this->worker->options['skip_deleted'] && !preg_match('/UNDELETED/', $criteria)) { + $criteria = 'UNDELETED '.$criteria; + } + + // unset CHARSET if criteria string is ASCII, this way + // SEARCH won't be re-sent after "unsupported charset" response + if ($charset && $charset != 'US-ASCII' && is_ascii($criteria)) { + $charset = 'US-ASCII'; + } + + if ($this->threading) { + $threads = $imap->thread($this->folder, $this->threading, $criteria, true, $charset); + + // Error, try with US-ASCII (RFC5256: SORT/THREAD must support US-ASCII and UTF-8, + // but I've seen that Courier doesn't support UTF-8) + if ($threads->is_error() && $charset && $charset != 'US-ASCII') { + $threads = $imap->thread($this->folder, $this->threading, + rcube_imap::convert_criteria($criteria, $charset), true, 'US-ASCII'); + } + + return $threads; + } + + if ($this->sort_field) { + $messages = $imap->sort($this->folder, $this->sort_field, $criteria, true, $charset); + + // Error, try with US-ASCII (RFC5256: SORT/THREAD must support US-ASCII and UTF-8, + // but I've seen Courier with disabled UTF-8 support) + if ($messages->is_error() && $charset && $charset != 'US-ASCII') { + $messages = $imap->sort($this->folder, $this->sort_field, + rcube_imap::convert_criteria($criteria, $charset), true, 'US-ASCII'); + } + + if (!$messages->is_error()) { + return $messages; + } + } + + $messages = $imap->search($this->folder, + ($charset && $charset != 'US-ASCII' ? "CHARSET $charset " : '') . $criteria, true); + + // Error, try with US-ASCII (some servers may support only US-ASCII) + if ($messages->is_error() && $charset && $charset != 'US-ASCII') { + $messages = $imap->search($this->folder, + rcube_imap::convert_criteria($criteria, $charset), true); + } + + return $messages; + } + + public function get_search_set() + { + return array( + $this->search, + $this->result, + $this->charset, + $this->sort_field, + $this->threading, + ); + } + + public function get_result() + { + return $this->result; + } +} + + +/** + * Wrker thread to run search jobs while maintaining a common context + */ +class rcube_imap_search_worker extends Worker +{ + public $id; + public $options; + + private $conn; + + /** + * Default constructor + */ + public function __construct($id, $options) + { + $this->id = $id; + $this->options = $options; + } + + /** + * Get a dedicated connection to the IMAP server + */ + public function get_imap() + { + // TODO: make this connection persistent for several jobs + #if ($this->conn) + # return $this->conn; + + $conn = new rcube_imap_generic(); + # $conn->setDebug(true, function($conn, $message){ trigger_error($message, E_USER_NOTICE); }); + + if ($this->options['user'] && $this->options['password']) { + $conn->connect($this->options['host'], $this->options['user'], $this->options['password'], $this->options); + } + + if ($conn->error) + trigger_error($this->conn->error, E_USER_WARNING); + + #$this->conn = $conn; + return $conn; + } + + /** + * @override + */ + public function run() + { + + } + + /** + * Close IMAP connection + */ + public function close() + { + if ($this->conn) { + $this->conn->close(); + } + } +} + diff --git a/program/lib/Roundcube/rcube_result_multifolder.php b/program/lib/Roundcube/rcube_result_multifolder.php new file mode 100644 index 000000000..8d7ae5de8 --- /dev/null +++ b/program/lib/Roundcube/rcube_result_multifolder.php @@ -0,0 +1,211 @@ + | + +-----------------------------------------------------------------------+ +*/ + +/** + * Class holding a set of rcube_result_index instances that together form a + * result set of a multi-folder search + * + * @package Framework + * @subpackage Storage + */ +class rcube_result_multifolder +{ + public $multi = true; + public $sets = array(); + + protected $meta = array(); + protected $order = 'ASC'; + + + /** + * Object constructor. + */ + public function __construct() + { + $this->meta = array('count' => 0); + } + + + /** + * Initializes object with SORT command response + * + * @param string $data IMAP response string + */ + public function add($result) + { + $this->sets[] = $result; + $this->meta['count'] += $result->count(); + } + + + /** + * Checks the result from IMAP command + * + * @return bool True if the result is an error, False otherwise + */ + public function is_error() + { + return false; + } + + + /** + * Checks if the result is empty + * + * @return bool True if the result is empty, False otherwise + */ + public function is_empty() + { + return empty($this->sets) || $this->meta['count'] == 0; + } + + + /** + * Returns number of elements in the result + * + * @return int Number of elements + */ + public function count() + { + return $this->meta['count']; + } + + + /** + * Returns number of elements in the result. + * Alias for count() for compatibility with rcube_result_thread + * + * @return int Number of elements + */ + public function count_messages() + { + return $this->count(); + } + + + /** + * Reverts order of elements in the result + */ + public function revert() + { + $this->order = $this->order == 'ASC' ? 'DESC' : 'ASC'; + } + + + /** + * Check if the given message ID exists in the object + * + * @param int $msgid Message ID + * @param bool $get_index When enabled element's index will be returned. + * Elements are indexed starting with 0 + * @return mixed False if message ID doesn't exist, True if exists or + * index of the element if $get_index=true + */ + public function exists($msgid, $get_index = false) + { + return false; + } + + + /** + * Filters data set. Removes elements listed in $ids list. + * + * @param array $ids List of IDs to remove. + * @param string $folder IMAP folder + */ + public function filter($ids = array(), $folder = null) + { + $this->meta['count'] = 0; + foreach ($this->sets as $set) { + if ($set->get_parameters('MAILBOX') == $folder) { + $set->filter($ids); + } + $this->meta['count'] += $set->count(); + } + } + + /** + * Filters data set. Removes elements not listed in $ids list. + * + * @param array $ids List of IDs to keep. + */ + public function intersect($ids = array()) + { + // not implemented + } + + /** + * Return all messages in the result. + * + * @return array List of message IDs + */ + public function get() + { + return array(); + } + + + /** + * Return all messages in the result. + * + * @return array List of message IDs + */ + public function get_compressed() + { + return ''; + } + + + /** + * Return result element at specified index + * + * @param int|string $index Element's index or "FIRST" or "LAST" + * + * @return int Element value + */ + public function get_element($index) + { + return null; + } + + + /** + * Returns response parameters, e.g. ESEARCH's MIN/MAX/COUNT/ALL/MODSEQ + * or internal data e.g. MAILBOX, ORDER + * + * @param string $param Parameter name + * + * @return array|string Response parameters or parameter value + */ + public function get_parameters($param=null) + { + return $params; + } + + + /** + * Returns length of internal data representation + * + * @return int Data length + */ + protected function length() + { + return $this->count(); + } +} diff --git a/program/steps/mail/search.inc b/program/steps/mail/search.inc index 9f4cdc9c9..9b5aa2fc1 100644 --- a/program/steps/mail/search.inc +++ b/program/steps/mail/search.inc @@ -106,6 +106,9 @@ if (!empty($subject)) { $search_str = trim($search_str); $sort_column = rcmail_sort_column(); +// TEMPORARY: search all folders +$mboxes = $RCMAIL->storage->list_folders_subscribed('', '*', 'mail'); + // execute IMAP search if ($search_str) { $RCMAIL->storage->search($mbox, $search_str, $imap_charset, $sort_column); @@ -128,17 +131,20 @@ $result_h = $RCMAIL->storage->list_messages($mbox, 1, $sort_column, rcmail_sort_ $count = $RCMAIL->storage->count($mbox, $RCMAIL->storage->get_threading() ? 'THREADS' : 'ALL'); // Add 'folder' column to list -if ($multi_folder_search) { +if ($_SESSION['search'][1]->multi) { $a_show_cols = $_SESSION['list_attrib']['columns'] ? $_SESSION['list_attrib']['columns'] : (array)$CONFIG['list_cols']; - if (!in_array($a_show_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', ''); } // Make sure we got the headers -- cgit v1.2.3 From b6e24c6946606cd504d522451c36b6dc574fe75d Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Tue, 15 Oct 2013 11:44:34 +0200 Subject: Minor improvements to threaded searching --- program/lib/Roundcube/rcube_imap.php | 8 +++---- program/lib/Roundcube/rcube_imap_search.php | 36 ++++++++++++++++++----------- 2 files changed, 26 insertions(+), 18 deletions(-) (limited to 'program/lib/Roundcube') diff --git a/program/lib/Roundcube/rcube_imap.php b/program/lib/Roundcube/rcube_imap.php index db94e7678..0cf34b2ca 100644 --- a/program/lib/Roundcube/rcube_imap.php +++ b/program/lib/Roundcube/rcube_imap.php @@ -969,7 +969,7 @@ class rcube_imap extends rcube_storage $to = $from + $page_size; // sort headers - if (!$this->threading) { + if (!$this->threading && !empty($a_msg_headers)) { $a_msg_headers = $this->conn->sortHeaders($a_msg_headers, $this->sort_field, $this->sort_order); } @@ -1476,10 +1476,8 @@ class rcube_imap extends rcube_storage new rcube_result_index; // trigger autoloader and make these classes available for threaded context new rcube_result_thread; - // connect IMAP - if (!defined('PTHREADS_INHERIT_ALL')) { - $this->check_connection(); - } + // connect IMAP to have all the required classes and settings loaded + $this->check_connection(); $searcher = new rcube_imap_search($this->options, $this->conn); $results = $searcher->exec( diff --git a/program/lib/Roundcube/rcube_imap_search.php b/program/lib/Roundcube/rcube_imap_search.php index ed4face98..d82ec8a24 100644 --- a/program/lib/Roundcube/rcube_imap_search.php +++ b/program/lib/Roundcube/rcube_imap_search.php @@ -172,9 +172,9 @@ class rcube_imap_search_job extends Stackable public function run() { - #trigger_error("Start search $this->folder", E_USER_NOTICE); + // trigger_error("Start search $this->folder", E_USER_NOTICE); $this->result = $this->search_index(); - #trigger_error("End search $this->folder: " . $this->result->count(), E_USER_NOTICE); + // trigger_error("End search $this->folder: " . $this->result->count(), E_USER_NOTICE); } /** @@ -182,6 +182,7 @@ class rcube_imap_search_job extends Stackable */ protected function search_index() { + $pthreads = defined('PTHREADS_INHERIT_ALL'); $criteria = $this->search; $charset = $this->charset; @@ -216,6 +217,10 @@ class rcube_imap_search_job extends Stackable rcube_imap::convert_criteria($criteria, $charset), true, 'US-ASCII'); } + // close IMAP connection again + if ($pthreads) + $imap->closeConnection(); + return $threads; } @@ -228,21 +233,23 @@ class rcube_imap_search_job extends Stackable $messages = $imap->sort($this->folder, $this->sort_field, rcube_imap::convert_criteria($criteria, $charset), true, 'US-ASCII'); } - - if (!$messages->is_error()) { - return $messages; - } } - $messages = $imap->search($this->folder, - ($charset && $charset != 'US-ASCII' ? "CHARSET $charset " : '') . $criteria, true); - - // Error, try with US-ASCII (some servers may support only US-ASCII) - if ($messages->is_error() && $charset && $charset != 'US-ASCII') { + if (!$messages || !$messages->is_error()) { $messages = $imap->search($this->folder, - rcube_imap::convert_criteria($criteria, $charset), true); + ($charset && $charset != 'US-ASCII' ? "CHARSET $charset " : '') . $criteria, true); + + // Error, try with US-ASCII (some servers may support only US-ASCII) + if ($messages->is_error() && $charset && $charset != 'US-ASCII') { + $messages = $imap->search($this->folder, + rcube_imap::convert_criteria($criteria, $charset), true); + } } + // close IMAP connection again + if ($pthreads) + $imap->closeConnection(); + return $messages; } @@ -279,6 +286,8 @@ class rcube_imap_search_worker extends Worker */ public function __construct($id, $options) { + $options['ident']['command'] = 'search-'.$id; + $this->id = $id; $this->options = $options; } @@ -296,11 +305,12 @@ class rcube_imap_search_worker extends Worker # $conn->setDebug(true, function($conn, $message){ trigger_error($message, E_USER_NOTICE); }); if ($this->options['user'] && $this->options['password']) { + // TODO: do this synchronized to avoid warnings like "Only one Id allowed in non-authenticated state" $conn->connect($this->options['host'], $this->options['user'], $this->options['password'], $this->options); } if ($conn->error) - trigger_error($this->conn->error, E_USER_WARNING); + trigger_error($conn->error, E_USER_WARNING); #$this->conn = $conn; return $conn; -- cgit v1.2.3 From d53b60406c8070f363d42b32a21670ae68f56cc1 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Thu, 16 Jan 2014 11:12:43 +0100 Subject: Fix typos --- program/lib/Roundcube/rcube_imap_search.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'program/lib/Roundcube') diff --git a/program/lib/Roundcube/rcube_imap_search.php b/program/lib/Roundcube/rcube_imap_search.php index d82ec8a24..70a11bc1c 100644 --- a/program/lib/Roundcube/rcube_imap_search.php +++ b/program/lib/Roundcube/rcube_imap_search.php @@ -235,7 +235,7 @@ class rcube_imap_search_job extends Stackable } } - if (!$messages || !$messages->is_error()) { + if (!$messages || $messages->is_error()) { $messages = $imap->search($this->folder, ($charset && $charset != 'US-ASCII' ? "CHARSET $charset " : '') . $criteria, true); @@ -272,7 +272,7 @@ class rcube_imap_search_job extends Stackable /** - * Wrker thread to run search jobs while maintaining a common context + * Worker thread to run search jobs while maintaining a common context */ class rcube_imap_search_worker extends Worker { -- cgit v1.2.3 From 2baeac116abef9d5bcb748c687577d16dce868a0 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Thu, 16 Jan 2014 14:17:08 +0100 Subject: Fix sorting and paging in cross-folder searches --- program/lib/Roundcube/rcube_imap.php | 4 ++-- program/steps/mail/list.inc | 16 +++++++++++++ program/steps/mail/search.inc | 44 +++++++++++------------------------- 3 files changed, 31 insertions(+), 33 deletions(-) (limited to 'program/lib/Roundcube') diff --git a/program/lib/Roundcube/rcube_imap.php b/program/lib/Roundcube/rcube_imap.php index 0cf34b2ca..e265946f2 100644 --- a/program/lib/Roundcube/rcube_imap.php +++ b/program/lib/Roundcube/rcube_imap.php @@ -952,7 +952,7 @@ class rcube_imap extends rcube_storage $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 @@ class rcube_imap extends rcube_storage // 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 277564c38..4b2a955b7 100644 --- a/program/steps/mail/list.inc +++ b/program/steps/mail/list.inc @@ -75,6 +75,22 @@ if (!empty($_REQUEST['_search']) && isset($_SESSION['search']) && $_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 67fee755d..5ce9fe6e2 100644 --- a/program/steps/mail/search.inc +++ b/program/steps/mail/search.inc @@ -111,7 +111,7 @@ $mboxes = $RCMAIL->storage->list_folders_subscribed('', '*', 'mail'); // 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 @@ 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']; - 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', ''); -} + $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; + } -// 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 -- cgit v1.2.3 From 2c33c7e38bc767330b4eebdc9e4d234caca72966 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Thu, 16 Jan 2014 15:41:19 +0100 Subject: Make message pagenav (prev/next) work with sorted multi-folder search results --- program/js/app.js | 3 +- program/lib/Roundcube/rcube_imap.php | 10 +++++- program/lib/Roundcube/rcube_result_multifolder.php | 40 +++++++++++++++++++--- program/steps/mail/func.inc | 4 ++- program/steps/mail/list.inc | 2 ++ program/steps/mail/search.inc | 8 ++--- 6 files changed, 56 insertions(+), 11 deletions(-) (limited to 'program/lib/Roundcube') 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']; -- cgit v1.2.3 From ff3eb834920e2ec04e24423b5f87bdf4d3064eeb Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Thu, 16 Jan 2014 15:50:48 +0100 Subject: Handle combined UID-folder identifiers in rcube_imap class --- program/lib/Roundcube/rcube_imap.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'program/lib/Roundcube') diff --git a/program/lib/Roundcube/rcube_imap.php b/program/lib/Roundcube/rcube_imap.php index 847bcfa70..698d0daf3 100644 --- a/program/lib/Roundcube/rcube_imap.php +++ b/program/lib/Roundcube/rcube_imap.php @@ -1656,6 +1656,7 @@ class rcube_imap extends rcube_storage public function refresh_search() { if (!empty($this->search_string)) { + // FIXME: make this work with saved multi-folder searches $this->search('', $this->search_string, $this->search_charset, $this->search_sort_field); } @@ -1678,6 +1679,11 @@ class rcube_imap extends rcube_storage $folder = $this->folder; } + // decode combined UID-folder identifier + if (preg_match('/^\d+-[^,]+$/', $uid)) { + list($uid, $folder) = explode('-', $uid); + } + // get cached headers if (!$force && $uid && ($mcache = $this->get_mcache_engine())) { $headers = $mcache->get_message($folder, $uid); @@ -1709,6 +1715,11 @@ class rcube_imap extends rcube_storage $folder = $this->folder; } + // decode combined UID-folder identifier + if (preg_match('/^\d+-[^,]+$/', $uid)) { + list($uid, $folder) = explode('-', $uid); + } + // Check internal cache if (!empty($this->icache['message'])) { if (($headers = $this->icache['message']) && $headers->uid == $uid) { -- cgit v1.2.3 From 689a222170aed32165cbe8bc8fc89fd428b29186 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Mon, 20 Jan 2014 09:33:58 +0100 Subject: Append per-folder search results to global index but only if it has matches --- program/lib/Roundcube/rcube_result_multifolder.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'program/lib/Roundcube') diff --git a/program/lib/Roundcube/rcube_result_multifolder.php b/program/lib/Roundcube/rcube_result_multifolder.php index 277a6d1ea..188fb26f2 100644 --- a/program/lib/Roundcube/rcube_result_multifolder.php +++ b/program/lib/Roundcube/rcube_result_multifolder.php @@ -52,8 +52,15 @@ class rcube_result_multifolder */ public function add($result) { - $this->sets[] = $result; - $this->meta['count'] += $result->count(); + if ($count = $result->count()) { + $this->sets[] = $result; + $this->meta['count'] += $count; + + // append UIDs to global index + $folder = $result->get_parameters('MAILBOX'); + $index = array_map(function($uid) use ($folder) { return $uid . '-' . $folder; }, $result->get()); + $this->index = array_merge($this->index, $index); + } } /** -- cgit v1.2.3 From 1bbf8c48868efb87baab7ae71721f2c9ad408e65 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Mon, 20 Jan 2014 10:05:36 +0100 Subject: - Make search scope selectable in UI - Disable thread mode when searching over multiple folders - Encode UID values for HTML message row identifiers --- program/js/app.js | 45 ++++++++++++++++++++++------------- program/js/list.js | 29 ++++++++++++---------- program/lib/Roundcube/rcube_imap.php | 4 ++++ program/localization/en_US/labels.inc | 4 ++++ program/steps/mail/func.inc | 3 +++ program/steps/mail/search.inc | 13 ++++++++-- skins/larry/templates/mail.html | 13 +++++----- skins/larry/ui.js | 27 +++++++++++++++------ 8 files changed, 93 insertions(+), 45 deletions(-) (limited to 'program/lib/Roundcube') diff --git a/program/js/app.js b/program/js/app.js index 5eae82351..2401e1e0c 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -217,6 +217,7 @@ function rcube_webmail() this.gui_objects.messagelist.parentNode.onmousedown = function(e){ return p.click_on_list(e); }; this.enable_command('toggle_status', 'toggle_flag', 'sort', true); + this.enable_command('set-listmode', this.env.threads && !this.env.search_request); // load messages this.command('list'); @@ -709,6 +710,10 @@ function rcube_webmail() this.list_contacts(props); break; + case 'set-listmode': + this.set_list_options(null, undefined, undefined, props == 'threads' ? 1 : 0); + break; + case 'sort': var sort_order = this.env.sort_order, sort_col = !this.env.disabled_sort_col ? props : this.env.sort_col; @@ -1753,7 +1758,7 @@ function rcube_webmail() this.init_message_row = function(row) { var i, fn = {}, self = this, uid = row.uid, - status_icon = (this.env.status_col != null ? 'status' : 'msg') + 'icn' + row.uid; + status_icon = (this.env.status_col != null ? 'status' : 'msg') + 'icn' + row.id; if (uid && this.env.messages[uid]) $.extend(row, this.env.messages[uid]); @@ -1765,17 +1770,17 @@ function rcube_webmail() // save message icon position too if (this.env.status_col != null) - row.msgicon = document.getElementById('msgicn'+row.uid); + row.msgicon = document.getElementById('msgicn'+row.id); else row.msgicon = row.icon; // set eventhandler to flag icon - if (this.env.flagged_col != null && (row.flagicon = document.getElementById('flagicn'+row.uid))) { + if (this.env.flagged_col != null && (row.flagicon = document.getElementById('flagicn'+row.id))) { fn.flagicon = function(e) { self.command('toggle_flag', uid); }; } // set event handler to thread expand/collapse icon - if (!row.depth && row.has_children && (row.expando = document.getElementById('rcmexpando'+row.uid))) { + if (!row.depth && row.has_children && (row.expando = document.getElementById('rcmexpando'+row.id))) { fn.expando = function(e) { self.expand_message_row(e, uid); }; } @@ -1837,7 +1842,7 @@ function rcube_webmail() + (flags.deleted ? ' deleted' : '') + (flags.flagged ? ' flagged' : '') + (message.selected ? ' selected' : ''), - row = { cols:[], style:{}, id:'rcmrow'+uid }; + row = { cols:[], style:{}, id:'rcmrow'+this.html_identifier(uid,true), uid:uid }; // message status icons css_class = 'msgicon'; @@ -1863,7 +1868,7 @@ function rcube_webmail() if (this.env.threading) { if (message.depth) { // This assumes that div width is hardcoded to 15px, - tree += '  '; + tree += '  '; if ((rows[message.parent_uid] && rows[message.parent_uid].expanded === false) || ((this.env.autoexpand_threads == 0 || this.env.autoexpand_threads == 2) && @@ -1882,7 +1887,7 @@ function rcube_webmail() message.expanded = true; } - expando = '
  
'; + expando = '
  
'; row_class += ' thread' + (message.expanded? ' expanded' : ''); } @@ -1890,14 +1895,14 @@ function rcube_webmail() row_class += ' unroot'; } - tree += ' '; + tree += ' '; row.className = row_class; // build subject link if (!bw.ie && cols.subject) { var action = flags.mbox == this.env.drafts_mailbox ? 'compose' : 'show'; var uid_param = flags.mbox == this.env.drafts_mailbox ? '_draft_uid' : '_uid'; - cols.subject = ''+cols.subject+''; } @@ -1908,7 +1913,7 @@ function rcube_webmail() if (c == 'flag') { css_class = (flags.flagged ? 'flagged' : 'unflagged'); - html = ' '; + html = ' '; } else if (c == 'attachment') { if (/application\/|multipart\/(m|signed)/.test(flags.ctype)) @@ -1927,7 +1932,7 @@ function rcube_webmail() css_class = 'unreadchildren'; else css_class = 'msgicon'; - html = ' '; + html = ' '; } else if (c == 'threads') html = expando; @@ -2390,7 +2395,7 @@ function rcube_webmail() } if (html) - $('#rcmtab'+uid).html(html); + $('#rcmtab'+this.html_identifier(uid, true)).html(html); }; // update parent in a thread @@ -2454,14 +2459,14 @@ function rcube_webmail() r.depth--; // move left // reset width and clear the content of a tab, icons will be added later - $('#rcmtab'+r.uid).width(r.depth * 15).html(''); + $('#rcmtab'+r.id).width(r.depth * 15).html(''); if (!r.depth) { // a new root count++; // increase roots count r.parent_uid = 0; if (r.has_children) { // replace 'leaf' with 'collapsed' - $('#rcmrow'+r.uid+' '+'.leaf:first') - .attr('id', 'rcmexpando' + r.uid) + $('#'+r.id+' .leaf:first') + .attr('id', 'rcmexpando' + r.id) .attr('class', (r.obj.style.display != 'none' ? 'expanded' : 'collapsed')) .bind('mousedown', {uid:r.uid, p:this}, function(e) { return e.data.p.expand_message_row(e, e.data.uid); }); @@ -4118,6 +4123,7 @@ function rcube_webmail() r = this.http_request(action, url, lock); this.env.qsearch = {lock: lock, request: r}; + this.enable_command('set-listmode', this.env.threads && (this.env.search_scope || 'base') == 'base'); } }; @@ -4126,7 +4132,8 @@ function rcube_webmail() { var n, url = {}, mods_arr = [], mods = this.env.search_mods, - mbox = this.env.mailbox; + mbox = this.env.mailbox, + scope = this.env.search_scope || 'base'; if (!filter && this.gui_objects.search_filter) filter = this.gui_objects.search_filter.value; @@ -4150,7 +4157,9 @@ function rcube_webmail() } } - if (mbox) + if (scope) + url._scope = scope; + if (mbox && scope != 'all') url._mbox = mbox; return url; @@ -4168,6 +4177,8 @@ function rcube_webmail() this.env.qsearch = null; this.env.search_request = null; this.env.search_id = null; + + this.enable_command('set-listmode', this.env.threads); }; this.sent_successfully = function(type, msg, folders) diff --git a/program/js/list.js b/program/js/list.js index 319807eae..c026ccb4a 100644 --- a/program/js/list.js +++ b/program/js/list.js @@ -107,11 +107,15 @@ init: function() */ init_row: function(row) { - // make references in internal array and set event handlers - if (row && String(row.id).match(this.id_regexp)) { - var self = this, - uid = RegExp.$1; + var uid; + if (row && (uid = $(row).data('uid'))) row.uid = uid; + else if (row && String(row.id).match(this.id_regexp)) + row.uid = RegExp.$1; + + // make references in internal array and set event handlers + if (row && row.uid) { + var self = this, uid = row.uid; this.rows[uid] = {uid:uid, id:row.id, obj:row}; // set eventhandlers to table row @@ -291,6 +295,7 @@ insert_row: function(row, before) if (row.id) domrow.id = row.id; if (row.className) domrow.className = row.className; if (row.style) $.extend(domrow.style, row.style); + if (row.uid) $(domrow).data('uid', row.uid); for (var domcell, col, i=0; row.cols && i < row.cols.length; i++) { col = row.cols[i]; @@ -589,7 +594,7 @@ expand: function(row) row.expanded = true; depth = row.depth; new_row = row.obj.nextSibling; - this.update_expando(row.uid, true); + this.update_expando(row.id, true); this.triggerEvent('expandcollapse', { uid:row.uid, expanded:row.expanded, obj:row.obj }); } else { @@ -639,7 +644,7 @@ collapse_all: function(row) row.expanded = false; depth = row.depth; new_row = row.obj.nextSibling; - this.update_expando(row.uid); + this.update_expando(row.id); this.triggerEvent('expandcollapse', { uid:row.uid, expanded:row.expanded, obj:row.obj }); // don't collapse sub-root tree in multiexpand mode @@ -661,7 +666,7 @@ collapse_all: function(row) $(new_row).css('display', 'none'); if (r.has_children && r.expanded) { r.expanded = false; - this.update_expando(r.uid, false); + this.update_expando(r.id, false); this.triggerEvent('expandcollapse', { uid:r.uid, expanded:r.expanded, obj:new_row }); } } @@ -683,7 +688,7 @@ expand_all: function(row) row.expanded = true; depth = row.depth; new_row = row.obj.nextSibling; - this.update_expando(row.uid, true); + this.update_expando(row.id, true); this.triggerEvent('expandcollapse', { uid:row.uid, expanded:row.expanded, obj:row.obj }); } else { @@ -700,7 +705,7 @@ expand_all: function(row) $(new_row).css('display', ''); if (r.has_children && !r.expanded) { r.expanded = true; - this.update_expando(r.uid, true); + this.update_expando(r.id, true); this.triggerEvent('expandcollapse', { uid:r.uid, expanded:r.expanded, obj:new_row }); } } @@ -714,9 +719,9 @@ expand_all: function(row) }, -update_expando: function(uid, expanded) +update_expando: function(id, expanded) { - var expando = document.getElementById('rcmexpando' + uid); + var expando = document.getElementById('rcmexpando' + id); if (expando) expando.className = expanded ? 'expanded' : 'collapsed'; }, @@ -1267,7 +1272,7 @@ use_arrow_key: function(keyCode, mod_key) this.collapse(selected_row); } - this.update_expando(selected_row.uid, selected_row.expanded); + this.update_expando(selected_row.id, selected_row.expanded); return false; } diff --git a/program/lib/Roundcube/rcube_imap.php b/program/lib/Roundcube/rcube_imap.php index 698d0daf3..dd0501c2d 100644 --- a/program/lib/Roundcube/rcube_imap.php +++ b/program/lib/Roundcube/rcube_imap.php @@ -953,6 +953,7 @@ class rcube_imap extends rcube_storage $this->sort_field = null; $this->page_size = 1000; // fetch up to 1000 matching messages per folder + $this->threading = false; $a_msg_headers = array(); foreach ($search_set->sets as $resultset) { @@ -1487,6 +1488,9 @@ class rcube_imap extends rcube_storage // connect IMAP to have all the required classes and settings loaded $this->check_connection(); + // disable threading + $this->threading = false; + $searcher = new rcube_imap_search($this->options, $this->conn); $results = $searcher->exec( $folder, diff --git a/program/localization/en_US/labels.inc b/program/localization/en_US/labels.inc index 61890a642..05eab6713 100644 --- a/program/localization/en_US/labels.inc +++ b/program/localization/en_US/labels.inc @@ -208,6 +208,10 @@ $labels['msgtext'] = 'Entire message'; $labels['body'] = 'Body'; $labels['type'] = 'Type'; $labels['namex'] = 'Name'; +$labels['searchscope'] = 'Scope'; +$labels['currentfolder'] = 'Current folder'; +$labels['subfolders'] = 'This and subfolders'; +$labels['allfolders'] = 'All folders'; $labels['openinextwin'] = 'Open in new window'; $labels['emlsave'] = 'Download (.eml)'; diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc index 45d4242f9..fd321e294 100644 --- a/program/steps/mail/func.inc +++ b/program/steps/mail/func.inc @@ -105,6 +105,9 @@ if (empty($RCMAIL->action) || $RCMAIL->action == 'list') { } $OUTPUT->set_env('search_mods', rcmail_search_mods()); + + if (!empty($_SESSION['search_scope'])) + $OUTPUT->set_env('search_scope', $_SESSION['search_scope']); } $threading = (bool) $RCMAIL->storage->get_threading(); diff --git a/program/steps/mail/search.inc b/program/steps/mail/search.inc index b45cdc0de..88bbe6eda 100644 --- a/program/steps/mail/search.inc +++ b/program/steps/mail/search.inc @@ -35,6 +35,7 @@ $str = rcube_utils::get_input_value('_q', rcube_utils::INPUT_GET, true); $mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_GET, true); $filter = rcube_utils::get_input_value('_filter', rcube_utils::INPUT_GET); $headers = rcube_utils::get_input_value('_headers', rcube_utils::INPUT_GET); +$scope = rcube_utils::get_input_value('_scope', rcube_utils::INPUT_GET); $subject = array(); $search_request = md5($mbox.$filter.$str); @@ -106,8 +107,15 @@ if (!empty($subject)) { $search_str = trim($search_str); $sort_column = rcmail_sort_column(); -// TEMPORARY: search all folders -$mboxes = $RCMAIL->storage->list_folders_subscribed('', '*', 'mail'); +// search all, current or subfolders folders +if ($scope == 'all') { + $mboxes = $RCMAIL->storage->list_folders_subscribed('', '*', 'mail'); +} +else if ($scope == 'sub') { + $mboxes = $RCMAIL->storage->list_folders_subscribed($mbox, '*', 'mail'); + if ($mbox != 'INBOX' && $mboxes[0] == 'INBOX') + array_shift($mboxes); +} // execute IMAP search if ($search_str) { @@ -128,6 +136,7 @@ if ($search_str) { $_SESSION['last_text_search'] = $str; } $_SESSION['search_request'] = $search_request; +$_SESSION['search_scope'] = $scope; // Add 'folder' column to list if ($_SESSION['search'][1]->multi) { diff --git a/skins/larry/templates/mail.html b/skins/larry/templates/mail.html index ff5f7549c..e2bf8901c 100644 --- a/skins/larry/templates/mail.html +++ b/skins/larry/templates/mail.html @@ -76,13 +76,8 @@
- - List - Threads - - List - Threads - + +
@@ -132,6 +127,10 @@
  • +
  • +
  • +
  • +
  • diff --git a/skins/larry/ui.js b/skins/larry/ui.js index 44fc727f6..2030b05cd 100644 --- a/skins/larry/ui.js +++ b/skins/larry/ui.js @@ -41,6 +41,7 @@ function rcube_mail_ui() this.show_popup = show_popup; this.add_popup = add_popup; this.set_searchmod = set_searchmod; + this.set_searchscope = set_searchscope; this.show_uploadform = show_uploadform; this.show_header_row = show_header_row; this.hide_header_row = hide_header_row; @@ -731,11 +732,10 @@ function rcube_mail_ui() */ function switch_view_mode(mode) { - if (rcmail.env.threading != (mode == 'thread')) - rcmail.set_list_options(null, undefined, undefined, mode == 'thread' ? 1 : 0); - - $('#maillistmode, #mailthreadmode').removeClass('selected'); - $('#mail'+mode+'mode').addClass('selected'); + if (!$('#mail'+mode+'mode').hasClass('disabled')) { + $('#maillistmode, #mailthreadmode').removeClass('selected'); + $('#mail'+mode+'mode').addClass('selected'); + } } @@ -761,11 +761,15 @@ function rcube_mail_ui() obj = popups['searchmenu'], list = $('input:checkbox[name="s_mods[]"]', obj), mbox = rcmail.env.mailbox, - mods = rcmail.env.search_mods; + mods = rcmail.env.search_mods, + scope = rcmail.env.search_scope || 'base'; if (rcmail.env.task == 'mail') { + if (scope == 'all') + mbox = '*'; mods = mods[mbox] ? mods[mbox] : mods['*']; all = 'text'; + $('#s_scope_'+scope).prop('checked', true); } else { all = '*'; @@ -896,7 +900,11 @@ function rcube_mail_ui() { var all, m, task = rcmail.env.task, mods = rcmail.env.search_mods, - mbox = rcmail.env.mailbox; + mbox = rcmail.env.mailbox, + scope = $('input[name="s_scope"]:checked').val(); + + if (scope == 'all') + mbox = '*'; if (!mods) mods = {}; @@ -937,6 +945,11 @@ function rcube_mail_ui() }); } + function set_searchscope(elem) + { + rcmail.env.search_scope = elem.value; + } + function push_contactgroup(p) { // lets the contacts list swipe to the left, nice! -- cgit v1.2.3 From 9202e93b754d07c0e6312f8b51bd4092ea14961d Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Mon, 20 Jan 2014 11:59:57 +0100 Subject: Fix slicing of returned search result headers --- program/lib/Roundcube/rcube_imap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'program/lib/Roundcube') diff --git a/program/lib/Roundcube/rcube_imap.php b/program/lib/Roundcube/rcube_imap.php index dd0501c2d..794f25a37 100644 --- a/program/lib/Roundcube/rcube_imap.php +++ b/program/lib/Roundcube/rcube_imap.php @@ -978,7 +978,7 @@ class rcube_imap extends rcube_storage $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)); + $slice_length = min($page_size, $cnt - $from); $a_msg_headers = array_slice(array_values($a_msg_headers), $from, $slice_length); if ($slice) { -- cgit v1.2.3 From 1d6082c5e2ad4f12986c59fee49bec5bc68bd829 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Mon, 20 Jan 2014 12:12:21 +0100 Subject: Fix thread/list mode update and display --- program/lib/Roundcube/rcube_imap.php | 4 ++++ program/steps/mail/search.inc | 1 + skins/larry/ui.js | 7 ++++--- 3 files changed, 9 insertions(+), 3 deletions(-) (limited to 'program/lib/Roundcube') diff --git a/program/lib/Roundcube/rcube_imap.php b/program/lib/Roundcube/rcube_imap.php index 794f25a37..6bb922d90 100644 --- a/program/lib/Roundcube/rcube_imap.php +++ b/program/lib/Roundcube/rcube_imap.php @@ -332,6 +332,10 @@ class rcube_imap extends rcube_storage $this->search_sort_field = $set[3]; $this->search_sorted = $set[4]; $this->search_threads = is_a($this->search_set, 'rcube_result_thread'); + + if (is_a($this->search_set, 'rcube_result_multifolder')) { + $this->set_threading(false); + } } diff --git a/program/steps/mail/search.inc b/program/steps/mail/search.inc index 51dab7dc4..e13bc2ce5 100644 --- a/program/steps/mail/search.inc +++ b/program/steps/mail/search.inc @@ -181,6 +181,7 @@ else { // update message count display $OUTPUT->set_env('search_request', $search_str ? $search_request : ''); +$OUTPUT->set_env('threading', $RCMAIL->storage->get_threading()); $OUTPUT->set_env('messagecount', $count); $OUTPUT->set_env('pagecount', ceil($count/$RCMAIL->storage->get_pagesize())); $OUTPUT->set_env('exists', $RCMAIL->storage->count($mbox_name, 'EXISTS')); diff --git a/skins/larry/ui.js b/skins/larry/ui.js index e5fce9197..b95e1f1c6 100644 --- a/skins/larry/ui.js +++ b/skins/larry/ui.js @@ -139,7 +139,8 @@ function rcube_mail_ui() if (rcmail.env.task == 'mail') { rcmail.addEventListener('menu-open', menu_open) .addEventListener('menu-save', menu_save) - .addEventListener('responseafterlist', function(e){ switch_view_mode(rcmail.env.threading ? 'thread' : 'list') }); + .addEventListener('responseafterlist', function(e){ switch_view_mode(rcmail.env.threading ? 'thread' : 'list', true) }) + .addEventListener('responseaftersearch', function(e){ switch_view_mode(rcmail.env.threading ? 'thread' : 'list', true) }); var dragmenu = $('#dragmessagemenu'); if (dragmenu.length) { @@ -730,9 +731,9 @@ function rcube_mail_ui() /** * */ - function switch_view_mode(mode) + function switch_view_mode(mode, force) { - if (!$('#mail'+mode+'mode').hasClass('disabled')) { + if (force || !$('#mail'+mode+'mode').hasClass('disabled')) { $('#maillistmode, #mailthreadmode').removeClass('selected'); $('#mail'+mode+'mode').addClass('selected'); } -- cgit v1.2.3 From d93ce5cde23b7170b96fd9816e8d5e8cfdf6e0f6 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Tue, 21 Jan 2014 17:18:28 +0100 Subject: Fix concurrent connections to IMAP while searching --- program/lib/Roundcube/rcube_imap_search.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'program/lib/Roundcube') diff --git a/program/lib/Roundcube/rcube_imap_search.php b/program/lib/Roundcube/rcube_imap_search.php index 70a11bc1c..c88198140 100644 --- a/program/lib/Roundcube/rcube_imap_search.php +++ b/program/lib/Roundcube/rcube_imap_search.php @@ -189,6 +189,8 @@ class rcube_imap_search_job extends Stackable $imap = $this->worker->get_imap(); if (!$imap->connected()) { + trigger_error("No IMAP connection for $this->folder", E_USER_WARNING); + if ($this->threading) { return new rcube_result_thread(); } @@ -280,14 +282,13 @@ class rcube_imap_search_worker extends Worker public $options; private $conn; + private $counts = 0; /** * Default constructor */ public function __construct($id, $options) { - $options['ident']['command'] = 'search-'.$id; - $this->id = $id; $this->options = $options; } @@ -298,21 +299,19 @@ class rcube_imap_search_worker extends Worker public function get_imap() { // TODO: make this connection persistent for several jobs - #if ($this->conn) - # return $this->conn; + // This doesn't seem to work. Socket connections don't survive serialization which is used in pthreads $conn = new rcube_imap_generic(); # $conn->setDebug(true, function($conn, $message){ trigger_error($message, E_USER_NOTICE); }); if ($this->options['user'] && $this->options['password']) { - // TODO: do this synchronized to avoid warnings like "Only one Id allowed in non-authenticated state" + $this->options['ident']['command'] = 'search-' . $this->id . 't' . ++$this->counts; $conn->connect($this->options['host'], $this->options['user'], $this->options['password'], $this->options); } if ($conn->error) trigger_error($conn->error, E_USER_WARNING); - #$this->conn = $conn; return $conn; } -- cgit v1.2.3 From e3857bb6c2a2f9a4331a72b0bd74e0d70ee8a8a1 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Tue, 4 Feb 2014 10:22:29 +0100 Subject: Fix infinite loop when converting invalid html to plaintext (#1489566) --- program/lib/Roundcube/rcube_html2text.php | 4 ++++ tests/Framework/Html2text.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) (limited to 'program/lib/Roundcube') diff --git a/program/lib/Roundcube/rcube_html2text.php b/program/lib/Roundcube/rcube_html2text.php index 01362e6fb..3b4508da9 100644 --- a/program/lib/Roundcube/rcube_html2text.php +++ b/program/lib/Roundcube/rcube_html2text.php @@ -616,6 +616,10 @@ class rcube_html2text break; } + // abort on invalid tag structure (e.g. no closing tag found) + else { + break; + } } while ($end || $next); } diff --git a/tests/Framework/Html2text.php b/tests/Framework/Html2text.php index 3e0df48d9..2c7759f7d 100644 --- a/tests/Framework/Html2text.php +++ b/tests/Framework/Html2text.php @@ -75,4 +75,32 @@ EOF; $this->assertContains('>> INNER 3', $res, 'Quote inner'); $this->assertContains('> OUTER END', $res, 'Quote outer'); } + + function test_broken_blockquotes() + { + // no end tag + $html = << +
    QUOTED TEXT +
    +NO END TAG FOUND +EOF; + $ht = new rcube_html2text($html, false, false); + $res = $ht->get_text(); + + $this->assertContains('QUOTED TEXT NO END TAG FOUND', $res, 'No quoating on invalid html'); + + // with some (nested) end tags + $html = << +
    QUOTED TEXT +
    INNER 1
    +
    INNER 2
    +NO END TAG FOUND +EOF; + $ht = new rcube_html2text($html, false, false); + $res = $ht->get_text(); + + $this->assertContains('QUOTED TEXT INNER 1 INNER 2 NO END', $res, 'No quoating on invalid html'); + } } -- cgit v1.2.3