Index: Tree.php
===================================================================
RCS file: /usr/src/CVSROOT-webmaster/horde-3.2/imp/lib/IMAP/Tree.php,v
retrieving revision 1.1.1.1
diff -r1.1.1.1 Tree.php
6a7
>  * $Horde: imp/lib/IMAP/Tree.php,v 1.185 2008/05/07 13:11:54 jan Exp $
502,533c503,530
<         foreach ($this->_namespaces as $key => $val) {
<             /* We only need to provide the list of folders in the base
<              * personal namespace.  Else, just use the base namespace entry. */
<             if (($val['type'] == 'personal') || empty($val['name'])) {
<                 $query = $val['name'] . '%';
<             } else {
<                 $query = (empty($val['delimiter'])) ? $val['name'] : rtrim($val['name'], $val['delimiter']);
<                 if (isset($this->_tree[$query])) {
<                     continue;
<                 }
<             }
<             $tmp = $this->_getList($query);
<             if (!empty($tmp)) {
<                 if ($val['type'] == 'personal') {
<                     /* IMAP servers put the INBOX in the personal namespace -
<                      * simply rename to 'INBOX' since that is where we
<                      * always access the mailbox. */
<                     $inbox_str = $val['name'] . 'INBOX';
<                     if (!empty($val['name']) && isset($tmp[$inbox_str])) {
<                         $tmp = array('INBOX' => $tmp[$inbox_str]) + $tmp;
<                         $tmp['INBOX']->name = 'INBOX';
<                         unset($tmp[$inbox_str]);
<                     }
<                 } elseif ($tv) {
<                     $name = ($val['type'] == 'other') ? IMPTREE_OTHER_KEY : IMPTREE_SHARED_KEY;
<                     if (!isset($this->_tree[$name])) {
<                         $ob = new stdClass;
<                         $ob->attributes = LATT_NOSELECT | IMPTREE_ELT_NAMESPACE | IMPTREE_ELT_IS_DISCOVERED | IMPTREE_ELT_IS_SUBSCRIBED | IMPTREE_ELT_NONIMAP | IMPTREE_ELT_NOSHOW;
<                         $ob->fullServerPath = $ob->name = $name;
<                         $elt = $this->_makeElt($ob);
<                         $elt['l'] = ($val['type'] == 'other') ? IMPTREE_OTHER_LABEL : IMPTREE_SHARED_LABEL;
<                         $this->_insertElt($elt);
---
>         if($GLOBALS['conf']['imap']['tree_build'] == 'quick'){
>             $boxes = $this->_getList("*");
>             // fake folders in the namespaces don't show up with a * search like they would with a $namespace/% search
>             $fake_folder_attributes = LATT_NOSELECT | LATT_HASCHILDREN; 
>             /* Non-folders with children aren't explicitly returned by _getList("*") */
>             foreach($boxes as $name=>$box){
>                 $pos = strpos($name, '/');
>                 $topfolder = substr($name,0,$pos);
>                 if(!isset($boxes[$topfolder])){
>                     $tmp[$topfolder] = (object)array('name'=>$topfolder,'attributes'=>$fake_folder_attributes,'delimiter'=>$this->_delimiter);
>                     $boxes = array_merge($boxes, $tmp);
>                 }
>             }
>             /*
>             if($tv){
>                 $this->createTreeView();
>             }*/
>             $this->_fullBoxList = $boxes;
>         } else {
>             foreach ($this->_namespaces as $key => $val) {
>                 /* We only need to provide the list of folders in the base
>                  * personal namespace.  Else, just use the base namespace entry. */
>                 if (($val['type'] == 'personal') || empty($val['name'])) {
>                     $query = $val['name'] . '%';
>                 } else {
>                     $query = (empty($val['delimiter'])) ? $val['name'] : rtrim($val['name'], $val['delimiter']);
>                     if (isset($this->_tree[$query])) {
>                         continue;
535,540c532,543
< 
<                     foreach ($this->_namespaces as $val2) {
<                         if (($val2['type'] == $val['type']) &&
<                             ($val2['name'] != $val['name'])) {
<                             $this->_tree[$name] &= ~IMPTREE_ELT_NOSHOW;
<                             break;
---
>                 }
>                 $tmp = $this->_getList($query);
>                 if (!empty($tmp)) {
>                     if ($val['type'] == 'personal') {
>                         /* IMAP servers put the INBOX in the personal namespace -
>                          * simply rename to 'INBOX' since that is where we
>                          * always access the mailbox. */
>                         $inbox_str = $val['name'] . 'INBOX';
>                         if (!empty($val['name']) && isset($tmp[$inbox_str])) {
>                             $tmp = array('INBOX' => $tmp[$inbox_str]) + $tmp;
>                             $tmp['INBOX']->name = 'INBOX';
>                             unset($tmp[$inbox_str]);
542c545,546
<                     }
---
>                     } 
>                     $boxes = array_merge($boxes, $tmp);
544d547
<                 $boxes = array_merge($boxes, $tmp);
547a551,553
>         if($tv){
>             $this->separateNonPersonalBoxes();
>         }
566a573,600
>      * Separate the non-personal mailboxes out from the main namespace
>      * and into folders called either IMPTREE_OTHER_KEY or IMPTREE_SHARED_KEY
>      */
>     function separateNonPersonalBoxes(){ 
>             foreach ($this->_namespaces as $key => $val) {
>                 if ($val['type'] != 'personal') {
>                     $name = ($val['type'] == 'other') ? IMPTREE_OTHER_KEY : IMPTREE_SHARED_KEY;
>                     if (!isset($this->_tree[$name])) {
>                         $ob = new stdClass;
>                         $ob->attributes = LATT_NOSELECT | IMPTREE_ELT_NAMESPACE | IMPTREE_ELT_IS_DISCOVERED | IMPTREE_ELT_IS_SUBSCRIBED | IMPTREE_ELT_NONIMAP | IMPTREE_ELT_NOSHOW;
>                         $ob->fullServerPath = $ob->name = $name;
>                         $elt = $this->_makeElt($ob);
>                         $elt['l'] = ($val['type'] == 'other') ? IMPTREE_OTHER_LABEL : IMPTREE_SHARED_LABEL;
>                         $this->_insertElt($elt);
>                     }
> 
>                     foreach ($this->_namespaces as $val2) {
>                         if (($val2['type'] == $val['type']) &&
>                             ($val2['name'] != $val['name'])) {
>                                 $this->_tree[$name] &= ~IMPTREE_ELT_NOSHOW;
>                                 break;
>                             }
>                     }
>                 }
>             }
>     }
> 
>     /**
1114c1148,1151
<                 $this->expand($elt['v']);
---
>                 /* the "quick" build pulls the full hierarchy in using one query*/
>                 if($GLOBALS['conf']['imap']['tree_build'] != 'quick'){
>                     $this->expand($elt['v']);
>                 }
1652,1655c1689,1693
<             foreach ($this->_namespaces as $val) {
<                 $tmp = call_user_func($imap_cmd, $imp_imap->stream(), $this->_server, $val['name'] . '*');
<                 if (!empty($tmp)) {
<                     $sublist = array_merge($sublist, $tmp);
---
>             if($GLOBALS['conf']['imap']['tree_build'] == 'quick' && !$GLOBALS['prefs']->getValue('subscribe')){
>                 /* Loop through the just recently obtained list of mailboxes */
>                 foreach($this->_fullBoxList as $name=>$box){
>                     /* Add each box to the subscribed list*/
>                     $this->_subscribed[$name] = 1;
1657,1661c1695,1705
<             }
< 
<             if (!empty($sublist)) {
<                 foreach ($sublist as $val) {
<                     $this->_subscribed[substr($val, strpos($val, '}') + 1)] = 1;
---
>             } else {
>                 foreach ($this->_namespaces as $val) {
>                     $tmp = call_user_func($imap_cmd, $imp_imap->stream(), $this->_server, $val['name'] . '*');
>                     if (!empty($tmp)) {
>                         $sublist = array_merge($sublist, $tmp);
>                     }
>                 }
>                 if (!empty($sublist)) {
>                     foreach ($sublist as $val) {
>                         $this->_subscribed[substr($val, strpos($val, '}') + 1)] = 1;
>                     }
1689,1693c1733,1747
<             /* Get list of all mailboxes. */
<             foreach ($this->_namespaces as $val) {
<                 $tmp = @imap_list($imp_imap->stream(), $this->_server, $val['name'] . '*');
<                 if (!empty($tmp)) {
<                     $all_list = array_merge($all_list, $tmp);
---
>             if($GLOBALS['conf']['imap']['tree_build'] == 'quick'){
>                 /* Loop through the just recently obtained list of mailboxes */
>                 foreach($this->_fullBoxList as $name=>$box){
>                     /* Add the boxes that aren't in _subscribed to _unsubscribed */
>                     if (!isset($this->_subscribed[$name])) {
>                         $this->_unsubscribed[$name] = 1;
>                     }
>                 }
>             } else {
>                 /* Get list of all mailboxes. */
>                 foreach ($this->_namespaces as $val) {
>                     $tmp = @imap_list($imp_imap->stream(), $this->_server, $val['name'] . '*');
>                     if (!empty($tmp)) {
>                         $all_list = array_merge($all_list, $tmp);
>                     }
