Changeset 15e00bd in github


Ignore:
Timestamp:
Mar 18, 2010 9:02:18 AM (3 years ago)
Author:
alecpl <alec@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
78fe4d8
Parents:
1845fb6
Message:
  • Improved performance of folders operations (#1486525) + code cleanups
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • CHANGELOG

    rb575fa9 r15e00bd  
    22=========================== 
    33 
     4- Improved performance of folders operations (#1486525) 
    45- Fix blocked.gif attachment is not attached to the message (#1486516) 
    56- Managesieve: import from Horde-INGO 
  • program/include/rcube_imap.php

    r1845fb6 r15e00bd  
    111111      raise_error(array('code' => 403, 'type' => 'imap', 
    112112        'file' => __FILE__, 'line' => __LINE__, 
    113         'message' => "Open SSL not available"), TRUE, FALSE); 
     113        'message' => "Open SSL not available"), true, false); 
    114114      $port = 143; 
    115115    } 
     
    143143      raise_error(array('code' => 403, 'type' => 'imap', 
    144144        'file' => __FILE__, 'line' => __LINE__, 
    145         'message' => $GLOBALS['iil_error']), TRUE, FALSE); 
     145        'message' => $GLOBALS['iil_error']), true, false); 
    146146      } 
    147147 
     
    155155      } 
    156156 
    157     return $this->conn ? TRUE : FALSE; 
     157    return $this->conn ? true : false; 
    158158    } 
    159159 
     
    472472        $a_folders = $data['folders']; 
    473473    } 
    474     else{ 
     474    else { 
    475475        // retrieve list of folders from IMAP server 
    476476        $a_folders = iil_C_ListSubscribed($this->conn, $this->mod_mailbox($root), $filter); 
    477477    } 
    478  
    479478     
    480479    if (!is_array($a_folders) || !sizeof($a_folders)) 
     
    497496   * @access  public 
    498497   */ 
    499   function messagecount($mbox_name='', $mode='ALL', $force=FALSE) 
     498  function messagecount($mbox_name='', $mode='ALL', $force=false) 
    500499    { 
    501500    $mailbox = $mbox_name ? $this->mod_mailbox($mbox_name) : $this->mailbox; 
     
    510509   * @see     rcube_imap::messagecount() 
    511510   */ 
    512   private function _messagecount($mailbox='', $mode='ALL', $force=FALSE) 
     511  private function _messagecount($mailbox='', $mode='ALL', $force=false) 
    513512    { 
    514513    $mode = strtoupper($mode); 
     
    619618   * @see     rcube_imap::list_headers 
    620619   */ 
    621   private function _list_headers($mailbox='', $page=NULL, $sort_field=NULL, $sort_order=NULL, $recursive=FALSE, $slice=0) 
     620  private function _list_headers($mailbox='', $page=NULL, $sort_field=NULL, $sort_order=NULL, $recursive=false, $slice=0) 
    622621    { 
    623622    if (!strlen($mailbox)) 
     
    651650      { 
    652651      $this->sync_header_index($mailbox); 
    653       return $this->_list_headers($mailbox, $page, $this->sort_field, $this->sort_order, TRUE, $slice); 
     652      return $this->_list_headers($mailbox, $page, $this->sort_field, $this->sort_order, true, $slice); 
    654653      } 
    655654 
     
    683682      } 
    684683    // use SORT command 
    685     else if ($this->get_capability('sort')) 
     684    else if ($this->get_capability('SORT')) 
    686685      { 
    687686      if ($msg_index = iil_C_Sort($this->conn, $mailbox, $this->sort_field, $this->skip_deleted ? 'UNDELETED' : '')) { 
     
    742741   * @see     rcube_imap::list_headers 
    743742   */ 
    744   private function _list_thread_headers($mailbox, $page=NULL, $sort_field=NULL, $sort_order=NULL, $recursive=FALSE, $slice=0) 
     743  private function _list_thread_headers($mailbox, $page=NULL, $sort_field=NULL, $sort_order=NULL, $recursive=false, $slice=0) 
    745744    { 
    746745    $this->_set_sort_order($sort_field, $sort_order); 
     
    926925 
    927926    // sorted messages, so we can first slice array and then fetch only wanted headers 
    928     if ($this->get_capability('sort')) // SORT searching result 
     927    if ($this->get_capability('SORT')) // SORT searching result 
    929928      { 
    930929      // reset search set if sorting field has been changed 
     
    11721171      } 
    11731172      // sort with SORT command 
    1174       else if ($this->get_capability('sort')) 
     1173      else if ($this->get_capability('SORT')) 
    11751174      { 
    11761175        if ($this->sort_field && $this->search_sort_field != $this->sort_field) 
     
    12071206    if ($cache_status>0) 
    12081207      { 
    1209       $a_index = $this->get_message_cache_index($cache_key, TRUE, $this->sort_field, $this->sort_order); 
     1208      $a_index = $this->get_message_cache_index($cache_key, true, $this->sort_field, $this->sort_order); 
    12101209      return array_keys($a_index); 
    12111210      } 
     
    12261225      } 
    12271226    // fetch complete message index 
    1228     else if ($this->get_capability('sort')) 
     1227    else if ($this->get_capability('SORT')) 
    12291228      { 
    12301229      if ($a_index = iil_C_Sort($this->conn, $mailbox, $this->sort_field, $this->skip_deleted ? 'UNDELETED' : '')) { 
     
    12831282    if ($cache_status>0) 
    12841283      { 
    1285       $a_index = $this->get_message_cache_index($cache_key, TRUE, $this->sort_field, $this->sort_order); 
     1284      $a_index = $this->get_message_cache_index($cache_key, true, $this->sort_field, $this->sort_order); 
    12861285      return array_keys($a_index); 
    12871286      } 
     
    13531352         
    13541353      // message in cache but in wrong position 
    1355       if (in_array((string)$uid, $cache_index, TRUE)) 
     1354      if (in_array((string)$uid, $cache_index, true)) 
    13561355        { 
    13571356        unset($cache_index[$id]); 
     
    14601459        ); 
    14611460      } 
    1462     else if ($sort_field && $this->get_capability('sort')) { 
     1461    else if ($sort_field && $this->get_capability('SORT')) { 
    14631462      $charset = $charset ? $charset : $this->default_charset; 
    1464       $a_messages = iil_C_Sort($this->conn, $mailbox, $sort_field, $criteria, FALSE, $charset); 
     1463      $a_messages = iil_C_Sort($this->conn, $mailbox, $sort_field, $criteria, false, $charset); 
    14651464 
    14661465      if (!$a_messages) 
     
    15131512    else { // ($sort_field == 'date' && $this->threading != 'REFS') 
    15141513      // use SORT command 
    1515       if ($this->get_capability('sort')) { 
     1514      if ($this->get_capability('SORT')) { 
    15161515        $a_index = iil_C_Sort($this->conn, $mailbox, $this->sort_field, 
    15171516            !empty($ids) ? $ids : ($this->skip_deleted ? 'UNDELETED' : '')); 
     
    16231622   * @return object Message headers representation 
    16241623   */ 
    1625   function get_headers($id, $mbox_name=NULL, $is_uid=TRUE, $bodystr=FALSE) 
     1624  function get_headers($id, $mbox_name=NULL, $is_uid=true, $bodystr=false) 
    16261625    { 
    16271626    $mailbox = $mbox_name ? $this->mod_mailbox($mbox_name) : $this->mailbox; 
     
    21692168 
    21702169    // make sure mailbox exists 
    2171     if (($mailbox == 'INBOX') || in_array($mailbox, $this->_list_mailboxes())) { 
     2170    if ($mailbox == 'INBOX' || $this->mailbox_exists($mbox_name)) { 
    21722171      if ($is_file) { 
    21732172        $separator = rcmail::get_instance()->config->header_delimiter(); 
     
    21842183      $this->_set_messagecount($mailbox, 'ALL', 1); 
    21852184      } 
    2186            
     2185 
    21872186    return $saved; 
    21882187    } 
     
    22052204 
    22062205    // make sure mailbox exists 
    2207     if ($to_mbox != 'INBOX' && !in_array($to_mbox, $this->_list_mailboxes())) 
     2206    if ($to_mbox != 'INBOX' && !$this->mailbox_exists($tbox)) 
    22082207      { 
    22092208      if (in_array($tbox, $this->default_folders)) 
    2210         $this->create_mailbox($tbox, TRUE); 
     2209        $this->create_mailbox($tbox, true); 
    22112210      else 
    2212         return FALSE; 
     2211        return false; 
    22132212      } 
    22142213 
     
    22342233    // really deleted from the source mailbox 
    22352234    if ($moved) { 
    2236       $this->_expunge($from_mbox, FALSE, $a_uids); 
     2235      $this->_expunge($from_mbox, false, $a_uids); 
    22372236      $this->_clear_messagecount($from_mbox); 
    22382237      $this->_clear_messagecount($to_mbox); 
     
    22942293      // send expunge command in order to have the deleted message 
    22952294      // really deleted from the mailbox 
    2296       $this->_expunge($mailbox, FALSE, $a_uids); 
     2295      $this->_expunge($mailbox, false, $a_uids); 
    22972296      $this->_clear_messagecount($mailbox); 
    22982297      unset($this->uid_id_map[$mailbox]); 
     
    23632362   * @return boolean True on success 
    23642363   */ 
    2365   function expunge($mbox_name='', $clear_cache=TRUE) 
     2364  function expunge($mbox_name='', $clear_cache=true) 
    23662365    { 
    23672366    $mailbox = $mbox_name ? $this->mod_mailbox($mbox_name) : $this->mailbox; 
     
    23802379   * @access private 
    23812380   */ 
    2382   private function _expunge($mailbox, $clear_cache=TRUE, $uids=NULL) 
     2381  private function _expunge($mailbox, $clear_cache=true, $uids=NULL) 
    23832382    { 
    23842383    if ($uids && $this->get_capability('UIDPLUS'))  
     
    24452444      return iil_C_GetQuota($this->conn); 
    24462445         
    2447     return FALSE; 
     2446    return false; 
    24482447    } 
    24492448 
     
    24882487   * @param string  Name of the created mailbox, false on error 
    24892488   */ 
    2490   function create_mailbox($name, $subscribe=FALSE) 
    2491     { 
    2492     $result = FALSE; 
     2489  function create_mailbox($name, $subscribe=false) 
     2490    { 
     2491    $result = false; 
    24932492     
    24942493    // reduce mailbox name to 100 chars 
    24952494    $name = substr($name, 0, 100); 
    2496  
    24972495    $abs_name = $this->mod_mailbox($name); 
    2498     $a_mailbox_cache = $this->get_cache('mailboxes'); 
    2499  
    2500     if (strlen($abs_name) && (!is_array($a_mailbox_cache) || !in_array($abs_name, $a_mailbox_cache))) 
    2501       $result = iil_C_CreateFolder($this->conn, $abs_name); 
     2496    $result = iil_C_CreateFolder($this->conn, $abs_name); 
    25022497 
    25032498    // try to subscribe it 
     
    25052500      $this->subscribe($name); 
    25062501 
    2507     return $result ? $name : FALSE; 
     2502    return $result ? $name : false; 
    25082503    } 
    25092504 
     
    25182513  function rename_mailbox($mbox_name, $new_name) 
    25192514    { 
    2520     $result = FALSE; 
     2515    $result = false; 
    25212516 
    25222517    // encode mailbox name and reduce it to 100 chars 
     
    25592554      iil_C_Subscribe($this->conn, $abs_name); 
    25602555 
    2561     return $result ? $name : FALSE; 
     2556    return $result ? $name : false; 
    25622557    } 
    25632558 
     
    25712566  function delete_mailbox($mbox_name) 
    25722567    { 
    2573     $deleted = FALSE; 
     2568    $deleted = false; 
    25742569 
    25752570    if (is_array($mbox_name)) 
     
    25782573      $a_mboxes = explode(',', $mbox_name); 
    25792574 
    2580     $all_mboxes = iil_C_ListMailboxes($this->conn, $this->mod_mailbox($root), '*'); 
    2581  
    25822575    if (is_array($a_mboxes)) 
    25832576      foreach ($a_mboxes as $mbox_name) 
    25842577        { 
    25852578        $mailbox = $this->mod_mailbox($mbox_name); 
     2579        $sub_mboxes = iil_C_ListMailboxes($this->conn, $this->mod_mailbox(''), 
     2580          $mailbox . $this->delimiter . '*'); 
    25862581 
    25872582        // unsubscribe mailbox before deleting 
     
    25912586        $result = iil_C_DeleteFolder($this->conn, $mailbox); 
    25922587        if ($result >= 0) { 
    2593           $deleted = TRUE; 
     2588          $deleted = true; 
    25942589          $this->clear_message_cache($mailbox.'.msg'); 
    25952590          } 
    25962591           
    2597         foreach ($all_mboxes as $c_mbox) 
    2598           { 
    2599           $regex = preg_quote($mailbox . $this->delimiter, '/'); 
    2600           $regex = '/^' . $regex . '/'; 
    2601           if (preg_match($regex, $c_mbox)) 
    2602             { 
    2603             iil_C_UnSubscribe($this->conn, $c_mbox); 
    2604             $result = iil_C_DeleteFolder($this->conn, $c_mbox); 
    2605             if ($result >= 0) { 
    2606               $deleted = TRUE; 
    2607               $this->clear_message_cache($c_mbox.'.msg'); 
    2608               } 
    2609             } 
     2592        foreach ($sub_mboxes as $c_mbox) 
     2593          if ($c_mbox != 'INBOX') { 
     2594          iil_C_UnSubscribe($this->conn, $c_mbox); 
     2595          $result = iil_C_DeleteFolder($this->conn, $c_mbox); 
     2596          if ($result >= 0) { 
     2597            $deleted = true; 
     2598            $this->clear_message_cache($c_mbox.'.msg'); 
     2599            } 
    26102600          } 
    26112601        } 
     
    26242614  function create_default_folders() 
    26252615    { 
    2626     $a_folders = iil_C_ListMailboxes($this->conn, $this->mod_mailbox(''), '*'); 
    2627     $a_subscribed = iil_C_ListSubscribed($this->conn, $this->mod_mailbox(''), '*'); 
    2628      
    26292616    // create default folders if they do not exist 
    26302617    foreach ($this->default_folders as $folder) 
    26312618      { 
    2632       $abs_name = $this->mod_mailbox($folder); 
    2633       if (!in_array($abs_name, $a_folders)) 
    2634         $this->create_mailbox($folder, TRUE); 
    2635       else if (!in_array($abs_name, $a_subscribed)) 
     2619      if (!$this->mailbox_exists($folder)) 
     2620        $this->create_mailbox($folder, true); 
     2621      else if (!$this->mailbox_exists($folder, true)) 
    26362622        $this->subscribe($folder); 
    26372623      } 
     2624    } 
     2625 
     2626 
     2627  /** 
     2628   * Checks if folder exists and is subscribed 
     2629   * 
     2630   * @param string   Folder name 
     2631   * @param boolean  Enable subscription checking 
     2632   * @return boolean TRUE or FALSE 
     2633   */ 
     2634  function mailbox_exists($mbox_name, $subscription=false) 
     2635    { 
     2636    if ($mbox_name) { 
     2637      if ($mbox_name == 'INBOX') 
     2638        return true; 
     2639 
     2640      $mbox = $this->mod_mailbox($mbox_name); 
     2641       
     2642      if ($subscription) { 
     2643        if ($a_folders = iil_C_ListSubscribed($this->conn, $this->mod_mailbox(''), $mbox)) 
     2644          return true; 
     2645        } 
     2646      else { 
     2647        $a_folders = iil_C_ListMailboxes($this->conn, $this->mod_mailbox(''), $mbox); 
     2648         
     2649        if (is_array($a_folders) && in_array($mbox, $a_folders)) 
     2650          return true; 
     2651        } 
     2652      } 
     2653 
     2654    return false; 
    26382655    } 
    26392656 
     
    26502667    { 
    26512668    if ($set && is_object($this->db)) 
    2652       $this->caching_enabled = TRUE; 
     2669      $this->caching_enabled = true; 
    26532670    else 
    2654       $this->caching_enabled = FALSE; 
     2671      $this->caching_enabled = false; 
    26552672    } 
    26562673 
     
    26752692    { 
    26762693    $this->cache[$key] = $data; 
    2677     $this->cache_changed = TRUE; 
    2678     $this->cache_changes[$key] = TRUE; 
     2694    $this->cache_changed = true; 
     2695    $this->cache_changes[$key] = true; 
    26792696    } 
    26802697 
     
    27082725 
    27092726      $this->cache = array(); 
    2710       $this->cache_changed = FALSE; 
     2727      $this->cache_changed = false; 
    27112728      $this->cache_changes = array(); 
    27122729      } 
     
    27142731      { 
    27152732      $this->_clear_cache_record($key); 
    2716       $this->cache_changes[$key] = FALSE; 
     2733      $this->cache_changes[$key] = false; 
    27172734      unset($this->cache[$key]); 
    27182735      } 
     
    27392756        $this->cache_keys[$sql_key] = $sql_arr['cache_id']; 
    27402757        if (!isset($this->cache[$sql_key])) 
    2741           $this->cache[$sql_key] = $sql_arr['data'] ? unserialize($sql_arr['data']) : FALSE; 
     2758          $this->cache[$sql_key] = $sql_arr['data'] ? unserialize($sql_arr['data']) : false; 
    27422759        } 
    27432760      } 
     
    27522769    { 
    27532770    if (!$this->db) 
    2754       return FALSE; 
     2771      return false; 
    27552772 
    27562773    // update existing cache record 
     
    29472964   * @access private 
    29482965   */   
    2949   private function get_message_cache_index($key, $force=FALSE, $sort_field='idx', $sort_order='ASC') 
     2966  private function get_message_cache_index($key, $force=false, $sort_field='idx', $sort_order='ASC') 
    29502967    { 
    29512968    static $sa_message_index = array(); 
     
    30323049        $index, 
    30333050        $headers->uid, 
    3034         (string)mb_substr($this->db->encode($this->decode_header($headers->subject, TRUE)), 0, 128), 
    3035         (string)mb_substr($this->db->encode($this->decode_header($headers->from, TRUE)), 0, 128), 
    3036         (string)mb_substr($this->db->encode($this->decode_header($headers->to, TRUE)), 0, 128), 
    3037         (string)mb_substr($this->db->encode($this->decode_header($headers->cc, TRUE)), 0, 128), 
     3051        (string)mb_substr($this->db->encode($this->decode_header($headers->subject, true)), 0, 128), 
     3052        (string)mb_substr($this->db->encode($this->decode_header($headers->from, true)), 0, 128), 
     3053        (string)mb_substr($this->db->encode($this->decode_header($headers->to, true)), 0, 128), 
     3054        (string)mb_substr($this->db->encode($this->decode_header($headers->cc, true)), 0, 128), 
    30383055        (int)$headers->size, 
    30393056        serialize($this->db->encode(clone $headers)), 
     
    31943211   * @return string Decoded string 
    31953212   */ 
    3196   function decode_header($input, $remove_quotes=FALSE) 
     3213  function decode_header($input, $remove_quotes=false) 
    31973214    { 
    31983215    $str = rcube_imap::decode_mime_string((string)$input, $this->default_charset); 
     
    35053522  private function _change_subscription($a_mboxes, $mode) 
    35063523    { 
    3507     $updated = FALSE; 
     3524    $updated = false; 
    35083525 
    35093526    if (is_array($a_mboxes)) 
     
    35463563  private function _set_messagecount($mbox_name, $mode, $increment) 
    35473564    { 
    3548     $a_mailbox_cache = FALSE; 
     3565    $a_mailbox_cache = false; 
    35493566    $mailbox = $mbox_name ? $mbox_name : $this->mailbox; 
    35503567    $mode = strtoupper($mode); 
     
    35533570     
    35543571    if (!is_array($a_mailbox_cache[$mailbox]) || !isset($a_mailbox_cache[$mailbox][$mode]) || !is_numeric($increment)) 
    3555       return FALSE; 
     3572      return false; 
    35563573     
    35573574    // add incremental value to messagecount 
     
    35653582    $this->update_cache('messagecount', $a_mailbox_cache); 
    35663583     
    3567     return TRUE; 
     3584    return true; 
    35683585    } 
    35693586 
     
    35753592  private function _clear_messagecount($mbox_name='') 
    35763593    { 
    3577     $a_mailbox_cache = FALSE; 
     3594    $a_mailbox_cache = false; 
    35783595    $mailbox = $mbox_name ? $mbox_name : $this->mailbox; 
    35793596 
  • program/lib/imap.inc

    r1845fb6 r15e00bd  
    17491749 
    17501750function iil_C_ListMailboxes(&$conn, $ref, $mailbox) { 
    1751         global $IGNORE_FOLDERS; 
    1752          
    1753         $ignore = $IGNORE_FOLDERS[strtolower($conn->host)]; 
    17541751                 
    17551752        $fp = $conn->fp; 
     
    17801777                        $a = iil_ExplodeQuotedString(' ', $line); 
    17811778                        // last string is folder name 
    1782                         $folder = preg_replace(array('/^"/', '/"$/'), '', iil_UnEscape($a[count($a)-1])); 
    1783              
    1784                         if (empty($ignore) || (!empty($ignore) 
    1785                                 && !preg_match('/'.preg_quote(ignore, '/').'/i', $folder))) { 
    1786                                 $folders[$i] = $folder; 
    1787                         } 
     1779                        $folders[$i] = preg_replace(array('/^"/', '/"$/'), '', iil_UnEscape($a[count($a)-1])); 
    17881780             
    17891781                        // second from last is delimiter 
     
    18131805 
    18141806function iil_C_ListSubscribed(&$conn, $ref, $mailbox) { 
    1815         global $IGNORE_FOLDERS; 
    1816          
    1817         $ignore = $IGNORE_FOLDERS[strtolower($conn->host)]; 
    18181807         
    18191808        $fp = $conn->fp; 
     
    18471836                        // last string is folder name 
    18481837                        $folder = preg_replace(array('/^"/', '/"$/'), '', iil_UnEscape($a[count($a)-1])); 
    1849          
    1850                         if ((!in_array($folder, $folders)) && (empty($ignore) 
    1851                                 || (!empty($ignore) && !preg_match('/'.preg_quote(ignore, '/').'/i', $folder)))) { 
     1838 
     1839                        // @TODO: do we need this check??? 
     1840                        if (!in_array($folder, $folders)) { 
    18521841                            $folders[$i] = $folder; 
    18531842                        } 
  • program/steps/mail/func.inc

    rf52c936f r15e00bd  
    4343  $OUTPUT->send('login'); 
    4444} 
    45  
    4645 
    4746// set imap properties and session vars 
Note: See TracChangeset for help on using the changeset viewer.