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