removing trailing ?> from function scripts
[squirrelmail.git] / functions / folder_manip.php
index 46ba4b9d8469beddabd0e1ca6eb4759830d69fcb..b1032dc9f9b511ccd3cbbc52c2a886af6a839c20 100644 (file)
@@ -1,19 +1,18 @@
 <?php
 
 /**
-* folder_manip.php
-*
-* Copyright (c) 1999-2005 The SquirrelMail Project Team
-* Licensed under the GNU GPL. For full terms see the file COPYING.
-*
-* Functions for IMAP folder manipulation:
-* (un)subscribe, create, rename, delete.
-*
-* @version $Id$
-* @package squirrelmail
-* @see folders.php
-* @author Thijs Kinkhorst - kink@squirrelmail.org
-*/
+ * folder_manip.php
+ *
+ * Functions for IMAP folder manipulation:
+ * (un)subscribe, create, rename, delete.
+ *
+ * @author Thijs Kinkhorst <kink at squirrelmail.org>
+ * @copyright &copy; 1999-2006 The SquirrelMail Project Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
+ * @version $Id$
+ * @package squirrelmail
+ * @see folders.php
+ */
 
 
 /**
@@ -25,13 +24,18 @@ function folders_checkname($imapConnection, $folder_name, $delimiter)
 {
     if (substr_count($folder_name, '"') || substr_count($folder_name, "\\") ||
         substr_count($folder_name, $delimiter) || ($folder_name == '')) {
-        
-        global $color;
-        plain_error_message(_("Illegal folder name. Please select a different name.").
-            '<br /><a href="../src/folders.php">'._("Click here to go back").'</a>.', $color);
-                   
+
+        global $color, $oTemplate;
+        error_box(_("Illegal folder name.") . "<br />\n" .
+                sprintf(_("The name may not contain any of the following: %s"), '<tt>" \\ '.$delimiter.'</tt>')
+                . "<br />\n" .
+                _("Please select a different name.").
+                '<br /><a href="folders.php">'.
+                _("Click here to go back") . '</a>.');
+
         sqimap_logout($imapConnection);
-           exit;
+        $oTemplate->display('footer.tpl');
+        exit;
     }
 }
 
@@ -45,7 +49,7 @@ function folders_create ($imapConnection, $delimiter, $folder_name, $subfolder,
     global $folder_prefix;
 
     $folder_name = imap_utf7_encode_local($folder_name);
-   
+
     if ( ! empty($contain_subs) ) {
         $folder_name = $folder_name . $delimiter;
     }
@@ -74,12 +78,12 @@ function folders_create ($imapConnection, $delimiter, $folder_name, $subfolder,
  * folder should be renamed to.
  */
 function folders_rename_getname ($imapConnection, $delimiter, $old) {
-    global $color;
+    global $color,$default_folder_prefix;
 
     if ( $old == '' ) {
         plain_error_message(_("You have not selected a folder to rename. Please do so.").
             '<br /><a href="../src/folders.php">'._("Click here to go back").'</a>.', $color);
-        sqimap_logout($imapConnection);    
+        sqimap_logout($imapConnection);
         exit;
     }
 
@@ -94,7 +98,15 @@ function folders_rename_getname ($imapConnection, $delimiter, $old) {
 
     if (strpos($old, $delimiter)) {
         $old_name = substr($old, strrpos($old, $delimiter)+1, strlen($old));
-        $old_parent = substr($old, 0, strrpos($old, $delimiter));
+        // hide default prefix (INBOX., mail/ or other)
+        $quoted_prefix=preg_quote($default_folder_prefix,'/');
+        $prefix_length=(preg_match("/^$quoted_prefix/",$old) ? strlen($default_folder_prefix) : 0);
+        if ($prefix_length>strrpos($old, $delimiter)) {
+            $old_parent = '';
+        } else {
+            $old_parent = substr($old, $prefix_length, (strrpos($old, $delimiter)-$prefix_length))
+                . ' ' . $delimiter;
+        }
     } else {
         $old_name = $old;
         $old_parent = '';
@@ -109,8 +121,8 @@ function folders_rename_getname ($imapConnection, $delimiter, $old) {
             html_tag( 'td', '', 'center', $color[4] ) .
             addForm('folders.php').
             addHidden('smaction', 'rename').
-             _("New name:").
-             '<br /><b>' . htmlspecialchars($old_parent) . ' ' . htmlspecialchars($delimiter) . '</b>' .
+             '<label for="new_name">' . _("New name:") . '</label>' .
+             '<br /><b>' . htmlspecialchars($old_parent) . '</b>' .
              addInput('new_name', $old_name, 25) . '<br /><br />' . "\n";
              if ( $isfolder ) {
                  echo addHidden('isfolder', 'true');
@@ -120,9 +132,9 @@ function folders_rename_getname ($imapConnection, $delimiter, $old) {
              '<input type="submit" value="'._("Rename")."\" />\n".
              '<input type="submit" name="cancelbutton" value="'._("Cancel")."\" />\n".
              '</form><br /></td></tr></table>';
-    echo "\n\n</body></html>";
-    
-    sqimap_logout($imapConnection);    
+    echo "\n</td></tr></table>\n</td></tr></table>\n\n</body></html>";
+
+    sqimap_logout($imapConnection);
     exit;
 }
 
@@ -136,7 +148,7 @@ function folders_rename_do($imapConnection, $delimiter, $orig, $old_name, $new_n
     $orig = imap_utf7_encode_local($orig);
     $old_name = imap_utf7_encode_local($old_name);
     $new_name = imap_utf7_encode_local($new_name);
-    
+
     if ($old_name != $new_name) {
 
         if (strpos($orig, $delimiter)) {
@@ -170,7 +182,7 @@ function folders_rename_do($imapConnection, $delimiter, $orig, $old_name, $new_n
  */
 function folders_delete_ask ($imapConnection, $folder_name)
 {
-    global $color;
+    global $color,$default_folder_prefix;
 
     if ($folder_name == '') {
         plain_error_message(_("You have not selected a folder to delete. Please do so.").
@@ -178,6 +190,12 @@ function folders_delete_ask ($imapConnection, $folder_name)
         exit;
     }
 
+    // hide default folder prefix (INBOX., mail/ or other)
+    $visible_folder_name = imap_utf7_decode_local($folder_name);
+    $quoted_prefix = preg_quote($default_folder_prefix,'/');
+    $prefix_length = (preg_match("/^$quoted_prefix/",$visible_folder_name) ? strlen($default_folder_prefix) : 0);
+    $visible_folder_name = substr($visible_folder_name,$prefix_length);
+
     echo '<br />' .
         html_tag( 'table', '', 'center', '', 'width="95%" border="0"' ) .
         html_tag( 'tr',
@@ -186,8 +204,7 @@ function folders_delete_ask ($imapConnection, $folder_name)
         html_tag( 'tr' ) .
         html_tag( 'td', '', 'center', $color[4] ) .
         sprintf(_("Are you sure you want to delete %s?"),
-            str_replace(array(' ','<','>'),array('&nbsp;','&lt;','&gt;'),
-                imap_utf7_decode_local($folder_name))).
+            str_replace(array(' ','<','>'),array('&nbsp;','&lt;','&gt;'),$visible_folder_name)).
         addForm('folders.php', 'post')."<p>\n".
         addHidden('smaction', 'delete').
         addHidden('folder_name', $folder_name).
@@ -195,9 +212,9 @@ function folders_delete_ask ($imapConnection, $folder_name)
         addSubmit(_("No"), 'cancelbutton').
         '</p></form><br /></td></tr></table>';
 
-    echo "\n\n</body></html>";
+    echo "\n</td></tr></table>\n</td></tr></table>\n\n</body></html>";
 
-    sqimap_logout($imapConnection);    
+    sqimap_logout($imapConnection);
     exit;
 }
 
@@ -206,8 +223,8 @@ function folders_delete_ask ($imapConnection, $folder_name)
  */
 function folders_delete_do ($imapConnection, $delimiter, $folder_name)
 {
-    require_once(SM_PATH . 'functions/tree.php');
-    
+    include(SM_PATH . 'functions/tree.php');
+
     $boxes = sqimap_mailbox_list ($imapConnection);
 
     global $delete_folder, $imap_server_type, $trash_folder, $move_to_trash;
@@ -293,7 +310,7 @@ function folders_subscribe($imapConnection, $folder_names)
                 '<br /><a href="../src/folders.php">'._("Click here to go back").'</a>.', $color);
             sqimap_logout($imapConnection);
             exit;
-            
+
         }
     }
     foreach ( $folder_names as $folder_name ) {
@@ -323,6 +340,3 @@ function folders_unsubscribe($imapConnection, $folder_names)
 
     return;
 }
-
-
-?>