[dev] IMP/lib/Folder.php

Chris chris at jeks.net
Mon Jan 6 21:25:38 PST 2003


Found a couple of bugs in IMP's flist function.

The first is a missing check to see if a parent folder has already been
seen as a regular folder.

ie

sub.folder1
sub.folder1.sub

The current function adds sub.folder1 as a selectable folder, then considers
sub.folder1.sub

It adds sub.folder1 as a parent without checking that sub.folder1 is already 
in the list.

I think maybe that the line !array_key_exists($prefix . $namespace . $parent, $list)
was meant to do this, but the stuff with prefix is not what is in the array keys.

Example patch to fix:

RCS file: /repository/imp/lib/Folder.php,v
retrieving revision 1.88
diff -c -r1.88 Folder.php
*** lib/Folder.php      7 Jan 2003 04:52:49 -0000       1.88
--- lib/Folder.php      7 Jan 2003 05:10:21 -0000
***************
*** 195,200 ****
--- 195,201 ----
                          $parent = implode($delimiter, $parts);
                          if (!empty($parent) && ($parent != 'INBOX') &&
                              !array_key_exists($prefix . $namespace . $parent, $list) &&
+                             !array_key_exists($parent, $list) &&
                              !array_key_exists($parent, $parents)) {
                              $parents[$parent] = 1;
                              $plabel = str_repeat(' ', 4 * (count($parts) - 1)) . imap_utf7_decode($parts[count($parts) - 1]) . $delimiter;

==========================================

Ok, onto the second problem which may be more contraversial:

If you have:

sub1.folder1
sub1.folder2
sub2.sub3.folder1

You get:

sub1
  folder1
  folder2
    sub3
      folder1

Instead of:

sub1
  folder1
  folder2
sub2
  sub3
    folder1

Essentially, instead of just checking one folder up, you need to loop up
the folders checking them all.

e.g.

while (there_are_parts) {
  checkparent;
  array_pop(parts);
}

Attached is a patch to imp/lib/Folder.php that does both these fixes.

This is my first patch in a while. Someone who knows the folder code should check 
that this is sane. I work with courier. It should be tested on another IMAP server too.

-- 
~ ~ ~
Chris Hyde

In the beginning the Universe was created. This has made a lot of
people very angry and been widely regarded as a bad move... HHG

~ ~ ~
-------------- next part --------------
Index: lib/Folder.php
===================================================================
RCS file: /repository/imp/lib/Folder.php,v
retrieving revision 1.87
diff -c -r1.87 Folder.php
*** lib/Folder.php	3 Jan 2003 02:15:27 -0000	1.87
--- lib/Folder.php	7 Jan 2003 05:07:30 -0000
***************
*** 192,210 ****
                          }
                          $parts = explode($delimiter, $label);
                          $subfolder = array_pop($parts);
!                         $parent = implode($delimiter, $parts);
!                         if (!empty($parent) && ($parent != 'INBOX') &&
!                             !array_key_exists($prefix . $namespace . $parent, $list) &&
!                             !array_key_exists($parent, $parents)) {
!                             $parents[$parent] = 1;
!                             $plabel = str_repeat(' ', 4 * (count($parts) - 1)) . imap_utf7_decode($parts[count($parts) - 1]) . $delimiter;
!                             if (strlen($plabel) > 26) {
!                                 $pabbrev = substr($plabel, 0, 10) . '...' . substr($plabel, -13, 13);
!                             } else {
!                                 $pabbrev = $plabel;
!                             }
!                             $list[$parent] = array('val' => '', 'label' => $plabel, 'abbrev' => $pabbrev);
!                         }
                          $folded = str_repeat(' ', 4 * count($parts)) . imap_utf7_decode($subfolder);
  
                          if (strlen($folded) > 26) {
--- 192,216 ----
                          }
                          $parts = explode($delimiter, $label);
                          $subfolder = array_pop($parts);
! 												
! 												$parentparts = $parts;
! 												while (count($parentparts) > 0) {
! 													$parent = implode($delimiter, $parentparts);
! 													if (!empty($parent) && ($parent != 'INBOX') &&
! 															!array_key_exists($prefix . $namespace . $parent, $list) &&
! 															!array_key_exists($parent, $list) &&
! 															!array_key_exists($parent, $parents)) {
! 															$parents[$parent] = 1;
! 															$plabel = str_repeat(' ', 4 * (count($parentparts) - 1)) . imap_utf7_decode($parts[count($parentparts) - 1]) . $delimiter;
! 															if (strlen($plabel) > 26) {
! 																	$pabbrev = substr($plabel, 0, 10) . '...' . substr($plabel, -13, 13);
! 															} else {
! 																	$pabbrev = $plabel;
! 															}
! 															$list[$parent] = array('val' => '', 'label' => $plabel, 'abbrev' => $pabbrev);
! 													}
! 													array_pop($parentparts);
! 												}
                          $folded = str_repeat(' ', 4 * count($parts)) . imap_utf7_decode($subfolder);
  
                          if (strlen($folded) > 26) {


More information about the dev mailing list