* Possible fix for UW giving billions of files as "folders"
[squirrelmail.git] / functions / imap_mailbox.php
index 0ac9ca999ee9ee6231599cdf00084c774d2be815..5d59aafbac04b49e211a73adeb3a29b8f8c40843 100755 (executable)
@@ -7,11 +7,14 @@
     **  $Id$
     **/
 
+   if (defined ('imap_mailbox_php'))
+      return;
+   define ('imap_mailbox_php', true);
+
    /******************************************************************************
     **  Expunges a mailbox 
     ******************************************************************************/
    function sqimap_mailbox_expunge ($imap_stream, $mailbox,$handle_errors = true) {
-      sqimap_mailbox_select ($imap_stream, $mailbox);
       fputs ($imap_stream, "a001 EXPUNGE\r\n");
       $read = sqimap_read_data($imap_stream, "a001", $handle_errors, $response, $message);
    }
          // a parent.
          $boxesbyname[$mailbox] = $g;
          $parentfolder = readMailboxParent($mailbox, $dm);
-         if((eregi("^inbox".quotemeta($dm), $mailbox)) || 
-            (ereg("^".$folder_prefix, $mailbox)) ||
-            ( isset($boxesbyname[$parentfolder]) && (strlen($parentfolder) > 0) ) ) {
+         if((strtolower(substr($mailbox, 0, 5)) == "inbox") ||
+            (substr($mailbox, 0, strlen($folder_prefix)) == $folder_prefix) ||
+            (isset($boxesbyname[$parentfolder]) && (strlen($parentfolder) > 0) ) ) {
             $indent = $dm_count - (countCharInString($folder_prefix, $dm));
-            if ($indent)
+            if ($indent > 0)
                 $boxes[$g]["formatted"]  = str_repeat("  ", $indent);
             else
                 $boxes[$g]["formatted"] = '';
          if (substr($mailbox, -1) == $dm)
             $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
          $boxes[$g]['unformatted'] = $mailbox;
-         $boxes[$g]['unformatted-disp'] = ereg_replace('^' . $folder_prefix, '', $mailbox);
+         if (substr($mailbox,0,strlen($folder_prefix))==$folder_prefix)
+            $mailbox = substr($mailbox, strlen($folder_prefix));
+         $boxes[$g]['unformatted-disp'] = $mailbox;
          $boxes[$g]['id'] = $g;
 
          if (isset($line[$g]))
-         ereg("\(([^)]*)\)",$line[$g],$regs);
+            ereg("\(([^)]*)\)",$line[$g],$regs);
          $flags = trim(strtolower(str_replace('\\', '',$regs[1])));
          if ($flags) {
             $boxes[$g]['flags'] = explode(' ', $flags);
-         }
+         } else
+            $boxes[$g]['flags'] = array();
       }
 
       return $boxes;
     **  See comment on sqimap_mailbox_parse() for info about the returned array.
     ******************************************************************************/
    function sqimap_mailbox_list ($imap_stream) {
-      global $load_prefs_php, $prefs_php, $config_php;
       global $data_dir, $username, $list_special_folders_first;
       global $trash_folder, $sent_folder;
-      global $move_to_trash, $move_to_sent;
+      global $move_to_trash, $move_to_sent, $folder_prefix;
 
       $inbox_in_list = false;
       $inbox_subscribed = false;
 
-      if (!isset($load_prefs_php)) include "../src/load_prefs.php";
-      else global $folder_prefix;
-      if (!function_exists ("ary_sort")) include "../functions/array.php";
+      include "../src/load_prefs.php";
+      include "../functions/array.php";
 
       $dm = sqimap_get_delimiter ($imap_stream);
 
       /** LSUB array **/
       $inbox_subscribed = false;
-      fputs ($imap_stream, "a001 LSUB \"\" \"*\"\r\n");
+      fputs ($imap_stream, "a001 LSUB \"$folder_prefix\" \"*%\"\r\n");
       $lsub_ary = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
 
       /** OS: we don't want to parse last element of array, 'cause it is OK command, so we unset it **/
          if (isset($read[0]))
          $sorted_list_ary[$i] = $read[0];
          else
-         $sorget_list_ary[$i] = "";
+         $sorted_list_ary[$i] = "";
          if (isset($sorted_list_ary[$i]) && find_mailbox_name($sorted_list_ary[$i]) == "INBOX")
             $inbox_in_list = true;
       }
             $flags = str_replace('\\', '', $flags);
             $flags = trim(strtolower($flags));
             if ($flags) {
-               $boxes[$g]["flags"] = explode(" ", $flags);
+               $boxes[$g]['flags'] = explode(" ", $flags);
+            }
+            else
+            {
+               $boxes[$g]['flags'] = array();
             }
          }
          $g++;