Changeset 5398 in subversion


Ignore:
Timestamp:
Nov 8, 2011 6:22:14 AM (19 months ago)
Author:
alec
Message:
  • Fix so folders with \Noinferiors attribute aren't listed in parent selector
  • Add LIST result and folder attributes cache
  • rcmail_render_folder_tree_select(): fix 'exceptions' parameter, add 'skip_noinferiors' option
Location:
trunk/roundcubemail
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/CHANGELOG

    r5394 r5398  
    22=========================== 
    33 
     4- Fix so folders with \Noinferiors attribute aren't listed in parent selector 
    45- Fix handling of curly brackets in URLs (#1488168) 
    56- Fix handling of dates (birthday/anniversary) in contact data (#1488147) 
  • trunk/roundcubemail/program/include/main.inc

    r5390 r5398  
    12331233    $select->add($p['noselection'], ''); 
    12341234 
    1235   rcmail_render_folder_tree_select($a_mailboxes, $mbox, $p['maxlength'], $select, $p['realnames'], 0, $p['exceptions']); 
     1235  rcmail_render_folder_tree_select($a_mailboxes, $mbox, $p['maxlength'], $select, $p['realnames'], 0, $p); 
    12361236 
    12371237  return $select; 
     
    12821282 
    12831283  if (!isset($arrFolders[$currentFolder])) { 
    1284     // Check \Noselect option (if options are in cache) 
    1285     if (!$virtual && ($opts = $RCMAIL->imap->mailbox_options($path))) { 
    1286       $virtual = in_array('\\Noselect', $opts); 
     1284    // Check \Noselect attribute (if attributes are in cache) 
     1285    if (!$virtual && ($attrs = $RCMAIL->imap->mailbox_attributes($path))) { 
     1286      $virtual = in_array('\\Noselect', $attrs); 
    12871287    } 
    12881288 
     
    14031403 * @return string 
    14041404 */ 
    1405 function rcmail_render_folder_tree_select(&$arrFolders, &$mbox_name, $maxlength, &$select, $realnames=false, $nestLevel=0, $exceptions=array()) 
    1406 { 
     1405function rcmail_render_folder_tree_select(&$arrFolders, &$mbox_name, $maxlength, &$select, $realnames=false, $nestLevel=0, $opts=array()) 
     1406{ 
     1407  global $RCMAIL; 
     1408 
    14071409  $out = ''; 
    14081410 
    14091411  foreach ($arrFolders as $key => $folder) { 
    1410     if (empty($exceptions) || !in_array($folder['id'], $exceptions)) { 
    1411       if (!$realnames && ($folder_class = rcmail_folder_classname($folder['id']))) 
    1412         $foldername = rcube_label($folder_class); 
    1413       else { 
    1414         $foldername = $folder['name']; 
    1415  
    1416         // shorten the folder name to a given length 
    1417         if ($maxlength && $maxlength>1) 
    1418           $foldername = abbreviate_string($foldername, $maxlength); 
    1419       } 
    1420  
    1421       $select->add(str_repeat(' ', $nestLevel*4) . $foldername, $folder['id']); 
    1422     } 
    1423     else if ($nestLevel) 
     1412    // skip exceptions (and its subfolders) 
     1413    if (!empty($opts['exceptions']) && in_array($folder['id'], $opts['exceptions'])) { 
    14241414      continue; 
     1415    } 
     1416 
     1417    // skip folders in which it isn't possible to create subfolders 
     1418    if (!empty($opts['skip_noinferiors']) && ($attrs = $RCMAIL->imap->mailbox_attributes($folder['id'])) 
     1419        && in_array('\\Noinferiors', $attrs) 
     1420    ) { 
     1421      continue; 
     1422    } 
     1423 
     1424    if (!$realnames && ($folder_class = rcmail_folder_classname($folder['id']))) 
     1425      $foldername = rcube_label($folder_class); 
     1426    else { 
     1427      $foldername = $folder['name']; 
     1428 
     1429      // shorten the folder name to a given length 
     1430      if ($maxlength && $maxlength>1) 
     1431        $foldername = abbreviate_string($foldername, $maxlength); 
     1432    } 
     1433 
     1434    $select->add(str_repeat(' ', $nestLevel*4) . $foldername, $folder['id']); 
    14251435 
    14261436    if (!empty($folder['folders'])) 
    14271437      $out .= rcmail_render_folder_tree_select($folder['folders'], $mbox_name, $maxlength, 
    1428         $select, $realnames, $nestLevel+1, $exceptions); 
     1438        $select, $realnames, $nestLevel+1, $opts); 
    14291439  } 
    14301440 
  • trunk/roundcubemail/program/include/rcube_imap.php

    r5397 r5398  
    30883088    function list_unsubscribed($root='', $name='*', $filter=null, $rights=null, $skip_sort=false) 
    30893089    { 
    3090         // @TODO: caching 
     3090        $cache_key = $root.':'.$name; 
     3091        if (!empty($filter)) { 
     3092            $cache_key .= ':'.(is_string($filter) ? $filter : serialize($filter)); 
     3093        } 
     3094        $cache_key .= ':'.$rights; 
     3095        $cache_key = 'mailboxes.list.'.md5($cache_key); 
     3096 
     3097        // get cached folder list 
     3098        $a_mboxes = $this->get_cache($cache_key); 
     3099        if (is_array($a_mboxes)) { 
     3100            return $a_mboxes; 
     3101        } 
     3102 
    30913103        // Give plugins a chance to provide a list of mailboxes 
    30923104        $data = rcmail::get_instance()->plugins->exec_hook('mailboxes_list', 
     
    31103122        } 
    31113123 
     3124        // cache folder attributes 
     3125        if ($root == '' && $name == '*' && empty($filter)) { 
     3126            $this->update_cache('mailboxes.attributes', $this->conn->data['LIST']); 
     3127        } 
     3128 
    31123129        // filter folders list according to rights requirements 
    31133130        if ($rights && $this->get_capability('ACL')) { 
     
    31193136            $a_mboxes = $this->_sort_mailbox_list($a_mboxes); 
    31203137        } 
     3138 
     3139        // write mailboxlist to cache 
     3140        $this->update_cache($cache_key, $a_mboxes); 
    31213141 
    31223142        return $a_mboxes; 
     
    34513471 
    34523472    /** 
    3453      * Gets folder options from LIST response, e.g. \Noselect, \Noinferiors 
     3473     * Gets folder attributes from LIST response, e.g. \Noselect, \Noinferiors 
    34543474     * 
    34553475     * @param string $mailbox Folder name 
    3456      * @param bool   $force   Set to True if options should be refreshed 
    3457      *                        Options are available after LIST command only 
     3476     * @param bool   $force   Set to True if attributes should be refreshed 
    34583477     * 
    34593478     * @return array Options list 
    34603479     */ 
    3461     function mailbox_options($mailbox, $force=false) 
    3462     { 
    3463         if ($mailbox == 'INBOX') { 
    3464             return array(); 
    3465         } 
    3466  
    3467         if (!is_array($this->conn->data['LIST']) || !is_array($this->conn->data['LIST'][$mailbox])) { 
    3468             if ($force) { 
    3469                 $this->conn->listMailboxes('', $mailbox); 
    3470             } 
    3471             else { 
    3472                 return array(); 
    3473             } 
    3474         } 
    3475  
    3476         $opts = $this->conn->data['LIST'][$mailbox]; 
     3480    function mailbox_attributes($mailbox, $force=false) 
     3481    { 
     3482        // get attributes directly from LIST command 
     3483        if (!empty($this->conn->data['LIST']) && is_array($this->conn->data['LIST'][$mailbox])) { 
     3484            $opts = $this->conn->data['LIST'][$mailbox]; 
     3485        } 
     3486        // get cached folder attributes 
     3487        else if (!$force) { 
     3488            $opts = $this->get_cache('mailboxes.attributes'); 
     3489            $opts = $opts[$mailbox]; 
     3490        } 
     3491 
     3492        if (!is_array($opts)) { 
     3493            $this->conn->listMailboxes('', $mailbox); 
     3494            $opts = $this->conn->data['LIST'][$mailbox]; 
     3495        } 
    34773496 
    34783497        return is_array($opts) ? $opts : array(); 
     
    35573576        } 
    35583577 
    3559         $options['name']      = $mailbox; 
    3560         $options['options']   = $this->mailbox_options($mailbox, true); 
    3561         $options['namespace'] = $this->mailbox_namespace($mailbox); 
    3562         $options['rights']    = $acl && !$options['is_root'] ? (array)$this->my_rights($mailbox) : array(); 
    3563         $options['special']   = in_array($mailbox, $this->default_folders); 
     3578        $options['name']       = $mailbox; 
     3579        $options['attributes'] = $this->mailbox_attributes($mailbox, true); 
     3580        $options['namespace']  = $this->mailbox_namespace($mailbox); 
     3581        $options['rights']     = $acl && !$options['is_root'] ? (array)$this->my_rights($mailbox) : array(); 
     3582        $options['special']    = in_array($mailbox, $this->default_folders); 
    35643583 
    35653584        // Set 'noselect' and 'norename' flags 
    3566         if (is_array($options['options'])) { 
    3567             foreach ($options['options'] as $opt) { 
    3568                 $opt = strtolower($opt); 
    3569                 if ($opt == '\noselect' || $opt == '\nonexistent') { 
     3585        if (is_array($options['attributes'])) { 
     3586            foreach ($options['attributes'] as $attrib) { 
     3587                $attrib = strtolower($attrib); 
     3588                if ($attrib == '\noselect' || $attrib == '\nonexistent') { 
    35703589                    $options['noselect'] = true; 
    35713590                } 
  • trunk/roundcubemail/program/include/rcube_imap_generic.php

    r5365 r5398  
    22592259 
    22602260                    // Add to options array 
    2261                     if (!empty($opts)) { 
    2262                         if (empty($this->data['LIST'][$mailbox])) 
    2263                             $this->data['LIST'][$mailbox] = $opts; 
    2264                         else 
    2265                             $this->data['LIST'][$mailbox] = array_unique(array_merge( 
    2266                                 $this->data['LIST'][$mailbox], $opts)); 
    2267                     } 
     2261                    if (empty($this->data['LIST'][$mailbox])) 
     2262                        $this->data['LIST'][$mailbox] = $opts; 
     2263                    else if (!empty($opts)) 
     2264                        $this->data['LIST'][$mailbox] = array_unique(array_merge( 
     2265                            $this->data['LIST'][$mailbox], $opts)); 
    22682266                } 
    22692267                // * STATUS <mailbox> (<result>) 
  • trunk/roundcubemail/program/steps/settings/edit_folder.inc

    r5306 r5398  
    120120            'maxlength'   => 150, 
    121121            'unsubscribed' => true, 
    122             'exceptions' => array($mbox_imap), 
     122            'skip_noinferiors' => true, 
     123            'exceptions'  => array($mbox_imap), 
    123124        )); 
    124125 
  • trunk/roundcubemail/program/steps/settings/folders.inc

    r5309 r5398  
    284284 
    285285        if (!$protected) { 
    286             $opts = $IMAP->mailbox_options($folder['id']); 
    287             $noselect = in_array('\\Noselect', $opts); 
     286            $attrs = $IMAP->mailbox_attributes($folder['id']); 
     287            $noselect = in_array('\\Noselect', $attrs); 
    288288        } 
    289289 
Note: See TracChangeset for help on using the changeset viewer.