[dev] imp folder prefix

Egan egan@sevenkings.net
Tue, 29 May 2001 09:52:00 -0400


On Mon, 28 May 2001 19:44:00 -0400, Egan <egan@sevenkings.net> wrote:

>When you have a prefix, it seems to work, except when collapsing all
>folders.  Then you are left with nothing but the INBOX.  Looks like
>some other section of code will need patching to handle that.

OK, I fixed that.

I also cleaned up the previous patch.  Please ignore it, and review
this one instead.  Everything works that I could think of to test, at
least in regard to the folder prefix changes.

I had to patch the pickle code in Tree.php because the folder prefix
was not being saved in the session.  That caused display problems
because the prefix was missing in the case of restoring the tree from
the session data.  While I was there, I changed the pickling order to
match the order of the fields defined in class IMP_tree.  $offset is
not initialized to any value in the class definition, so I was not
sure if it should be pickled too.  But I did, just to be consistent.

I did notice some bugs that were present without my patch:

When you expand the folder view, and then refresh, the view collapses.
This seems to be a bug, because it does not happen when you expand the
view, then go to a folder, and then go again the folder view.  In that
case, it maintains whatever you had already expanded the view to.

Also, at least three times while testing, I got dumped back to the
login screen.  I tried to reproduce the problem by following similar
steps which led to it, but I could not.  I'm not completely sure, but
it seems like the problem happened sometime after using the browser
back button to go back to the folder view from some other screen, and
getting the page expired browser message.

I updated horde/imp CVS yesterday, and I'm using PHP 4.0.5.  Maybe
this is a PHP bug, I don't know.  I do know that if I turn on output
buffering, PHP crashes consistently.

BTW, it seems like the page expired message does not happen when going
back to the message list from some other screen; it only happens when
going back to the folder view.  Is this something that needs fixing
with the folder view?

Here is my new folder prefix patch ...

Egan


--- horde/imp/templates/folders/row.inc	Mon May 28 17:57:53 2001
+++ horde/imp/templates/folders/row.inc	Mon May 28 17:55:46 2001
@@ -1,7 +1,7 @@
 <tr class="<?= $navclass ?>">
  <td class="<?= $navclass ?>">
   <input class="<?= $navclass ?>" type="checkbox" name="folder_list[]" value="<?= str_replace('"', '\"', $mailbox['value']) ?>" /> 
-  <?php Horde::pimg('/folders/spacer.gif', 'height="1" width="' . $mailbox['level'] * 18 . '"') ?>
+  <?php Horde::pimg('/folders/spacer.gif', 'height="1" width="' . $indent_level * 18 . '"') ?>
  <?= $dir . '&nbsp;&nbsp;' . $name ?>
  </td>
  <td align="center"><?= $msgs ?></td>
--- horde/imp/folders.php	Tue May 29 07:23:08 2001
+++ horde/imp/folders.php	Tue May 29 07:26:55 2001
@@ -340,9 +340,22 @@
     } else {
         $navclass = ($rowct = !$rowct) ? 'list' : 'listlt';
     }
-
-    include $conf['paths']['templates'] . '/folders/row.inc';
-    $i++;
+    
+    $indent_level = $mailbox['level'];
+    if ($imaptree->prefix != '' && $mailbox['value'] != 'INBOX') {
+        // We have a folder prefix, shift each folder in the
+        // hierarchy up one level before showing it to the user
+        $indent_level--;
+    }
+    if ($indent_level < 0) {
+        // This is a folder prefix; hide it from the user,
+        // and revert rowct, since we hide the folder prefix
+        $rowct = !$rowct;
+    } else {
+        // Display the folder    
+        include $conf['paths']['templates'] . '/folders/row.inc';
+        $i++;
+    }    
     
     if ($imaptree->isOpen($mailbox)) {
         $mailbox = $imaptree->next();
--- horde/imp/lib/Tree.php	Tue May 29 07:23:09 2001
+++ horde/imp/lib/Tree.php	Tue May 29 07:32:32 2001
@@ -134,7 +134,10 @@
         
         $mailbox = $this->head();
         while (isset($mailbox) && is_array($mailbox)) {
-            if ($this->hasChildren($mailbox)) {
+            if ($this->prefix != '' && $mailbox['level'] == 0) {
+            // We have a folder prefix, don't collapse the first level
+            }
+            else if ($this->hasChildren($mailbox)) {
                 $this->collapse($this->server . $mailbox['value']);
             }
             $mailbox = $this->next();
@@ -312,22 +315,26 @@
     function pickle () {
         $pickle = array();
         $pickle['tree'] = base64_encode(serialize($this->tree));
-        $pickle['first'] = $this->first;
         $pickle['cur'] = $this->cur;
+        $pickle['first'] = $this->first;
         $pickle['delimiter'] = $this->delimiter;
-        $pickle['server'] = $this->server;
         $pickle['listcmd'] = $this->listcmd;
+        $pickle['prefix'] = $this->prefix;
+        $pickle['offset'] = $this->offset;
+        $pickle['server'] = $this->server;
         return $pickle;
     } // pickle()
     
     // rebuild oneself from a serialized string
     function unpickle ($pickle) {
         $this->tree = unserialize(base64_decode($pickle['tree']));
-        $this->first = $pickle['first'];
         $this->cur = $pickle['cur'];
+        $this->first = $pickle['first'];
         $this->delimiter = $pickle['delimiter'];
-        $this->server = $pickle['server'];
         $this->listcmd = $pickle['listcmd'];
+        $this->prefix = $pickle['prefix'];
+        $this->offset = $pickle['offset'];
+        $this->server = $pickle['server'];
     }