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 if (!isset($config_php))
15 include("../config/config.php");
16 if (!isset($strings_php))
17 include("../functions/strings.php");
18 if (!isset($page_header_php))
19 include("../functions/page_header.php");
20 if (!isset($imap_php))
21 include("../functions/imap.php");
23 include("../src/load_prefs.php");
25 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
26 $dm = sqimap_get_delimiter($imapConnection);
28 if (strpos($orig, $dm))
29 $old_dir = substr($orig, 0, strrpos($orig, $dm));
34 $newone = "$old_dir$dm$new_name";
36 $newone = "$new_name";
38 $orig = sqStripSlashes($orig);
39 $newone = sqStripSlashes($newone);
41 fputs ($imapConnection, ". RENAME \"$orig\" \"$newone\"\r\n");
42 $data = sqimap_read_data($imapConnection, ".", true, $a, $b);
44 // Renaming a folder doesn't renames the folder but leaves you unsubscribed
45 // at least on Cyrus IMAP servers.
47 $newone = $newone.$dm;
50 sqimap_unsubscribe($imapConnection, $orig);
51 sqimap_subscribe($imapConnection, $newone);
53 fputs ($imapConnection, "a001 LSUB \"\" \"$orig*\"\r\n");
54 $data = sqimap_read_data($imapConnection, "a001", true, $a, $b);
55 for ($i=0; $i < count($data); $i++
) {
56 $name = find_mailbox_name($data[$i]);
57 sqimap_unsubscribe($imapConnection, $name);
58 $name = substr($name, strlen($orig));
59 $name = $newone . $name;
60 sqimap_subscribe($imapConnection, $name);
64 /** Log out this session **/
65 sqimap_logout($imapConnection);
66 $location = get_location();
67 header ("Location: $location/folders.php?success=rename");