59177427 |
1 | <?php |
ef870322 |
2 | /** |
3 | ** folders_rename_do.php |
4 | ** |
5 | ** Copyright (c) 1999-2000 The SquirrelMail development team |
6 | ** Licensed under the GNU GPL. For full terms see the file COPYING. |
7 | ** |
8 | ** Does the actual renaming of files on the IMAP server. |
9 | ** Called from the folders.php |
245a6892 |
10 | ** |
11 | ** $Id$ |
ef870322 |
12 | **/ |
13 | |
f740c049 |
14 | include("../src/validate.php"); |
f740c049 |
15 | include("../functions/page_header.php"); |
16 | include("../functions/imap.php"); |
ef870322 |
17 | include("../src/load_prefs.php"); |
18 | |
5bdd7223 |
19 | |
20 | if($old_name == $new_name) { |
21 | $location = get_location(); |
22 | header ("Location: $location/folders.php"); |
23 | exit; |
24 | } |
25 | |
ef870322 |
26 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
27 | $dm = sqimap_get_delimiter($imapConnection); |
28 | |
d92b6f31 |
29 | if (strpos($orig, $dm)) |
30 | $old_dir = substr($orig, 0, strrpos($orig, $dm)); |
31 | else |
32 | $old_dir = ""; |
33 | |
34 | if ($old_dir != "") |
35 | $newone = "$old_dir$dm$new_name"; |
36 | else |
37 | $newone = "$new_name"; |
38 | |
390372b4 |
39 | fputs ($imapConnection, ". RENAME \"$orig\" \"$newone\"\r\n"); |
813eba2f |
40 | $data = sqimap_read_data($imapConnection, ".", true, $a, $b); |
d92b6f31 |
41 | |
f16d469a |
42 | // Renaming a folder doesn't renames the folder but leaves you unsubscribed |
43 | // at least on Cyrus IMAP servers. |
1863670d |
44 | if (isset($isfolder)) { |
693ccbc9 |
45 | $newone = $newone.$dm; |
46 | $orig = $orig.$dm; |
47 | } |
693ccbc9 |
48 | sqimap_unsubscribe($imapConnection, $orig); |
49 | sqimap_subscribe($imapConnection, $newone); |
d92b6f31 |
50 | |
a97105e6 |
51 | fputs ($imapConnection, "a001 LIST \"\" \"$newone*\"\r\n"); |
390372b4 |
52 | $data = sqimap_read_data($imapConnection, "a001", true, $a, $b); |
a97105e6 |
53 | for ($i=0; $i < count($data); $i++) |
54 | { |
390372b4 |
55 | $name = find_mailbox_name($data[$i]); |
390372b4 |
56 | |
5bdd7223 |
57 | if ($name != $newone) // don't try to resubscribe when renaming ab to abc |
a97105e6 |
58 | { |
59 | sqimap_unsubscribe($imapConnection, $name); |
60 | $name = substr($name, strlen($orig)); |
61 | $name = $newone . $name; |
62 | sqimap_subscribe($imapConnection, $name); |
63 | } |
64 | } |
390372b4 |
65 | |
be69e508 |
66 | /** Log out this session **/ |
693ccbc9 |
67 | sqimap_logout($imapConnection); |
1195c340 |
68 | $location = get_location(); |
69 | header ("Location: $location/folders.php?success=rename"); |
be69e508 |
70 | ?> |