Changeset 2983 in subversion


Ignore:
Timestamp:
Sep 23, 2009 8:32:09 AM (4 years ago)
Author:
alec
Message:
  • sorting by message index - added 'index_sort' option (#1485936)
Location:
trunk/roundcubemail
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/CHANGELOG

    r2977 r2983  
    22=========================== 
    33 
     4- Fix Received header format 
     5- Implemented sorting by message index - added 'index_sort' option (#1485936) 
    46- Fix dl() use in installer (#1486150) 
    57- Added 'ldap_debug' option 
  • trunk/roundcubemail/config/main.inc.php.dist

    r2976 r2983  
    444444$rcmail_config['display_next'] = FALSE; 
    445445 
     446// If true, messages list will be sorted by message index instead of message date 
     447$rcmail_config['index_sort'] = TRUE; 
     448 
    446449// end of config file 
    447450?> 
  • trunk/roundcubemail/program/include/rcmail.php

    r2976 r2983  
    367367    $this->imap->debug_level = $this->config->get('debug_level'); 
    368368    $this->imap->skip_deleted = $this->config->get('skip_deleted'); 
     369    $this->imap->index_sort = $this->config->get('index_sort', true); 
    369370 
    370371    // enable caching of imap data 
  • trunk/roundcubemail/program/include/rcube_imap.php

    r2974 r2983  
    5151  var $sort_field = 'date'; 
    5252  var $sort_order = 'DESC'; 
     53  var $index_sort = true; 
    5354  var $delimiter = NULL; 
    5455  var $caching_enabled = FALSE; 
     
    599600    $a_msg_headers = array(); 
    600601 
    601     if ($this->get_capability('sort') && ($msg_index = iil_C_Sort($this->conn, $mailbox, $this->sort_field, $this->skip_deleted ? 'UNDELETED' : ''))) 
     602    // use message index sort for sorting by Date (for better performance) 
     603    if ($this->index_sort && $this->sort_field == 'date') 
     604      { 
     605        if ($this->skip_deleted) { 
     606          $msg_index = $this->_search_index($mailbox, 'ALL'); 
     607          $max = max($msg_index); 
     608          list($begin, $end) = $this->_get_message_range(count($msg_index), $page); 
     609          $msg_index = array_slice($msg_index, $begin, $end-$begin); 
     610        } else if ($max = iil_C_CountMessages($this->conn, $mailbox)) { 
     611          list($begin, $end) = $this->_get_message_range($max, $page); 
     612          $msg_index = range($begin+1, $end); 
     613        } else 
     614          return array(); 
     615 
     616        if ($slice) 
     617          $msg_index = array_slice($msg_index, ($this->sort_order == 'DESC' ? 0 : -$slice), $slice); 
     618 
     619        // fetch reqested headers from server 
     620        $this->_fetch_headers($mailbox, join(",", $msg_index), $a_msg_headers, $cache_key); 
     621      } 
     622    // use SORT command 
     623    else if ($this->get_capability('sort') && ($msg_index = iil_C_Sort($this->conn, $mailbox, $this->sort_field, $this->skip_deleted ? 'UNDELETED' : ''))) 
    602624      { 
    603625      list($begin, $end) = $this->_get_message_range(count($msg_index), $page); 
     
    611633      $this->_fetch_headers($mailbox, join(',', $msg_index), $a_msg_headers, $cache_key); 
    612634      } 
     635    // fetch specified header for all messages and sort 
    613636    else 
    614637      { 
     
    678701    $this->_set_sort_order($sort_field, $sort_order); 
    679702 
     703    // quickest method 
     704    if ($this->index_sort && $this->search_sort_field == 'date' && $this->sort_field == 'date') 
     705      { 
     706      if ($sort_order == 'DESC') 
     707        $msgs = array_reverse($msgs); 
     708 
     709      // get messages uids for one page 
     710      $msgs = array_slice(array_values($msgs), $start_msg, min(count($msgs)-$start_msg, $this->page_size)); 
     711 
     712      if ($slice) 
     713        $msgs = array_slice($msgs, -$slice, $slice); 
     714 
     715      // fetch headers 
     716      $this->_fetch_headers($mailbox, join(',',$msgs), $a_msg_headers, NULL); 
     717 
     718      // I didn't found in RFC that FETCH always returns messages sorted by index 
     719      $sorter = new rcube_header_sorter(); 
     720      $sorter->set_sequence_numbers($msgs); 
     721      $sorter->sort_headers($a_msg_headers); 
     722 
     723      return array_values($a_msg_headers); 
     724      } 
    680725    // sorted messages, so we can first slice array and then fetch only wanted headers 
    681     if ($this->get_capability('sort')) // SORT searching result 
     726    if ($this->get_capability('sort') && (!$this->index_sort || $this->sort_field != 'date')) // SORT searching result 
    682727      { 
    683728      // reset search set if sorting field has been changed 
    684729      if ($this->sort_field && $this->search_sort_field != $this->sort_field) 
    685         { 
    686730        $msgs = $this->search('', $this->search_string, $this->search_charset, $this->sort_field); 
    687         } 
    688731 
    689732      // return empty array if no messages found 
     
    711754    else { // SEARCH searching result, need sorting 
    712755      $cnt = count($msgs); 
    713       if ($cnt > 300 && $cnt > $this->page_size) { // experimantal value for best result 
     756      // 300: experimantal value for best result 
     757      if (($cnt > 300 && $cnt > $this->page_size) || ($this->index_sort && $this->sort_field == 'date')) { 
    714758        // use memory less expensive (and quick) method for big result set 
    715759        $a_index = $this->message_index('', $this->sort_field, $this->sort_order); 
     
    845889    $key = "{$mailbox}:{$this->sort_field}:{$this->sort_order}:{$this->search_string}.msgi"; 
    846890 
    847     // we have a saved search result. get index from there 
     891    // we have a saved search result, get index from there 
    848892    if (!isset($this->cache[$key]) && $this->search_string && $mailbox == $this->mailbox) 
    849893    { 
    850894      $this->cache[$key] = array(); 
    851895       
    852       if ($this->get_capability('sort')) 
     896      // use message index sort for sorting by Date 
     897      if ($this->index_sort && $this->sort_field == 'date') 
     898        { 
     899        $msgs = $this->search_set; 
     900         
     901        if ($this->search_sort_field != 'date') 
     902          sort($msgs); 
     903         
     904        if ($this->sort_order == 'DESC') 
     905          $this->cache[$key] = array_reverse($msgs); 
     906        else 
     907          $this->cache[$key] = $msgs; 
     908        } 
     909      // sort with SORT command 
     910      else if ($this->get_capability('sort')) 
    853911        { 
    854912        if ($this->sort_field && $this->search_sort_field != $this->sort_field) 
     
    888946      } 
    889947 
     948    // use message index sort for sorting by Date 
     949    if ($this->index_sort && $this->sort_field == 'date') 
     950      { 
     951      if ($this->skip_deleted) { 
     952        $a_index = $this->_search_index($mailbox, 'ALL'); 
     953      } else if ($max = $this->_messagecount($mailbox)) { 
     954        $a_index = range(1, $max); 
     955      } 
     956 
     957      if ($this->sort_order == 'DESC') 
     958        $a_index = array_reverse($a_index); 
     959 
     960      $this->cache[$key] = $a_index; 
     961      } 
    890962    // fetch complete message index 
    891     if ($this->get_capability('sort') && ($a_index = iil_C_Sort($this->conn, $mailbox, $this->sort_field, $this->skip_deleted ? 'UNDELETED' : ''))) 
     963    else if ($this->get_capability('sort') && ($a_index = iil_C_Sort($this->conn, $mailbox, $this->sort_field, $this->skip_deleted ? 'UNDELETED' : ''))) 
    892964      { 
    893965      if ($this->sort_order == 'DESC') 
     
    10331105      $criteria = 'UNDELETED '.$criteria; 
    10341106 
    1035     if ($sort_field && $this->get_capability('sort')) 
    1036       { 
     1107    if ($sort_field && $this->get_capability('sort') && (!$this->index_sort || $sort_field != 'date')) { 
    10371108      $charset = $charset ? $charset : $this->default_charset; 
    10381109      $a_messages = iil_C_Sort($this->conn, $mailbox, $sort_field, $criteria, FALSE, $charset); 
    10391110      } 
    1040     else 
    1041       $a_messages = iil_C_Search($this->conn, $mailbox, ($charset ? "CHARSET $charset " : '') . $criteria); 
    1042      
     1111    else { 
     1112      if ($orig_criteria == 'ALL') { 
     1113        $max = $this->_messagecount($mailbox); 
     1114        $a_messages = $max ? range(1, $max) : array(); 
     1115        } 
     1116      else { 
     1117        $a_messages = iil_C_Search($this->conn, $mailbox, ($charset ? "CHARSET $charset " : '') . $criteria); 
     1118     
     1119        // I didn't found that SEARCH always returns sorted IDs 
     1120        if ($this->index_sort && $this->sort_field == 'date') 
     1121          sort($a_messages); 
     1122        } 
     1123      } 
    10431124    // update messagecount cache ? 
    10441125//    $a_mailbox_cache = get_cache('messagecount'); 
     
    22202301   * @param string Mailbox name 
    22212302   * @param string Internal cache key 
    2222    * @return int -3 = off, -2 = incomplete, -1 = dirty 
     2303   * @return int   Cache status: -3 = off, -2 = incomplete, -1 = dirty 
    22232304   */ 
    22242305  private function check_cache_status($mailbox, $cache_key) 
     
    22272308      return -3; 
    22282309 
    2229     $cache_index = $this->get_message_cache_index($cache_key, TRUE); 
     2310    $cache_index = $this->get_message_cache_index($cache_key); 
    22302311    $msg_count = $this->_messagecount($mailbox); 
    22312312    $cache_count = count($cache_index); 
     
    22342315    if (!$msg_count) 
    22352316      return $cache_count ? -2 : 1; 
    2236      
     2317 
     2318    // @TODO: We've got one big performance problem in cache status checking method 
     2319    // E.g. mailbox contains 1000 messages, in cache table we've got first 100 
     2320    // of them. Now if we want to display only that 100 (which we've got) 
     2321    // check_cache_status returns 'incomplete' and messages are fetched 
     2322    // from IMAP instead of DB. 
     2323 
    22372324    if ($cache_count==$msg_count) { 
    22382325      if ($this->skip_deleted) { 
     
    22492336        return -2; 
    22502337      } else { 
    2251         // get highest index 
    2252         $header = iil_C_FetchHeader($this->conn, $mailbox, "$msg_count"); 
     2338        // get UID of message with highest index 
     2339        $uid = iil_C_ID2UID($this->conn, $mailbox, $msg_count); 
    22532340        $cache_uid = array_pop($cache_index); 
    22542341       
    22552342        // uids of highest message matches -> cache seems OK 
    2256         if ($cache_uid == $header->uid) 
     2343        if ($cache_uid == $uid) 
    22572344          return 1; 
    22582345      } 
     
    22752362    $db_header_fields = array('idx', 'uid', 'subject', 'from', 'to', 'cc', 'date', 'size'); 
    22762363     
    2277     if (!in_array($sort_field, $db_header_fields)) 
     2364    $config = rcmail::get_instance()->config; 
     2365 
     2366    // use idx sort for sorting by Date with index_sort=true or for unknown field 
     2367    if (($sort_field == 'date' && $this->index_sort) 
     2368      || !in_array($sort_field, $db_header_fields)) { 
    22782369      $sort_field = 'idx'; 
     2370      } 
    22792371     
    22802372    if ($this->caching_enabled && !isset($this->cache[$cache_key])) 
     
    23502442    if (!empty($sa_message_index[$key]) && !$force) 
    23512443      return $sa_message_index[$key]; 
     2444 
     2445    // use idx sort for sorting by Date with index_sort=true 
     2446    if ($sort_field == 'date' && $this->index_sort) 
     2447      $sort_field = 'idx'; 
    23522448     
    23532449    $sa_message_index[$key] = array(); 
  • trunk/roundcubemail/program/js/app.js

    r2978 r2983  
    30193019        target = window.frames[this.env.contentframe]; 
    30203020        } 
    3021  
    30223021      target.location.href = this.env.comm_path+'&_action=edit-prefs&_section='+id+add_url; 
    30233022      } 
  • trunk/roundcubemail/program/localization/en_US/labels.inc

    r2831 r2983  
    307307$labels['checkallfolders'] = 'Check all folders for new messages'; 
    308308$labels['displaynext'] = 'After message delete/move display the next message'; 
     309$labels['indexsort'] = 'Use message index for sorting by date'; 
    309310$labels['mainoptions'] = 'Main Options'; 
    310311$labels['section'] = 'Section'; 
  • trunk/roundcubemail/program/localization/pl_PL/labels.inc

    r2836 r2983  
    267267$labels['skipdeleted'] = 'Ukryj wiadomości oznaczone do usunięcia'; 
    268268$labels['autosavedraft'] = 'Automatyczny zapis tworzonej wiadomości'; 
     269$labels['indexsort'] = 'Stosuj indeks wiadomości do sortowania wg daty'; 
    269270$labels['keepalive']  = 'Sprawdzaj czy nadeszły nowe wiadomości'; 
    270271$labels['everynminutes']  = 'co $n minut(y)'; 
  • trunk/roundcubemail/program/steps/mail/list.inc

    r2960 r2983  
    5050{ 
    5151  $search_request = md5($mbox_name.$_SESSION['search_filter']); 
    52  
    5352  $IMAP->search($mbox_name, $_SESSION['search_filter'], RCMAIL_CHARSET, $sort_col); 
    5453  $_SESSION['search'][$search_request] = $IMAP->get_search_set(); 
    5554  $OUTPUT->set_env('search_request', $search_request); 
    5655} 
    57                                
    5856 
    5957// fetch message headers 
  • trunk/roundcubemail/program/steps/settings/edit_prefs.inc

    r2830 r2983  
    163163    } 
    164164 
     165    // Show checkbox for toggling 'index_sort'  
     166    if (!isset($no_override['index_sort'])) { 
     167      $field_id = 'rcmfd_indexsort'; 
     168      $input_indexsort = new html_checkbox(array('name' => '_index_sort', 'id' => $field_id, 'value' => 1)); 
     169 
     170      $blocks['list']['options']['index_sort'] = array( 
     171        'title' => html::label($field_id, Q(rcube_label('indexsort'))), 
     172        'content' => $input_indexsort->show($config['index_sort']?1:0), 
     173      ); 
     174    } 
     175 
    165176    // show drop-down for available skins 
    166177    if (!isset($no_override['skin'])) { 
  • trunk/roundcubemail/program/steps/settings/save_prefs.inc

    r2873 r2983  
    3333      'dst_active'   => isset($_POST['_dst_active']) ? TRUE : FALSE, 
    3434      'pagesize'     => is_numeric($_POST['_pagesize']) ? max(2, intval($_POST['_pagesize'])) : $CONFIG['pagesize'], 
     35      'index_sort'   => isset($_POST['_index_sort']) ? TRUE : FALSE, 
    3536      'prettydate'   => isset($_POST['_pretty_date']) ? TRUE : FALSE, 
    3637      'skin'         => isset($_POST['_skin']) ? get_input_value('_skin', RCUBE_INPUT_POST) : $CONFIG['skin'], 
Note: See TracChangeset for help on using the changeset viewer.