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 include("../src/validate.php");
15 include("../functions/imap.php");
18 if($old_name == $new_name) {
19 $location = get_location();
20 header ("Location: $location/folders.php");
24 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
25 $dm = sqimap_get_delimiter($imapConnection);
27 if (strpos($orig, $dm))
28 $old_dir = substr($orig, 0, strrpos($orig, $dm));
33 $newone = "$old_dir$dm$new_name";
35 $newone = "$new_name";
37 $cmd = "a024 RENAME \"" . quoteIMAP($orig) . "\" \"" .
38 quoteIMAP($newone) . "\"\r\n";
39 echo htmlspecialchars($cmd) . "<br>\n";
40 fputs ($imapConnection, $cmd);
41 $data = sqimap_read_data($imapConnection, "a024", true, $a, $b);
43 // Renaming a folder doesn't renames the folder but leaves you unsubscribed
44 // at least on Cyrus IMAP servers.
45 if (isset($isfolder)) {
46 $newone = $newone.$dm;
49 sqimap_unsubscribe($imapConnection, $orig);
50 sqimap_subscribe($imapConnection, $newone);
52 fputs ($imapConnection, "a001 LIST \"\" \"" . quoteIMAP($newone) .
54 $data = sqimap_read_data($imapConnection, "a001", true, $a, $b);
55 for ($i=0; $i < count($data); $i++
)
57 $name = find_mailbox_name($data[$i]);
59 if ($name != $newone) // don't try to resubscribe when renaming ab to abc
61 sqimap_unsubscribe($imapConnection, $name);
62 $name = substr($name, strlen($orig));
63 $name = $newone . $name;
64 sqimap_subscribe($imapConnection, $name);
68 /** Log out this session **/
69 sqimap_logout($imapConnection);
70 $location = get_location();
71 header ("Location: $location/folders.php?success=rename");