From f540f86d19ae1d374ba3c78fe11eaf3f771af150 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/steps/mail/func.inc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'program/steps/mail/func.inc') diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc index 48afecb60..b677c4675 100644 --- a/program/steps/mail/func.inc +++ b/program/steps/mail/func.inc @@ -363,6 +363,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 = format_date($header->date); + else if ($col == 'folder') + $cont = Q(rcube_charset::convert($header->folder, 'UTF7-IMAP')); else $cont = Q($header->$col); @@ -386,7 +388,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'] = 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)) -- cgit v1.2.3 From 9e63cd5f24defa521724dfe3dcbbaa4385761836 Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 9 Oct 2013 17:12:30 +0200 Subject: Support globally unique message UIDs with IMAP folder name appended --- program/js/app.js | 27 ++++++++++++++++--------- program/steps/mail/copy.inc | 6 +++--- program/steps/mail/func.inc | 44 +++++++++++++++++++++++++++++++++++++++++ program/steps/mail/mark.inc | 10 ++++++---- program/steps/mail/move_del.inc | 21 ++++++++++---------- program/steps/mail/search.inc | 16 ++++++++++++++- 6 files changed, 97 insertions(+), 27 deletions(-) (limited to 'program/steps/mail/func.inc') diff --git a/program/js/app.js b/program/js/app.js index 1d59794d7..94f343f9e 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -641,7 +641,7 @@ function rcube_webmail() case 'open': if (uid = this.get_single_uid()) { - obj.href = this.url('show', {_mbox: this.env.mailbox, _uid: uid}); + obj.href = this.url('show', {_mbox: this.get_message_mailbox(uid), _uid: uid}); return true; } break; @@ -737,9 +737,9 @@ function rcube_webmail() this.load_contact(cid, 'edit'); else if (this.task == 'settings' && props) this.load_identity(props, 'edit-identity'); - else if (this.task == 'mail' && (cid = this.get_single_uid())) { - url = { _mbox: this.env.mailbox }; - url[this.env.mailbox == this.env.drafts_mailbox && props != 'new' ? '_draft_uid' : '_uid'] = cid; + else if (this.task == 'mail' && (uid = this.get_single_uid())) { + url = { _mbox: this.get_message_mailbox(uid) }; + url[this.env.mailbox == this.env.drafts_mailbox && props != 'new' ? '_draft_uid' : '_uid'] = uid; this.open_compose_step(url); } break; @@ -1029,7 +1029,7 @@ function rcube_webmail() case 'reply-list': case 'reply': if (uid = this.get_single_uid()) { - url = {_reply_uid: uid, _mbox: this.env.mailbox}; + url = {_reply_uid: uid, _mbox: this.get_message_mailbox(uid)}; if (command == 'reply-all') // do reply-list, when list is detected and popup menu wasn't used url._all = (!props && this.commands['reply-list'] ? 'list' : 'all'); @@ -1057,7 +1057,7 @@ function rcube_webmail() this.gui_objects.messagepartframe.contentWindow.print(); } else if (uid = this.get_single_uid()) { - ref.printwin = this.open_window(this.env.comm_path+'&_action=print&_uid='+uid+'&_mbox='+urlencode(this.env.mailbox)+(this.env.safemode ? '&_safe=1' : ''), true, true); + ref.printwin = this.open_window(this.env.comm_path+'&_action=print&_uid='+uid+'&_mbox='+urlencode(this.get_message_mailbox(uid))+(this.env.safemode ? '&_safe=1' : ''), true, true); if (this.printwin) { if (this.env.action != 'show') this.mark_message('read', uid); @@ -1074,8 +1074,9 @@ function rcube_webmail() if (this.env.action == 'get') { location.href = location.href.replace(/_frame=/, '_download='); } - else if (uid = this.get_single_uid()) - this.goto_url('viewsource', { _uid: uid, _mbox: this.env.mailbox, _save: 1 }); + else if (uid = this.get_single_uid()) { + this.goto_url('viewsource', { _uid: uid, _mbox: this.get_message_mailbox(uid), _save: 1 }); + } break; // quicksearch @@ -1772,6 +1773,7 @@ function rcube_webmail() selected: this.select_all_mode || this.message_list.in_selection(uid), ml: flags.ml?1:0, ctype: flags.ctype, + mbox: flags.mbox, // flags from plugins flags: flags.extra_flags }); @@ -1974,7 +1976,7 @@ function rcube_webmail() var win, target = window, action = preview ? 'preview': 'show', - url = '&_action='+action+'&_uid='+id+'&_mbox='+urlencode(this.env.mailbox); + url = '&_action='+action+'&_uid='+id+'&_mbox='+urlencode(this.get_message_mailbox(id)); if (preview && (win = this.get_frame_window(this.env.contentframe))) { target = win; @@ -6882,6 +6884,13 @@ function rcube_webmail() return this.env.cid ? this.env.cid : (this.contact_list ? this.contact_list.get_single_selection() : null); }; + // get the IMP mailbox of the message with the given UID + this.get_message_mailbox = function(uid) + { + var msg = this.env.messages ? this.env.messages[uid] : {}; + return msg.mbox || this.env.mailbox; + } + // gets cursor position this.get_caret_pos = function(obj) { diff --git a/program/steps/mail/copy.inc b/program/steps/mail/copy.inc index 876657485..0ed0d05a1 100644 --- a/program/steps/mail/copy.inc +++ b/program/steps/mail/copy.inc @@ -25,11 +25,11 @@ if (!$OUTPUT->ajax_call) // move messages if (!empty($_POST['_uid']) && strlen($_POST['_target_mbox'])) { - $uids = get_input_value('_uid', RCUBE_INPUT_POST); $target = get_input_value('_target_mbox', RCUBE_INPUT_POST, true); - $mbox = get_input_value('_mbox', RCUBE_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 b677c4675..807ec3ce9 100644 --- a/program/steps/mail/func.inc +++ b/program/steps/mail/func.inc @@ -66,6 +66,21 @@ 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); + + if (empty($_REQUEST['_mbox']) && !empty($mbox)) { + $_GET['_mbox'] = $mbox; + $_POST['_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 @@ -161,6 +176,35 @@ $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 -[,-]* + + $_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 'to' if current folder is configured Sent or Drafts diff --git a/program/steps/mail/mark.inc b/program/steps/mail/mark.inc index dfc892ea1..fad11d0fc 100644 --- a/program/steps/mail/mark.inc +++ b/program/steps/mail/mark.inc @@ -32,7 +32,7 @@ $a_flags_map = array( $threading = (bool) $RCMAIL->storage->get_threading(); -if (($uids = get_input_value('_uid', RCUBE_INPUT_POST)) && ($flag = get_input_value('_flag', RCUBE_INPUT_POST))) +if (($_uids = get_input_value('_uid', RCUBE_INPUT_POST)) && ($flag = get_input_value('_flag', RCUBE_INPUT_POST))) { $flag = $a_flags_map[$flag] ? $a_flags_map[$flag] : strtoupper($flag); @@ -40,10 +40,12 @@ if (($uids = get_input_value('_uid', RCUBE_INPUT_POST)) && ($flag = get_input_va // 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 @@ -117,7 +119,7 @@ if (($uids = get_input_value('_uid', RCUBE_INPUT_POST)) && ($flag = get_input_va } // 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 f15cd2460..e172d7188 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. | @@ -30,12 +30,13 @@ $old_pages = ceil($old_count / $RCMAIL->storage->get_pagesize()); // move messages if ($RCMAIL->action == 'move' && !empty($_POST['_uid']) && strlen($_POST['_target_mbox'])) { - $count = sizeof(explode(',', ($uids = get_input_value('_uid', RCUBE_INPUT_POST)))); $target = get_input_value('_target_mbox', RCUBE_INPUT_POST, true); - $mbox = get_input_value('_mbox', RCUBE_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 @@ -46,17 +47,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 = get_input_value('_uid', RCUBE_INPUT_POST)))); - $mbox = get_input_value('_mbox', RCUBE_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 @@ -67,7 +68,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 fb1b48797..0632b042a 100644 --- a/program/steps/mail/search.inc +++ b/program/steps/mail/search.inc @@ -126,9 +126,23 @@ $_SESSION['search_request'] = $search_request; $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 ($multi_folder_search) { + $a_show_cols = $_SESSION['list_attrib']['columns'] ? $_SESSION['list_attrib']['columns'] : (array)$CONFIG['list_cols']; + if (!in_array($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; + if ($header->parent_uid) + $header->parent_uid .= '-'.$header->folder; + } +} + // Make sure we got the headers if (!empty($result_h)) { - rcmail_js_message_list($result_h); + rcmail_js_message_list($result_h, false, $a_show_cols); if ($search_str) $OUTPUT->show_message('searchsuccessful', 'confirmation', array('nr' => $RCMAIL->storage->count(NULL, 'ALL'))); } -- cgit v1.2.3 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/js/app.js | 4 +++- program/js/list.js | 14 ++++++++++++++ program/lib/Roundcube/rcube_imap.php | 1 + program/lib/Roundcube/rcube_message_header.php | 9 +++++++++ program/steps/mail/func.inc | 4 +++- skins/larry/mail.css | 8 ++++++++ 6 files changed, 38 insertions(+), 2 deletions(-) (limited to 'program/steps/mail/func.inc') diff --git a/program/js/app.js b/program/js/app.js index 654faa024..55387c0ed 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -6399,8 +6399,10 @@ function rcube_webmail() if ((n = $.inArray('status', this.env.coltypes)) >= 0) this.env.status_col = n; - if (list) + if (list) { + list.hide_column('folder', !(this.env.search_request || this.env.search_id)); list.init_header(); + } }; // replace content of row count display diff --git a/program/js/list.js b/program/js/list.js index 022ed3180..319807eae 100644 --- a/program/js/list.js +++ b/program/js/list.js @@ -381,6 +381,20 @@ blur: function() }, +/** + * Set/unset the given column as hidden + */ +hide_column: function(col, hide) +{ + var method = hide ? 'addClass' : 'removeClass'; + + if (this.fixed_header) + $(this.row_tagname()+' '+this.col_tagname()+'.'+col, this.fixed_header)[method]('hidden'); + + $(this.row_tagname()+' '+this.col_tagname()+'.'+col, this.list)[method]('hidden'); +}, + + /** * onmousedown-handler of message list column */ 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', diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc index 0211fabc4..7436544be 100644 --- a/program/steps/mail/func.inc +++ b/program/steps/mail/func.inc @@ -398,6 +398,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 +423,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/skins/larry/mail.css b/skins/larry/mail.css index 8e6e78e77..bf77201fd 100644 --- a/skins/larry/mail.css +++ b/skins/larry/mail.css @@ -497,6 +497,14 @@ table.messagelist.fixedcopy { width: 155px; } +.messagelist tr td.folder { + width: 135px; +} + +.messagelist tr td.hidden { + display: none; +} + .messagelist tr.message { /* background-color: #fff; */ } -- cgit v1.2.3 From 9684dc018f68b037e8ee369e7ed08f4c760fe736 Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 9 Oct 2013 17:12:30 +0200 Subject: Support globally unique message UIDs with IMAP folder name appended --- program/js/app.js | 27 ++++++++++++++++--------- program/steps/mail/copy.inc | 6 +++--- program/steps/mail/func.inc | 44 +++++++++++++++++++++++++++++++++++++++++ program/steps/mail/mark.inc | 10 ++++++---- program/steps/mail/move_del.inc | 22 +++++++++++---------- program/steps/mail/search.inc | 16 ++++++++++++++- 6 files changed, 98 insertions(+), 27 deletions(-) (limited to 'program/steps/mail/func.inc') diff --git a/program/js/app.js b/program/js/app.js index 55387c0ed..2717e35d5 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -685,7 +685,7 @@ function rcube_webmail() case 'open': if (uid = this.get_single_uid()) { - obj.href = this.url('show', {_mbox: this.env.mailbox, _uid: uid}); + obj.href = this.url('show', {_mbox: this.get_message_mailbox(uid), _uid: uid}); return true; } break; @@ -788,9 +788,9 @@ function rcube_webmail() this.load_contact(cid, 'edit'); else if (this.task == 'settings' && props) this.load_identity(props, 'edit-identity'); - else if (this.task == 'mail' && (cid = this.get_single_uid())) { - url = { _mbox: this.env.mailbox }; - url[this.env.mailbox == this.env.drafts_mailbox && props != 'new' ? '_draft_uid' : '_uid'] = cid; + else if (this.task == 'mail' && (uid = this.get_single_uid())) { + url = { _mbox: this.get_message_mailbox(uid) }; + url[this.env.mailbox == this.env.drafts_mailbox && props != 'new' ? '_draft_uid' : '_uid'] = uid; this.open_compose_step(url); } break; @@ -1070,7 +1070,7 @@ function rcube_webmail() case 'reply-list': case 'reply': if (uid = this.get_single_uid()) { - url = {_reply_uid: uid, _mbox: this.env.mailbox}; + url = {_reply_uid: uid, _mbox: this.get_message_mailbox(uid)}; if (command == 'reply-all') // do reply-list, when list is detected and popup menu wasn't used url._all = (!props && this.env.reply_all_mode == 1 && this.commands['reply-list'] ? 'list' : 'all'); @@ -1098,7 +1098,7 @@ function rcube_webmail() this.gui_objects.messagepartframe.contentWindow.print(); } else if (uid = this.get_single_uid()) { - ref.printwin = this.open_window(this.env.comm_path+'&_action=print&_uid='+uid+'&_mbox='+urlencode(this.env.mailbox)+(this.env.safemode ? '&_safe=1' : ''), true, true); + ref.printwin = this.open_window(this.env.comm_path+'&_action=print&_uid='+uid+'&_mbox='+urlencode(this.get_message_mailbox(uid))+(this.env.safemode ? '&_safe=1' : ''), true, true); if (this.printwin) { if (this.env.action != 'show') this.mark_message('read', uid); @@ -1115,8 +1115,9 @@ function rcube_webmail() if (this.env.action == 'get') { location.href = location.href.replace(/_frame=/, '_download='); } - else if (uid = this.get_single_uid()) - this.goto_url('viewsource', { _uid: uid, _mbox: this.env.mailbox, _save: 1 }); + else if (uid = this.get_single_uid()) { + this.goto_url('viewsource', { _uid: uid, _mbox: this.get_message_mailbox(uid), _save: 1 }); + } break; // quicksearch @@ -1820,6 +1821,7 @@ function rcube_webmail() selected: this.select_all_mode || this.message_list.in_selection(uid), ml: flags.ml?1:0, ctype: flags.ctype, + mbox: flags.mbox, // flags from plugins flags: flags.extra_flags }); @@ -2022,7 +2024,7 @@ function rcube_webmail() var win, target = window, action = preview ? 'preview': 'show', - url = '&_action='+action+'&_uid='+id+'&_mbox='+urlencode(this.env.mailbox); + url = '&_action='+action+'&_uid='+id+'&_mbox='+urlencode(this.get_message_mailbox(id)); if (preview && (win = this.get_frame_window(this.env.contentframe))) { target = win; @@ -7424,6 +7426,13 @@ function rcube_webmail() return this.env.cid ? this.env.cid : (this.contact_list ? this.contact_list.get_single_selection() : null); }; + // get the IMP mailbox of the message with the given UID + this.get_message_mailbox = function(uid) + { + var msg = this.env.messages ? this.env.messages[uid] : {}; + return msg.mbox || this.env.mailbox; + } + // gets cursor position this.get_caret_pos = function(obj) { 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 7436544be..cc2c7e0b5 100644 --- a/program/steps/mail/func.inc +++ b/program/steps/mail/func.inc @@ -68,6 +68,21 @@ 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); + + if (empty($_REQUEST['_mbox']) && !empty($mbox)) { + $_GET['_mbox'] = $mbox; + $_POST['_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 @@ -166,6 +181,35 @@ $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 -[,-]* + + $_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 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 a80887254..9f4cdc9c9 100644 --- a/program/steps/mail/search.inc +++ b/program/steps/mail/search.inc @@ -127,9 +127,23 @@ $_SESSION['search_request'] = $search_request; $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 ($multi_folder_search) { + $a_show_cols = $_SESSION['list_attrib']['columns'] ? $_SESSION['list_attrib']['columns'] : (array)$CONFIG['list_cols']; + if (!in_array($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; + if ($header->parent_uid) + $header->parent_uid .= '-'.$header->folder; + } +} + // Make sure we got the headers if (!empty($result_h)) { - rcmail_js_message_list($result_h); + rcmail_js_message_list($result_h, false, $a_show_cols); if ($search_str) { $OUTPUT->show_message('searchsuccessful', 'confirmation', array('nr' => $RCMAIL->storage->count(NULL, 'ALL'))); } -- 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/steps/mail/func.inc') 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 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/steps/mail/func.inc') 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 19262e6eab19951393154d8e52fe141c63b5cd5d Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Mon, 20 Jan 2014 15:53:28 +0100 Subject: Code cleanup: remove duplicated code, don't trigger multi-folder search on simple filter requests --- program/js/app.js | 2 +- program/steps/mail/func.inc | 24 +++++++++++++++++++++--- program/steps/mail/list.inc | 22 +++------------------- program/steps/mail/search.inc | 39 +++++++++++---------------------------- 4 files changed, 36 insertions(+), 51 deletions(-) (limited to 'program/steps/mail/func.inc') diff --git a/program/js/app.js b/program/js/app.js index e276f6f96..675372107 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -6422,7 +6422,7 @@ function rcube_webmail() this.env.status_col = n; if (list) { - list.hide_column('folder', !(this.env.search_request || this.env.search_id)); + list.hide_column('folder', !(this.env.search_request || this.env.search_id) || this.env.search_scope == 'base'); list.init_header(); } }; diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc index fd321e294..3487ec73f 100644 --- a/program/steps/mail/func.inc +++ b/program/steps/mail/func.inc @@ -363,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; @@ -382,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 @@ -390,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); @@ -412,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; } @@ -428,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(); diff --git a/program/steps/mail/list.inc b/program/steps/mail/list.inc index a77d60f32..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); } @@ -75,24 +76,6 @@ 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; - } - - $OUTPUT->command('select_folder', ''); - } } // remove old search data else if (empty($_REQUEST['_search']) && isset($_SESSION['search'])) { @@ -119,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/search.inc b/program/steps/mail/search.inc index e13bc2ce5..e17552f7d 100644 --- a/program/steps/mail/search.inc +++ b/program/steps/mail/search.inc @@ -104,21 +104,21 @@ 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); $sort_column = rcmail_sort_column(); -// 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) { $RCMAIL->storage->search($mboxes, $search_str, $imap_charset, $sort_column); @@ -140,26 +140,9 @@ if ($search_str) { $_SESSION['search_request'] = $search_request; $_SESSION['search_scope'] = $scope; -// 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', ''); -} - // Make sure we got the headers if (!empty($result_h)) { - rcmail_js_message_list($result_h, false, $a_show_cols); + rcmail_js_message_list($result_h, false); if ($search_str) { $OUTPUT->show_message('searchsuccessful', 'confirmation', array('nr' => $RCMAIL->storage->count(NULL, 'ALL'))); } -- cgit v1.2.3