summaryrefslogtreecommitdiff
path: root/program/steps
diff options
context:
space:
mode:
authorThomas Bruederli <thomas@roundcube.net>2014-04-07 09:53:46 +0200
committerThomas Bruederli <thomas@roundcube.net>2014-04-07 09:53:46 +0200
commit66536974fe12a02ca5ffcec4354bf5113282a0cc (patch)
tree034b848ec971008eab1003a2a9a401fb7020a517 /program/steps
parentc77a8497e7c4b04dd881e55341c779f6fe5ffa34 (diff)
parente3857bb6c2a2f9a4331a72b0bd74e0d70ee8a8a1 (diff)
Merge branch 'dev-multi-folder-search'
Diffstat (limited to 'program/steps')
-rw-r--r--program/steps/mail/autocomplete.inc4
-rw-r--r--program/steps/mail/copy.inc6
-rw-r--r--program/steps/mail/func.inc76
-rw-r--r--program/steps/mail/list.inc4
-rw-r--r--program/steps/mail/mark.inc10
-rw-r--r--program/steps/mail/move_del.inc22
-rw-r--r--program/steps/mail/search.inc28
7 files changed, 119 insertions, 31 deletions
diff --git a/program/steps/mail/autocomplete.inc b/program/steps/mail/autocomplete.inc
index 20cf94084..71b337a53 100644
--- a/program/steps/mail/autocomplete.inc
+++ b/program/steps/mail/autocomplete.inc
@@ -49,7 +49,7 @@ $mode = (int) $RCMAIL->config->get('addressbook_search_mode');
$single = (bool) $RCMAIL->config->get('autocomplete_single');
$search = rcube_utils::get_input_value('_search', rcube_utils::INPUT_GPC, true);
$source = rcube_utils::get_input_value('_source', rcube_utils::INPUT_GPC);
-$sid = rcube_utils::get_input_value('_id', rcube_utils::INPUT_GPC);
+$reqid = rcube_utils::get_input_value('_reqid', rcube_utils::INPUT_GPC);
if (strlen($source)) {
$book_types = array($source);
@@ -155,5 +155,5 @@ if (!empty($book_types) && strlen($search)) {
}
}
-$OUTPUT->command('ksearch_query_results', $contacts, $search, $sid);
+$OUTPUT->command('ksearch_query_results', $contacts, $search, $reqid);
$OUTPUT->send();
diff --git a/program/steps/mail/copy.inc b/program/steps/mail/copy.inc
index a392f309f..0f7b1a03a 100644
--- a/program/steps/mail/copy.inc
+++ b/program/steps/mail/copy.inc
@@ -26,11 +26,11 @@ if (!$OUTPUT->ajax_call) {
// move messages
if (!empty($_POST['_uid']) && strlen($_POST['_target_mbox'])) {
- $uids = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_POST);
$target = rcube_utils::get_input_value('_target_mbox', rcube_utils::INPUT_POST, true);
- $mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_POST, true);
- $copied = $RCMAIL->storage->copy_message($uids, $target, $mbox);
+ foreach (rcmail_get_uids() as $mbox => $uids) {
+ $copied += (int)$RCMAIL->storage->copy_message($uids, $target, $mbox);
+ }
if (!$copied) {
// send error message
diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc
index 072ee716c..066d38151 100644
--- a/program/steps/mail/func.inc
+++ b/program/steps/mail/func.inc
@@ -68,6 +68,23 @@ if (!empty($_REQUEST['_search']) && isset($_SESSION['search'])
$OUTPUT->set_env('search_text', $_SESSION['last_text_search']);
}
+// remove mbox part from _uid
+if (($_uid = get_input_value('_uid', RCUBE_INPUT_GPC)) && preg_match('/^\d+-[^,]+$/', $_uid)) {
+ list($_uid, $mbox) = explode('-', $_uid);
+ if (isset($_GET['_uid'])) $_GET['_uid'] = $_uid;
+ if (isset($_POST['_uid'])) $_POST['_uid'] = $_uid;
+ $_REQUEST['_uid'] = $_uid;
+ unset($_uid);
+
+ // override mbox
+ if (!empty($mbox)) {
+ $_GET['_mbox'] = $mbox;
+ $_POST['_mbox'] = $mbox;
+ $RCMAIL->storage->set_folder(($_SESSION['mbox'] = $mbox));
+ }
+}
+
+
// set main env variables, labels and page title
if (empty($RCMAIL->action) || $RCMAIL->action == 'list') {
// connect to storage server and trigger error on failure
@@ -88,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();
@@ -166,6 +186,34 @@ $RCMAIL->register_action_map(array(
));
+/**
+ * Returns message UID(s) and IMAP folder(s) from GET/POST data
+ *
+ * @return array List of message UIDs per folder
+ */
+function rcmail_get_uids()
+{
+ // message UID (or comma-separated list of IDs) is provided in
+ // the form of <ID>-<MBOX>[,<ID>-<MBOX>]*
+
+ $_uid = get_input_value('_uid', RCUBE_INPUT_GPC);
+ $_mbox = (string)get_input_value('_mbox', RCUBE_INPUT_GPC);
+
+ if (is_array($uid)) {
+ return $uid;
+ }
+
+ // create a per-folder UIDs array
+ $result = array();
+ foreach (explode(',', $_uid) as $uid) {
+ list($uid, $mbox) = explode('-', $uid, 2);
+ if (empty($mbox))
+ $mbox = $_mbox;
+ $result[$mbox][] = $uid;
+ }
+
+ return $result;
+}
/**
* Returns default search mods
@@ -315,7 +363,7 @@ function rcmail_message_list($attrib)
/**
* return javascript commands to add rows to the message list
*/
-function rcmail_js_message_list($a_headers, $insert_top=FALSE, $a_show_cols=null)
+function rcmail_js_message_list($a_headers, $insert_top=false, $a_show_cols=null)
{
global $RCMAIL, $OUTPUT;
@@ -334,6 +382,14 @@ function rcmail_js_message_list($a_headers, $insert_top=FALSE, $a_show_cols=null
$head_replace = true;
}
+ // add 'folder' column to list on multi-folder searches
+ $search_set = $RCMAIL->storage->get_search_set();
+ $multifolder = $search_set && $search_set[1]->multi;
+ if ($multifolder && !in_array('folder', $a_show_cols)) {
+ $a_show_cols[] = 'folder';
+ $head_replace = true;
+ }
+
$mbox = $RCMAIL->storage->get_folder();
// make sure 'threads' and 'subject' columns are present
@@ -342,8 +398,6 @@ function rcmail_js_message_list($a_headers, $insert_top=FALSE, $a_show_cols=null
if (!in_array('threads', $a_show_cols))
array_unshift($a_show_cols, 'threads');
- $_SESSION['list_attrib']['columns'] = $a_show_cols;
-
// Make sure there are no duplicated columns (#1486999)
$a_show_cols = array_unique($a_show_cols);
@@ -364,6 +418,10 @@ function rcmail_js_message_list($a_headers, $insert_top=FALSE, $a_show_cols=null
$OUTPUT->command('set_message_coltypes', $a_show_cols, $thead, $smart_col);
+ if ($multifolder) {
+ $OUTPUT->command('select_folder', '');
+ }
+
if (empty($a_headers)) {
return;
}
@@ -380,6 +438,14 @@ function rcmail_js_message_list($a_headers, $insert_top=FALSE, $a_show_cols=null
if (empty($header))
continue;
+ // make message UIDs unique by appending the folder name
+ if ($multifolder) {
+ $header->uid .= '-'.$header->folder;
+ $header->flags['skip_mbox_check'] = true;
+ if ($header->parent_uid)
+ $header->parent_uid .= '-'.$header->folder;
+ }
+
$a_msg_cols = array();
$a_msg_flags = array();
@@ -398,6 +464,8 @@ function rcmail_js_message_list($a_headers, $insert_top=FALSE, $a_show_cols=null
$cont = show_bytes($header->$col);
else if ($col == 'date')
$cont = $RCMAIL->format_date($header->date);
+ else if ($col == 'folder')
+ $cont = rcube::Q(rcube_charset::convert($header->folder, 'UTF7-IMAP'));
else
$cont = rcube::Q($header->$col);
@@ -421,7 +489,7 @@ function rcmail_js_message_list($a_headers, $insert_top=FALSE, $a_show_cols=null
$a_msg_flags['prio'] = (int) $header->priority;
$a_msg_flags['ctype'] = rcube::Q($header->ctype);
- $a_msg_flags['mbox'] = $mbox;
+ $a_msg_flags['mbox'] = $header->folder;
// merge with plugin result (Deprecated, use $header->flags)
if (!empty($header->list_flags) && is_array($header->list_flags))
diff --git a/program/steps/mail/list.inc b/program/steps/mail/list.inc
index 277564c38..18f771d8b 100644
--- a/program/steps/mail/list.inc
+++ b/program/steps/mail/list.inc
@@ -42,6 +42,7 @@ if ($sort = rcube_utils::get_input_value('_sort', rcube_utils::INPUT_GET)) {
// is there a set of columns for this request?
if ($cols = rcube_utils::get_input_value('_cols', rcube_utils::INPUT_GET)) {
+ $_SESSION['list_attrib']['columns'] = $cols;
if (!in_array('list_cols', $dont_override)) {
$save_arr['list_cols'] = explode(',', $cols);
}
@@ -101,7 +102,8 @@ $OUTPUT->set_env('exists', $exists);
$OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($count), $mbox_name);
// add message rows
-rcmail_js_message_list($a_headers, FALSE, $cols);
+rcmail_js_message_list($a_headers, false, $cols);
+
if (isset($a_headers) && count($a_headers)) {
if ($search_request) {
$OUTPUT->show_message('searchsuccessful', 'confirmation', array('nr' => $count));
diff --git a/program/steps/mail/mark.inc b/program/steps/mail/mark.inc
index daa8c7e54..50243c636 100644
--- a/program/steps/mail/mark.inc
+++ b/program/steps/mail/mark.inc
@@ -36,7 +36,7 @@ $a_flags_map = array(
'unflagged' => 'UNFLAGGED',
);
-if (($uids = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_POST))
+if (($_uids = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_POST))
&& ($flag = rcube_utils::get_input_value('_flag', rcube_utils::INPUT_POST))
) {
$flag = $a_flags_map[$flag] ? $a_flags_map[$flag] : strtoupper($flag);
@@ -45,10 +45,12 @@ if (($uids = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_POST))
// count messages before changing anything
$old_count = $RCMAIL->storage->count(NULL, $threading ? 'THREADS' : 'ALL');
$old_pages = ceil($old_count / $RCMAIL->storage->get_pagesize());
- $count = sizeof(explode(',', $uids));
}
- $marked = $RCMAIL->storage->set_flag($uids, $flag);
+ foreach (rcmail_get_uids() as $mbox => $uids) {
+ $marked += (int)$RCMAIL->storage->set_flag($uids, $flag, $mbox);
+ $count += count($uids);
+ }
if (!$marked) {
// send error message
@@ -128,7 +130,7 @@ if (($uids = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_POST))
}
// add new rows from next page (if any)
- if ($count && $uids != '*' && ($jump_back || $nextpage_count > 0)) {
+ if ($old_count && $_uids != '*' && ($jump_back || $nextpage_count > 0)) {
$a_headers = $RCMAIL->storage->list_messages($mbox, NULL,
rcmail_sort_column(), rcmail_sort_order(), $jump_back ? NULL : $count);
diff --git a/program/steps/mail/move_del.inc b/program/steps/mail/move_del.inc
index 7564bb89d..26c724597 100644
--- a/program/steps/mail/move_del.inc
+++ b/program/steps/mail/move_del.inc
@@ -5,7 +5,7 @@
| program/steps/mail/move_del.inc |
| |
| This file is part of the Roundcube Webmail client |
- | Copyright (C) 2005-2009, The Roundcube Dev Team |
+ | Copyright (C) 2005-2013, The Roundcube Dev Team |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
@@ -32,11 +32,13 @@ $trash = $RCMAIL->config->get('trash_mbox');
// move messages
if ($RCMAIL->action == 'move' && !empty($_POST['_uid']) && strlen($_POST['_target_mbox'])) {
- $count = sizeof(explode(',', ($uids = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_POST))));
$target = rcube_utils::get_input_value('_target_mbox', rcube_utils::INPUT_POST, true);
- $mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_POST, true);
+ $trash = $RCMAIL->config->get('trash_mbox');
- $moved = $RCMAIL->storage->move_message($uids, $target, $mbox);
+ foreach (rcmail_get_uids() as $mbox => $uids) {
+ $moved += (int)$RCMAIL->storage->move_message($uids, $target, $mbox);
+ $count += count($uids);
+ }
if (!$moved) {
// send error message
@@ -47,17 +49,17 @@ if ($RCMAIL->action == 'move' && !empty($_POST['_uid']) && strlen($_POST['_targe
exit;
}
else {
- $OUTPUT->show_message('messagemoved', 'confirmation');
+ $OUTPUT->show_message('messagemoved', 'confirmation');
}
$addrows = true;
}
// delete messages
else if ($RCMAIL->action=='delete' && !empty($_POST['_uid'])) {
- $count = sizeof(explode(',', ($uids = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_POST))));
- $mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_POST, true);
-
- $del = $RCMAIL->storage->delete_message($uids, $mbox);
+ foreach (rcmail_get_uids() as $mbox => $uids) {
+ $del += (int)$RCMAIL->storage->delete_message($uids, $mbox);
+ $count += count($uids);
+ }
if (!$del) {
// send error message
@@ -68,7 +70,7 @@ else if ($RCMAIL->action=='delete' && !empty($_POST['_uid'])) {
exit;
}
else {
- $OUTPUT->show_message('messagedeleted', 'confirmation');
+ $OUTPUT->show_message('messagedeleted', 'confirmation');
}
$addrows = true;
diff --git a/program/steps/mail/search.inc b/program/steps/mail/search.inc
index ba8b124a3..941e68bd9 100644
--- a/program/steps/mail/search.inc
+++ b/program/steps/mail/search.inc
@@ -21,6 +21,8 @@
$REMOTE_REQUEST = TRUE;
+@set_time_limit(170); // extend default max_execution_time to ~3 minutes
+
// reset list_page and old search results
$RCMAIL->storage->set_page(1);
$RCMAIL->storage->set_search_set(NULL);
@@ -35,6 +37,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();
$filter = trim($filter);
@@ -102,6 +105,16 @@ if (!empty($subject)) {
foreach ($subject as $sub) {
$search_str .= ' ' . $sub . ' ' . rcube_imap_generic::escape($search);
}
+
+ // 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);
+ }
}
$search_str = trim($search_str);
@@ -109,9 +122,13 @@ $sort_column = rcmail_sort_column();
// 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);
}
+// 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();
@@ -122,15 +139,11 @@ if ($search_str) {
$_SESSION['last_text_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');
+$_SESSION['search_scope'] = $scope;
// Make sure we got the headers
if (!empty($result_h)) {
- rcmail_js_message_list($result_h);
+ rcmail_js_message_list($result_h, false);
if ($search_str) {
$OUTPUT->show_message('searchsuccessful', 'confirmation', array('nr' => $RCMAIL->storage->count(NULL, 'ALL')));
}
@@ -152,6 +165,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'));