3 ** folders_rename_do.php
5 ** Copyright (c) 1999-2000 The SquirrelMail development team
6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
8 ** Does the actual renaming of files on the IMAP server.
9 ** Called from the folders.php
14 require_once('../src/validate.php');
15 require_once('../functions/imap.php');
17 if($old_name == $new_name) {
18 $location = get_location();
19 header ("Location: $location/folders.php");
23 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
24 $dm = sqimap_get_delimiter($imapConnection);
26 if (strpos($orig, $dm))
27 $old_dir = substr($orig, 0, strrpos($orig, $dm));
32 $newone = "$old_dir$dm$new_name";
34 $newone = "$new_name";
36 $cmd = "a024 RENAME \"" . quoteIMAP($orig) . "\" \"" .
37 quoteIMAP($newone) . "\"\r\n";
38 fputs ($imapConnection, $cmd);
39 $data = sqimap_read_data($imapConnection, "a024", true, $a, $b);
41 // Renaming a folder doesn't renames the folder but leaves you unsubscribed
42 // at least on Cyrus IMAP servers.
43 if (isset($isfolder)) {
44 $newone = $newone.$dm;
47 sqimap_unsubscribe($imapConnection, $orig);
48 sqimap_subscribe($imapConnection, $newone);
50 fputs ($imapConnection, "a001 LIST \"\" \"" . quoteIMAP($newone) .
52 $data = sqimap_read_data($imapConnection, "a001", true, $a, $b);
53 for ($i=0; $i < count($data); $i++
)
55 $name = find_mailbox_name($data[$i]);
57 if ($name != $newone) // don't try to resubscribe when renaming ab to abc
59 sqimap_unsubscribe($imapConnection, $name);
60 $name = substr($name, strlen($orig));
61 $name = $newone . $name;
62 sqimap_subscribe($imapConnection, $name);
66 /** Log out this session **/
67 sqimap_logout($imapConnection);
68 $location = get_location();
69 header ("Location: $location/folders.php?success=rename");