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 | |
ff8a98e7 |
14 | require_once('../src/validate.php'); |
15 | require_once('../functions/imap.php'); |
5bdd7223 |
16 | |
17 | if($old_name == $new_name) { |
18 | $location = get_location(); |
19 | header ("Location: $location/folders.php"); |
20 | exit; |
21 | } |
22 | |
ef870322 |
23 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
24 | $dm = sqimap_get_delimiter($imapConnection); |
25 | |
d92b6f31 |
26 | if (strpos($orig, $dm)) |
27 | $old_dir = substr($orig, 0, strrpos($orig, $dm)); |
28 | else |
29 | $old_dir = ""; |
30 | |
31 | if ($old_dir != "") |
32 | $newone = "$old_dir$dm$new_name"; |
33 | else |
34 | $newone = "$new_name"; |
35 | |
56a19f1e |
36 | $cmd = sqimap_session_id() . " RENAME \"" . quoteIMAP($orig) . "\" \"" . |
844d9c1a |
37 | quoteIMAP($newone) . "\"\r\n"; |
844d9c1a |
38 | fputs ($imapConnection, $cmd); |
56a19f1e |
39 | $data = sqimap_read_data($imapConnection, sqimap_session_id(), true, $a, $b); |
d92b6f31 |
40 | |
f16d469a |
41 | // Renaming a folder doesn't renames the folder but leaves you unsubscribed |
42 | // at least on Cyrus IMAP servers. |
1863670d |
43 | if (isset($isfolder)) { |
693ccbc9 |
44 | $newone = $newone.$dm; |
45 | $orig = $orig.$dm; |
46 | } |
693ccbc9 |
47 | sqimap_unsubscribe($imapConnection, $orig); |
48 | sqimap_subscribe($imapConnection, $newone); |
d92b6f31 |
49 | |
56a19f1e |
50 | fputs ($imapConnection, sqimap_session_id() . " LIST \"\" \"" . quoteIMAP($newone) . |
844d9c1a |
51 | "*\"\r\n"); |
56a19f1e |
52 | $data = sqimap_read_data($imapConnection, sqimap_session_id(), 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"); |
ff8a98e7 |
70 | ?> |