Thomas Bruederli
2014-01-20 19262e6eab19951393154d8e52fe141c63b5cd5d
Code cleanup: remove duplicated code, don't trigger multi-folder search on simple filter requests
4 files modified
87 ■■■■■ changed files
program/js/app.js 2 ●●● patch | view | raw | blame | history
program/steps/mail/func.inc 24 ●●●● patch | view | raw | blame | history
program/steps/mail/list.inc 22 ●●●● patch | view | raw | blame | history
program/steps/mail/search.inc 39 ●●●● patch | view | raw | blame | history
program/js/app.js
@@ -6422,7 +6422,7 @@
      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();
    }
  };
program/steps/mail/func.inc
@@ -363,7 +363,7 @@
/**
 * 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 @@
        $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
@@ -389,8 +397,6 @@
        array_unshift($a_show_cols, 'subject');
    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 @@
    $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 @@
        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();
program/steps/mail/list.inc
@@ -42,6 +42,7 @@
// 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 @@
    && $_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->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));
program/steps/mail/search.inc
@@ -104,20 +104,20 @@
    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) {
@@ -140,26 +140,9 @@
$_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')));
    }