Fixed a bug where users that did not log in before would get tons of
[squirrelmail.git] / functions / imap_mailbox.php
index 21ee5a80e3db2bf5fc36fa1a5c4cf8ad31031747..8e2600f059f6e70d70a553fc68377e1cc43a8291 100755 (executable)
@@ -12,7 +12,6 @@
       sqimap_mailbox_select ($imap_stream, $mailbox);
       fputs ($imap_stream, "a001 EXPUNGE\r\n");
       $read = sqimap_read_data($imap_stream, "a001", $handle_errors, $response, $message);
-      sqimap_mailbox_close ($imap_stream);
    }
 
 
       }
    }
 
-   /******************************************************************************
-    **  Closes an open mailbox 
-    ******************************************************************************/
-   function sqimap_mailbox_close ($imap_stream) {
-      fputs ($imap_stream, "a001 CLOSE\r\n");
-      $tmp = sqimap_read_data($imap_stream, "a001", false, $response, $message);
-   }
-
    /******************************************************************************
     **  Selects a mailbox
     ******************************************************************************/
            (ereg("^".$folder_prefix, $mailbox)) ||
             ( isset($boxesbyname[$parentfolder]) && (strlen($parentfolder) > 0) ) ) {
             $indent = $dm_count - (countCharInString($folder_prefix, $dm));
-            $boxes[$g]["formatted"]  = str_repeat("  ", $indent);
+            if ($indent)
+                $boxes[$g]["formatted"]  = str_repeat("  ", $indent);
+            else
+                $boxes[$g]["formatted"] = '';
             $boxes[$g]["formatted"] .= readShortMailboxName($mailbox, $dm);
          } else {
             $boxes[$g]["formatted"]  = $mailbox;
       fputs ($imap_stream, "a001 LSUB \"\" \"*\"\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 **/
+         unset($lsub_ary[count($lsub_ary)-1]);
+
       for ($i=0;$i < count($lsub_ary); $i++) {
          $sorted_lsub_ary[$i] = find_mailbox_name($lsub_ary[$i]);
          if ($sorted_lsub_ary[$i] == "INBOX")
 
          // Then list special folders and their subfolders
          for ($i = 0 ; $i <= count($boxes) ; $i++) {
-            if((eregi("^".$trash_folder.'$', $boxes[$i]["unformatted"]) ||
-                eregi("^".$trash_folder.quotemeta($dm), $boxes[$i]["unformatted"]) )  &&
+            if((eregi("^".quotemeta($trash_folder).'$', $boxes[$i]["unformatted"]) ||
+                eregi("^".quotemeta($trash_folder).quotemeta($dm), $boxes[$i]["unformatted"]) )  &&
                ($move_to_trash)) {        
                $boxesnew[] = $boxes[$i];
                $boxes[$i]["used"] = true;
             }
-            else if((eregi("^".$sent_folder.'$', $boxes[$i]["unformatted"]) ||
-                     eregi("^".$sent_folder.quotemeta($dm), $boxes[$i]["unformatted"]) )  &&
+            else if((eregi("^".quotemeta($sent_folder).'$', $boxes[$i]["unformatted"]) ||
+                     eregi("^".quotemeta($sent_folder).quotemeta($dm), $boxes[$i]["unformatted"]) )  &&
                     ($move_to_sent)) {        
                $boxesnew[] = $boxes[$i];
                $boxes[$i]["used"] = true;
             if((eregi("^inbox".quotemeta($dm), $mailbox)) || 
                (ereg("^".$folder_prefix, $mailbox)) ||
                ( isset($boxesbyname[$parentfolder]) && (strlen($parentfolder) > 0) ) ) {
-               $boxes[$g]["formatted"]  = str_repeat("&nbsp;&nbsp;", $dm_count);
+               if ($dm_count)
+                   $boxes[$g]["formatted"]  = str_repeat("&nbsp;&nbsp;", $dm_count);
+               else
+                   $boxes[$g]["formatted"] = '';
                $boxes[$g]["formatted"] .= readShortMailboxName($mailbox, $dm);
             } else {
                $boxes[$g]["formatted"]  = $mailbox;