fix for mailboxes with trailing delimiter in the new mailboxtree
[squirrelmail.git] / src / folders.php
index 9adb36b01e699da019795562a6577bd75883304d..26b9709b85d92353bd7fcd4a4f5283fb5b888ee3 100644 (file)
@@ -14,6 +14,7 @@
  */
 
 require_once('../src/validate.php');
+require_once('../functions/imap_utf7_decode_local.php');
 require_once('../functions/imap.php');
 require_once('../functions/array.php');
 require_once('../functions/plugin.php');
@@ -80,12 +81,15 @@ for ($i = 0; $i < count($boxes); $i++) {
     if (!in_array('noinferiors', $boxes[$i]['flags'])) {
         if ((strtolower($boxes[$i]['unformatted']) == 'inbox') &&
             $default_sub_of_inbox) {
+
             $box = $boxes[$i]['unformatted'];
-            $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
+            $box2 = imap_utf7_decode_local(
+                     str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']));
             echo "<OPTION SELECTED VALUE=\"$box\">$box2</option>\n";
         } else {
             $box = $boxes[$i]['unformatted'];
-            $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
+            $box2 = imap_utf7_decode_local(
+                     str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']));
             if (strtolower($imap_server_type) != 'courier' ||
                   strtolower($box) != "inbox.trash")
                 echo "<OPTION VALUE=\"$box\">$box2</option>\n";
@@ -103,14 +107,43 @@ echo "</FORM></TD></TR>\n";
 
 echo "<tr><td bgcolor=\"$color[4]\">&nbsp;</td></tr>\n";
 
+
+/** count special folders **/
+$count_special_folders = 0;
+$num_max = 1;
+if (strtolower($imap_server_type) == "courier" || $move_to_trash) {
+        $num_max++;
+}
+if ($move_to_sent) {
+        $num_max++;
+}
+if ($save_as_draft) {
+        $num_max++;
+}
+for ($p = 0; $p < count($boxes) && $count_special_folders < $num_max; $p++) {
+    if (strtolower($boxes[$p]['unformatted']) == 'inbox')
+        $count_special_folders++;
+    else if (strtolower($imap_server_type) == 'courier' &&
+            strtolower($boxes[$p]['unformatted']) == 'inbox.trash')
+        $count_special_folders++;
+    else if ($boxes[$p]['unformatted'] == $trash_folder && $trash_folder)
+        $count_special_folders++;
+    else if ($boxes[$p]['unformatted'] == $sent_folder && $sent_folder)
+        $count_special_folders++;
+    else if ($boxes[$p]['unformatted'] == $draft_folder && $draft_folder)
+        $count_special_folders++;
+}
+
+
 /** RENAMING FOLDERS **/
 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><B>".
      _("Rename a Folder").
      "</B></TD></TR>".
      "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>";
 if ($count_special_folders < count($boxes)) {
-    echo "<FORM ACTION=\"folders_rename_getname.php\" METHOD=\"POST\">\n".
-         "<TT><SELECT NAME=old>\n";
+    echo "<FORM ACTION=\"folders_rename_getname.php\" METHOD=\"POST\">\n"
+       . "<TT><SELECT NAME=old>\n"
+       . '         <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
     for ($i = 0; $i < count($boxes); $i++) {
         $use_folder = true;
 
@@ -120,7 +153,8 @@ if ($count_special_folders < count($boxes)) {
             ($boxes[$i]['unformatted'] != $draft_folder)) {
             $box = $boxes[$i]['unformatted-dm'];
 
-            $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
+            $box2 = imap_utf7_decode_local(
+                     str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']));
             if (strtolower($imap_server_type) != 'courier' || strtolower($box) != 'inbox.trash') {
                 echo "<OPTION VALUE=\"$box\">$box2</option>\n";
             }
@@ -144,44 +178,22 @@ echo _("Delete Folder");
 echo "</B></TD></TR>";
 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>";
 
-$count_special_folders = 0;
-$num_max = 1;
-if (strtolower($imap_server_type) == "courier" || $move_to_trash) {
-        $num_max++;
-}
-if ($move_to_sent) {
-        $num_max++;
-}
-if ($save_as_draft) {
-        $num_max++;
-}
-for ($p = 0; $p < count($boxes) && $count_special_folders < $num_max; $p++) {
-    if (strtolower($boxes[$p]['unformatted']) == 'inbox')
-        $count_special_folders++;
-    else if (strtolower($imap_server_type) == 'courier' &&
-            strtolower($boxes[$p]['unformatted']) == 'inbox.trash')
-        $count_special_folders++;
-    else if ($boxes[$p]['unformatted'] == $trash_folder && $trash_folder)
-        $count_special_folders++;
-    else if ($boxes[$p]['unformatted'] == $sent_folder && $sent_folder)
-        $count_special_folders++;
-    else if ($boxes[$p]['unformatted'] == $draft_folder && $draft_folder)
-        $count_special_folders++;
-}
-
 if ($count_special_folders < count($boxes)) {
-    echo "<FORM ACTION=\"folders_delete.php\" METHOD=\"POST\">\n";
-    echo "<TT><SELECT NAME=mailbox>\n";
+    echo "<FORM ACTION=\"folders_delete.php\" METHOD=\"POST\">\n"
+       . "<TT><SELECT NAME=mailbox>\n"
+       . '         <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
     for ($i = 0; $i < count($boxes); $i++) {
         $use_folder = true;
         if ((strtolower($boxes[$i]['unformatted']) != 'inbox') &&
             ($boxes[$i]['unformatted'] != $trash_folder) &&
             ($boxes[$i]['unformatted'] != $sent_folder) &&
             ($boxes[$i]['unformatted'] != $draft_folder) &&
+            (!in_array('noselect', $boxes[$i]['flags'])) &&
             ((strtolower($imap_server_type) != 'courier') ||
              (strtolower($boxes[$i]['unformatted']) != 'inbox.trash'))) {
             $box = $boxes[$i]['unformatted-dm'];
-            $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
+            $box2 = imap_utf7_decode_local(
+                     str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']));
             echo "         <OPTION VALUE=\"$box\">$box2</option>\n";
         }
     }
@@ -211,7 +223,8 @@ if ($count_special_folders < count($boxes)) {
             ($boxes[$i]["unformatted"] != $sent_folder) &&
             ($boxes[$i]["unformatted"] != $draft_folder)) {
             $box = $boxes[$i]["unformatted-dm"];
-            $box2 = str_replace(' ', '&nbsp;', $boxes[$i]["unformatted-disp"]);
+            $box2 = imap_utf7_decode_local(
+                     str_replace(' ', '&nbsp;', $boxes[$i]["unformatted-disp"]));
             echo "         <OPTION VALUE=\"$box\">$box2\n";
         }
     }
@@ -242,9 +255,9 @@ for ($i = 0, $q = 0; $i < count($boxes_all); $i++) {
             $use_folder = false;
         }
     }
-    if ($use_folder == true) { 
+    if ($use_folder == true) {
         $box[$q] = $boxes_all[$i]["unformatted-dm"];
-        $box2[$q] = $boxes_all[$i]["unformatted-disp"];
+        $box2[$q] = imap_utf7_decode_local($boxes_all[$i]["unformatted-disp"]);
         $q++;
     }
 }
@@ -278,4 +291,4 @@ do_hook("folders_bottom");
    sqimap_logout($imapConnection);
 ?>
 
-</body></html>
\ No newline at end of file
+</body></html>