NO it's not a habit from me.
[squirrelmail.git] / src / folders_rename_do.php
index 7c8bb47ba8f53f664d1972588565f53d99b27267..8c596eaae740feb979dc2719713e6d81caafb7e2 100644 (file)
@@ -1,78 +1,66 @@
 <?php
-   /**
-    **  folders_rename_do.php
-    **
-    **  Copyright (c) 1999-2000 The SquirrelMail development team
-    **  Licensed under the GNU GPL. For full terms see the file COPYING.
-    **
-    **  Does the actual renaming of files on the IMAP server. 
-    **  Called from the folders.php
-    **
-    **  $Id$
-    **/
 
-   session_start();
+/**
+ * folders_rename_do.php
+ *
+ * Copyright (c) 1999-2002 The SquirrelMail Project Team
+ * Licensed under the GNU GPL. For full terms see the file COPYING.
+ *
+ * Does the actual renaming of files on the IMAP server.
+ * Called from the folders.php
+ *
+ * $Id$
+ */
 
-   if (!isset($strings_php))
-      include("../functions/strings.php");
-   if (!isset($config_php))
-      include("../config/config.php");
-   if (!isset($page_header_php))
-      include("../functions/page_header.php");
-   if (!isset($imap_php))
-      include("../functions/imap.php");
+/* Path for SquirrelMail required files. */
+define('SM_PATH','../');
 
-   include("../src/load_prefs.php");
+/* SquirrelMail required files. */
+require_once(SM_PATH . 'include/validate.php');
+require_once(SM_PATH . 'functions/imap.php');
 
+/* globals */
+$username = $_SESSION['username'];
+$key = $_COOKIE['key'];
+$delimiter = $_SESSION['delimiter'];
+$onetimepad = $_SESSION['onetimepad'];
+$base_uri = $_SESSION['base_uri'];
 
-   if($old_name == $new_name) {
-      $location = get_location();
-      header ("Location: $location/folders.php");
-      exit;
-   }
+$orig = $_POST['orig'];
+$old_name = $_POST['old_name'];
+$new_name = $_POST['new_name'];
 
-   $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
-   $dm = sqimap_get_delimiter($imapConnection);
+/* end globals */
 
-   if (strpos($orig, $dm))
-      $old_dir = substr($orig, 0, strrpos($orig, $dm));
-   else
-      $old_dir = "";
+$new_name = trim($new_name);
 
-   if ($old_dir != "")
-      $newone = "$old_dir$dm$new_name";
-   else
-      $newone = "$new_name";
+if ($old_name <> $new_name) {
 
-   fputs ($imapConnection, ". RENAME \"$orig\" \"$newone\"\r\n");
-   $data = sqimap_read_data($imapConnection, ".", true, $a, $b);
+    $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
 
-   // Renaming a folder doesn't renames the folder but leaves you unsubscribed
-   //    at least on Cyrus IMAP servers.
-   if (isset($isfolder)) {
-      $newone = $newone.$dm;
-      $orig = $orig.$dm;
-   }   
-   sqimap_unsubscribe($imapConnection, $orig);
-   sqimap_subscribe($imapConnection, $newone);
+    if (strpos($orig, $delimiter)) {
+        $old_dir = substr($orig, 0, strrpos($orig, $delimiter));
+    } else {
+        $old_dir = '';
+    }
 
-       fputs ($imapConnection, "a001 LIST \"\" \"$newone*\"\r\n");
-   $data = sqimap_read_data($imapConnection, "a001", true, $a, $b);
-   for ($i=0; $i < count($data); $i++)
-   {
-      $name = find_mailbox_name($data[$i]);
+    if ($old_dir != '') {
+        $newone = $old_dir . $delimiter . $new_name;
+    } else {
+        $newone = $new_name;
+    }
 
-      if ($name != $newone) // don't try to resubscribe when renaming ab to abc
-      {
-        sqimap_unsubscribe($imapConnection, $name);
-        $name = substr($name, strlen($orig));
-        $name = $newone . $name;
-        sqimap_subscribe($imapConnection, $name);
-      }
-   }
+    // Renaming a folder doesn't renames the folder but leaves you unsubscribed
+    //    at least on Cyrus IMAP servers.
+    if (isset($isfolder)) {
+        $newone = $newone.$delimiter;
+        $orig = $orig.$delimiter;
+    }
+    sqimap_mailbox_rename( $imapConnection, $orig, $newone );
 
-   /** Log out this session **/
-   sqimap_logout($imapConnection);
-   $location = get_location();
-   header ("Location: $location/folders.php?success=rename");
+    // Log out this session 
+    sqimap_logout($imapConnection);
+
+}
+header ('Location: ' . $base_uri . 'src/folders.php?success=rename');
 ?>