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 |
10 | **/ |
11 | |
12 | session_start(); |
13 | |
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"); |
ef870322 |
22 | |
23 | include("../src/load_prefs.php"); |
24 | |
5bdd7223 |
25 | |
26 | if($old_name == $new_name) { |
27 | $location = get_location(); |
28 | header ("Location: $location/folders.php"); |
29 | exit; |
30 | } |
31 | |
ef870322 |
32 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
33 | $dm = sqimap_get_delimiter($imapConnection); |
34 | |
d92b6f31 |
35 | if (strpos($orig, $dm)) |
36 | $old_dir = substr($orig, 0, strrpos($orig, $dm)); |
37 | else |
38 | $old_dir = ""; |
39 | |
40 | if ($old_dir != "") |
41 | $newone = "$old_dir$dm$new_name"; |
42 | else |
43 | $newone = "$new_name"; |
44 | |
7aaa81fc |
45 | $orig = sqStripSlashes($orig); |
46 | $newone = sqStripSlashes($newone); |
d7092926 |
47 | |
390372b4 |
48 | fputs ($imapConnection, ". RENAME \"$orig\" \"$newone\"\r\n"); |
813eba2f |
49 | $data = sqimap_read_data($imapConnection, ".", true, $a, $b); |
d92b6f31 |
50 | |
f16d469a |
51 | // Renaming a folder doesn't renames the folder but leaves you unsubscribed |
52 | // at least on Cyrus IMAP servers. |
693ccbc9 |
53 | if ($isfolder) { |
54 | $newone = $newone.$dm; |
55 | $orig = $orig.$dm; |
56 | } |
693ccbc9 |
57 | sqimap_unsubscribe($imapConnection, $orig); |
58 | sqimap_subscribe($imapConnection, $newone); |
d92b6f31 |
59 | |
a97105e6 |
60 | fputs ($imapConnection, "a001 LIST \"\" \"$newone*\"\r\n"); |
390372b4 |
61 | $data = sqimap_read_data($imapConnection, "a001", true, $a, $b); |
a97105e6 |
62 | for ($i=0; $i < count($data); $i++) |
63 | { |
390372b4 |
64 | $name = find_mailbox_name($data[$i]); |
390372b4 |
65 | |
5bdd7223 |
66 | if ($name != $newone) // don't try to resubscribe when renaming ab to abc |
a97105e6 |
67 | { |
68 | sqimap_unsubscribe($imapConnection, $name); |
69 | $name = substr($name, strlen($orig)); |
70 | $name = $newone . $name; |
71 | sqimap_subscribe($imapConnection, $name); |
72 | } |
73 | } |
390372b4 |
74 | |
be69e508 |
75 | /** Log out this session **/ |
693ccbc9 |
76 | sqimap_logout($imapConnection); |
1195c340 |
77 | $location = get_location(); |
78 | header ("Location: $location/folders.php?success=rename"); |
be69e508 |
79 | ?> |