Fix missing $username when rg=0
[squirrelmail.git] / src / folders_rename_do.php
index 8807f6456c2bd9a72a3937e7c142942e143dfabb..8c596eaae740feb979dc2719713e6d81caafb7e2 100644 (file)
@@ -1,70 +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$
-    **/
 
-   require_once('../src/validate.php');
-   require_once('../functions/imap.php');
+/**
+ * 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($old_name == $new_name) {
-      $location = get_location();
-      header ("Location: $location/folders.php");
-      exit;
-   }
+/* Path for SquirrelMail required files. */
+define('SM_PATH','../');
 
-   $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
-   $dm = sqimap_get_delimiter($imapConnection);
+/* SquirrelMail required files. */
+require_once(SM_PATH . 'include/validate.php');
+require_once(SM_PATH . 'functions/imap.php');
 
-   if (strpos($orig, $dm))
-      $old_dir = substr($orig, 0, strrpos($orig, $dm));
-   else
-      $old_dir = "";
+/* globals */
+$username = $_SESSION['username'];
+$key = $_COOKIE['key'];
+$delimiter = $_SESSION['delimiter'];
+$onetimepad = $_SESSION['onetimepad'];
+$base_uri = $_SESSION['base_uri'];
 
-   if ($old_dir != "")
-      $newone = "$old_dir$dm$new_name";
-   else
-      $newone = "$new_name";
+$orig = $_POST['orig'];
+$old_name = $_POST['old_name'];
+$new_name = $_POST['new_name'];
 
-   $cmd = sqimap_session_id() . " RENAME \"" . quoteIMAP($orig) . "\" \"" .
-      quoteIMAP($newone) . "\"\r\n";
-   fputs ($imapConnection, $cmd);
-   $data = sqimap_read_data($imapConnection, sqimap_session_id(), true, $a, $b);
+/* end globals */
 
-   // 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);
+$new_name = trim($new_name);
 
-   fputs ($imapConnection, sqimap_session_id() . " LIST \"\" \"" . quoteIMAP($newone) .
-      "*\"\r\n");
-   $data = sqimap_read_data($imapConnection, sqimap_session_id(), true, $a, $b);
-   for ($i=0; $i < count($data); $i++)
-   {
-      $name = find_mailbox_name($data[$i]);
+if ($old_name <> $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);
-      }
-   }
+    $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
 
-   /** Log out this session **/
-   sqimap_logout($imapConnection);
-   $location = get_location();
-   header ("Location: $location/folders.php?success=rename");
-?>
\ No newline at end of file
+    if (strpos($orig, $delimiter)) {
+        $old_dir = substr($orig, 0, strrpos($orig, $delimiter));
+    } else {
+        $old_dir = '';
+    }
+
+    if ($old_dir != '') {
+        $newone = $old_dir . $delimiter . $new_name;
+    } else {
+        $newone = $new_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);
+
+}
+header ('Location: ' . $base_uri . 'src/folders.php?success=rename');
+?>