Changeset 422 in subversion


Ignore:
Timestamp:
Dec 20, 2006 9:27:47 AM (7 years ago)
Author:
thomasb
Message:

Fixed wrong message listing when showing search results

Location:
trunk/roundcubemail
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/CHANGELOG

    r412 r422  
    11CHANGELOG RoundCube Webmail 
    22--------------------------- 
     3 
     42006/12/20 (thomasb) 
     5---------- 
     6- Fixed wrong message listing when showing search results (closes #1484131) 
     7- Introduced functions Q() and JQ() as aliases for rep_specialchars_output() 
     8- Show remote images when opening HTML message part as attachment 
     9 
    310 
    4112006/12/17 (thomasb) 
  • trunk/roundcubemail/program/include/rcube_imap.inc

    r384 r422  
    66 |                                                                       | 
    77 | This file is part of the RoundCube Webmail client                     | 
    8  | Copyright (C) 2005, RoundCube Dev. - Switzerland                      | 
     8 | Copyright (C) 2005-2006, RoundCube Dev. - Switzerland                 | 
    99 | Licensed under the GNU GPL                                            | 
    1010 |                                                                       | 
     
    3636 * @package    RoundCube Webmail 
    3737 * @author     Thomas Bruederli <roundcube@gmail.com> 
    38  * @version    1.34 
     38 * @version    1.36 
    3939 * @link       http://ilohamail.org 
    4040 */ 
     
    6161  var $capabilities = array(); 
    6262  var $skip_deleted = FALSE; 
     63  var $search_set = NULL; 
     64  var $search_subject = ''; 
     65  var $search_string = ''; 
     66  var $search_charset = ''; 
    6367  var $debug_level = 1; 
    6468 
     
    266270    $this->page_size = (int)$size; 
    267271    } 
     272     
     273 
     274  /** 
     275   * Save a set of message ids for future message listing methods 
     276   * 
     277   * @param  array  List of IMAP fields to search in 
     278   * @param  string Search string 
     279   * @param  array  List of message ids or NULL if empty 
     280   */ 
     281  function set_search_set($subject, $str=null, $msgs=null, $charset=null) 
     282    { 
     283    if (is_array($subject) && $str == null && $msgs == null) 
     284      list($subject, $str, $msgs, $charset) = $subject; 
     285    if ($msgs != null && !is_array($msgs)) 
     286      $msgs = split(',', $msgs); 
     287       
     288    $this->search_subject = $subject; 
     289    $this->search_string = $str; 
     290    $this->search_set = is_array($msgs) ? $msgs : NULL; 
     291    $this->search_charset = $charset; 
     292    } 
     293 
     294 
     295  /** 
     296   * Return the saved search set as hash array 
     297   */ 
     298  function get_search_set() 
     299    { 
     300    return array($this->search_subject, $this->search_string, $this->search_set, $this->search_charset); 
     301    } 
    268302 
    269303 
     
    403437    if (empty($mailbox)) 
    404438      $mailbox = $this->mailbox; 
     439       
     440    // count search set 
     441    if ($this->search_set && $mailbox == $this->mailbox && $mode == 'ALL') 
     442      return count($this->search_set); 
    405443 
    406444    $a_mailbox_cache = $this->get_cache('messagecount'); 
     
    482520    if (!strlen($mailbox)) 
    483521      return array(); 
    484        
     522 
     523    // use saved message set 
     524    if ($this->search_set && $mailbox == $this->mailbox) 
     525      return $this->_list_header_set($mailbox, $this->search_set, $page, $sort_field, $sort_order); 
     526 
    485527    if ($sort_field!=NULL) 
    486528      $this->sort_field = $sort_field; 
     
    493535    list($begin, $end) = $this->_get_message_range($max, $page); 
    494536 
    495         // mailbox is empty 
     537    // mailbox is empty 
    496538    if ($begin >= $end) 
    497539      return array(); 
    498  
     540       
    499541    $headers_sorted = FALSE; 
    500542    $cache_key = $mailbox.'.msg'; 
     
    615657 
    616658    // return empty array if no messages found 
    617         if (!is_array($a_msg_headers) || empty($a_msg_headers)) 
    618                 return array(); 
     659    if (!is_array($a_msg_headers) || empty($a_msg_headers)) 
     660      return array(); 
    619661 
    620662    // if not already sorted 
    621663    $a_msg_headers = iil_SortHeaders($a_msg_headers, $this->sort_field, $this->sort_order); 
    622664 
    623         // only return the requested part of the set 
    624         return array_slice(array_values($a_msg_headers), $start_msg, min($max-$start_msg, $this->page_size)); 
     665    // only return the requested part of the set 
     666    return array_slice(array_values($a_msg_headers), $start_msg, min($max-$start_msg, $this->page_size)); 
    625667    } 
    626668 
     
    831873    { 
    832874    $mailbox = $mbox_name ? $this->_mod_mailbox($mbox_name) : $this->mailbox; 
    833     if ($str && $criteria) 
     875 
     876    // have an array of criterias => execute multiple searches 
     877    if (is_array($criteria) && $str) 
     878      { 
     879      $results = array(); 
     880      foreach ($criteria as $crit) 
     881        $results = array_merge($results, $this->search($mbox_name, $crit, $str, $charset)); 
     882       
     883      $results = array_unique($results); 
     884      $this->set_search_set($criteria, $str, $results, $charset); 
     885      return $results; 
     886      } 
     887    else if ($str && $criteria) 
    834888      { 
    835889      $search = (!empty($charset) ? "CHARSET $charset " : '') . sprintf("%s {%d}\r\n%s", $criteria, strlen($str), $str); 
     
    840894        $results = $this->search($mbox_name, $criteria, rcube_charset_convert($str, $charset, 'ISO-8859-1'), 'ISO-8859-1'); 
    841895       
     896      $this->set_search_set($criteria, $str, $results, $charset); 
    842897      return $results; 
    843898      } 
     
    866921         
    867922    return $a_messages; 
     923    } 
     924     
     925   
     926  /** 
     927   * Refresh saved search set 
     928   */ 
     929  function refresh_search() 
     930    { 
     931    if (!empty($this->search_subject) && !empty($this->search_string)) 
     932      $this->search_set = $this->search('', $this->search_subject, $this->search_string, $this->search_charset); 
     933       
     934    return $this->get_search_set(); 
    868935    } 
    869936 
     
    13041371      $this->_clear_messagecount($to_mbox); 
    13051372      } 
     1373       
     1374    // remove message ids from search set 
     1375    if ($moved && $this->search_set && $from_mbox == $this->mailbox) 
     1376      $this->search_set = array_diff($this->search_set, $a_mids); 
    13061377 
    13071378    // update cached message headers 
     
    13121383      foreach ($a_uids as $uid) 
    13131384        { 
    1314         if(($index = array_search($uid, $a_cache_index)) !== FALSE) 
    1315           $start_index = min($index, $start_index); 
     1385        if (($index = array_search($uid, $a_cache_index)) !== FALSE) 
     1386          $start_index = min($index, $start_index); 
    13161387        } 
    13171388 
     
    13521423      $this->_clear_messagecount($mailbox); 
    13531424      } 
     1425 
     1426    // remove message ids from search set 
     1427    if ($moved && $this->search_set && $mailbox == $this->mailbox) 
     1428      $this->search_set = array_diff($this->search_set, $a_mids); 
    13541429 
    13551430    // remove deleted messages from cache 
  • trunk/roundcubemail/program/steps/mail/list.inc

    r232 r422  
    4141  $sort_order = isset($_SESSION['sort_order']) ? $_SESSION['sort_order'] : $CONFIG['message_sort_order']; 
    4242  } 
    43    
    4443 
    45 // we have a saved search request 
    46 if (!empty($_GET['_search']) && isset($_SESSION['search'][$_GET['_search']])) 
    47   { 
    48   $a_msgs = split(',', $_SESSION['search'][$_GET['_search']]); 
    49   $a_headers = $IMAP->list_header_set($mbox_name, $a_msgs, NULL, $sort_col, $sort_order); 
    50   $count = count($a_msgs); 
    51   } 
    52 else 
    53   { 
    54   if ($count = $IMAP->messagecount()) 
    55     $a_headers = $IMAP->list_headers($mbox_name, NULL, $sort_col, $sort_order); 
    56   } 
     44 
     45// fetch message headers 
     46if ($count = $IMAP->messagecount()) 
     47  $a_headers = $IMAP->list_headers($mbox_name, NULL, $sort_col, $sort_order); 
    5748 
    5849$unseen = $IMAP->messagecount($mbox_name, 'UNSEEN', !empty($_GET['_refresh']) ? TRUE : FALSE); 
  • trunk/roundcubemail/program/steps/mail/move_del.inc

    r388 r422  
    6060  } 
    6161 
     62// refresh saved seach set after moving some messages 
     63if (($search_request = $_GET['_search']) && $IMAP->search_set) 
     64  $_SESSION['search'][$search_request] = $IMAP->refresh_search(); 
     65 
    6266 
    6367// update message count display 
    64 $pages = ceil($IMAP->messagecount()/$IMAP->page_size); 
    65 $commands = sprintf("this.set_rowcount('%s');\n", rcmail_get_messagecount_text()); 
     68$msg_count = $IMAP->messagecount(); 
     69$pages = ceil($msg_count / $IMAP->page_size); 
     70$commands = sprintf("this.set_rowcount('%s');\n", rcmail_get_messagecount_text($msg_count)); 
    6671$commands .= sprintf("this.set_env('pagecount', %d);\n", $pages); 
    6772 
     
    7984if ($_GET['_from']!='show' && $pages>1 && $IMAP->list_page < $pages) 
    8085  { 
    81   $a_headers = $IMAP->list_headers($mbox, null, $_SESSION['sort_col'], $_SESSION['sort_order']); 
     86  $sort_col   = isset($_SESSION['sort_col'])   ? $_SESSION['sort_col']   : $CONFIG['message_sort_col']; 
     87  $sort_order = isset($_SESSION['sort_order']) ? $_SESSION['sort_order'] : $CONFIG['message_sort_order']; 
     88   
     89  $a_headers = $IMAP->list_headers($mbox, NULL, $sort_col, $sort_order); 
    8290  $a_headers = array_slice($a_headers, -$count, $count); 
     91 
    8392  $commands .= rcmail_js_message_list($a_headers); 
    8493  } 
    8594 
    86    
     95 
    8796// send response 
    8897rcube_remote_response($commands); 
  • trunk/roundcubemail/program/steps/mail/search.inc

    r305 r422  
    1616$REMOTE_REQUEST = TRUE; 
    1717 
    18 // reset list_page 
     18// reset list_page and old search results 
    1919$IMAP->set_page(1); 
     20$IMAP->set_search_set(NULL); 
    2021$_SESSION['page'] = 1; 
    2122 
     
    2728$str = get_input_value('_search', RCUBE_INPUT_GET); 
    2829$mbox = get_input_value('_mbox', RCUBE_INPUT_GET); 
    29 $search_request = md5($str); 
     30$search_request = md5($mbox.$str); 
    3031 
    3132 
    3233// Check the search string for type of search 
    33 if (preg_match("/^from:/i", $str)) { 
     34if (preg_match("/^from:/i", $str)) 
     35{ 
    3436  list(,$srch) = explode(":", $str); 
    35   $search = $IMAP->search($mbox, "HEADER FROM" ,trim($srch), $imap_charset); 
    36   finish_search($mbox, $search); 
     37  $subject =  "HEADER FROM"; 
     38  $search = trim($srch); 
    3739} 
    38 else if (preg_match("/^to:/i", $str)) { 
     40else if (preg_match("/^to:/i", $str)) 
     41{ 
    3942  list(,$srch) = explode(":", $str); 
    40   $search = $IMAP->search($mbox, "HEADER TO", trim($srch), $imap_charset); 
    41   finish_search($mbox, $search); 
     43  $subject = "HEADER TO"; 
     44  $search = trim($srch); 
    4245} 
    43 else if (preg_match("/^cc:/i", $str)) { 
     46else if (preg_match("/^cc:/i", $str)) 
     47{ 
    4448  list(,$srch) = explode(":", $str); 
    45   $search = $IMAP->search($mbox, "HEADER CC", trim($srch), $imap_charset); 
    46   finish_search($mbox, $search); 
     49  $subject = "HEADER CC"; 
     50  $search = trim($srch); 
    4751} 
    48 else if (preg_match("/^subject:/i", $str)) { 
     52else if (preg_match("/^subject:/i", $str)) 
     53{ 
    4954  list(,$srch) = explode(":", $str); 
    50   $search = $IMAP->search($mbox, "HEADER SUBJECT", trim($srch), $imap_charset); 
    51   finish_search($mbox, $search); 
     55  $subject = "HEADER SUBJECT"; 
     56  $search = trim($srch); 
    5257} 
    53 else if (preg_match("/^body:/i", $str)) { 
     58else if (preg_match("/^body:/i", $str)) 
     59{ 
    5460  list(,$srch) = explode(":", $str); 
    55   $search = $IMAP->search($mbox, "TEXT", trim($srch), $imap_charset); 
    56   finish_search($mbox, $search); 
     61  $subject = "TEXT"; 
     62  $search = trim($srch); 
    5763} 
    5864// search in subject and sender by default 
    59 else { 
    60   $search = $IMAP->search($mbox, "HEADER SUBJECT", trim($str), $imap_charset); 
    61   $search2 = $IMAP->search($mbox, "HEADER FROM", trim($str), $imap_charset); 
    62   finish_search($mbox, array_unique(array_merge($search, $search2))); 
     65else 
     66{ 
     67  $subject = array("HEADER SUBJECT", "HEADER FROM"); 
     68  $search = trim($str); 
    6369} 
    6470 
    6571 
    66 // Complete the search display results or report error 
    67 function finish_search($mbox, $search) 
     72// execute IMAP search 
     73$result = $IMAP->search($mbox, $subject, $search, $imap_charset); 
     74 
     75$commands = ''; 
     76$count = 0; 
     77   
     78// Make sure our $result is legit.. 
     79if (is_array($result) && $result[0] != '') 
    6880  { 
    69   global $IMAP, $JS_OBJECT_NAME, $OUTPUT, $search_request; 
    70   $commands = ''; 
    71   $count = 0; 
    72      
    73   // Make sure our $search is legit.. 
    74   if (is_array($search) && $search[0] != '') 
     81  // Get the headers 
     82  $result_h = $IMAP->list_header_set($mbox, $result, 1, $_SESSION['sort_col'], $_SESSION['sort_order']); 
     83  $count = count($result); 
     84 
     85  // save search results in session 
     86  if (!is_array($_SESSION['search'])) 
     87    $_SESSION['search'] = array(); 
     88 
     89  // Make sure we got the headers 
     90  if ($result_h != NULL) 
    7591    { 
    76     // Get the headers 
    77     $result_h = $IMAP->list_header_set($mbox, $search, 1, $_SESSION['sort_col'], $_SESSION['sort_order']); 
    78     $count = count($search); 
    79  
    80     // save search results in session 
    81     if (!is_array($_SESSION['search'])) 
    82       $_SESSION['search'] = array(); 
    83  
    84     // Make sure we got the headers 
    85     if ($result_h != NULL) 
    86       { 
    87       $_SESSION['search'][$search_request] = join(',', $search); 
    88       $commands = rcmail_js_message_list($result_h); 
    89       $commands .= show_message('searchsuccessful', 'confirmation', array('nr' => $count)); 
    90       } 
     92    $_SESSION['search'][$search_request] = $IMAP->get_search_set(); 
     93    $commands = rcmail_js_message_list($result_h); 
     94    $commands .= show_message('searchsuccessful', 'confirmation', array('nr' => $count)); 
    9195    } 
    92   else 
    93     { 
    94     $commands = show_message('searchnomatch', 'warning'); 
    95     $search_request = -1; 
    96     } 
    97    
    98   // update message count display 
    99   $pages = ceil($count/$IMAP->page_size); 
    100   $commands .= sprintf("\nthis.set_env('search_request', '%s')\n", $search_request); 
    101   $commands .= sprintf("this.set_env('messagecount', %d);\n", $count); 
    102   $commands .= sprintf("this.set_env('pagecount', %d);\n", $pages); 
    103   $commands .= sprintf("this.set_rowcount('%s');\n", rcmail_get_messagecount_text($count, 1)); 
    104   rcube_remote_response($commands); 
     96  } 
     97else 
     98  { 
     99  $commands = show_message('searchnomatch', 'warning'); 
     100  $search_request = -1; 
    105101  } 
    106102 
     103// update message count display 
     104$pages = ceil($count/$IMAP->page_size); 
     105$commands .= sprintf("\nthis.set_env('search_request', '%s')\n", $search_request); 
     106$commands .= sprintf("this.set_env('messagecount', %d);\n", $count); 
     107$commands .= sprintf("this.set_env('pagecount', %d);\n", $pages); 
     108$commands .= sprintf("this.set_rowcount('%s');\n", rcmail_get_messagecount_text($count, 1)); 
     109rcube_remote_response($commands); 
     110 
    107111?> 
Note: See TracChangeset for help on using the changeset viewer.