59177427 |
1 | <?php |
895905c0 |
2 | |
35586184 |
3 | /** |
4 | * folders_rename_do.php |
5 | * |
76911253 |
6 | * Copyright (c) 1999-2003 The SquirrelMail Project Team |
35586184 |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
8 | * |
1c52ba77 |
9 | * Does the actual renaming of files on the IMAP server. |
35586184 |
10 | * Called from the folders.php |
11 | * |
12 | * $Id$ |
13 | */ |
14 | |
86725763 |
15 | /* Path for SquirrelMail required files. */ |
16 | define('SM_PATH','../'); |
17 | |
18 | /* SquirrelMail required files. */ |
08185f2a |
19 | require_once(SM_PATH . 'include/validate.php'); |
8650e9e1 |
20 | require_once(SM_PATH . 'functions/global.php'); |
86725763 |
21 | require_once(SM_PATH . 'functions/imap.php'); |
b7f83b61 |
22 | require_once(SM_PATH . 'functions/display_messages.php'); |
5bdd7223 |
23 | |
a32985a5 |
24 | /* globals */ |
1e12d1ff |
25 | sqgetGlobalVar('key', $key, SQ_COOKIE); |
26 | sqgetGlobalVar('username', $username, SQ_SESSION); |
27 | sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION); |
28 | sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION); |
29 | sqgetGlobalVar('orig', $orig, SQ_POST); |
30 | sqgetGlobalVar('old_name', $old_name, SQ_POST); |
31 | sqgetGlobalVar('new_name', $new_name, SQ_POST); |
a32985a5 |
32 | /* end globals */ |
08185f2a |
33 | |
c6ee68f5 |
34 | $new_name = trim($new_name); |
35 | |
b7f83b61 |
36 | if (substr_count($new_name, '"') || substr_count($new_name, "\\") || |
37 | substr_count($new_name, $delimiter) || ($new_name == '')) { |
38 | displayPageHeader($color, 'None'); |
39 | |
40 | plain_error_message(_("Illegal folder name. Please select a different name."). |
41 | '<BR><A HREF="../src/folders.php">'._("Click here to go back").'</A>.', $color); |
42 | |
43 | exit; |
44 | } |
45 | |
e429f014 |
46 | $orig = imap_utf7_encode_local($orig); |
47 | $old_name = imap_utf7_encode_local($old_name); |
48 | $new_name = imap_utf7_encode_local($new_name); |
49 | |
1c52ba77 |
50 | if ($old_name <> $new_name) { |
5bdd7223 |
51 | |
1c52ba77 |
52 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
ef870322 |
53 | |
1c52ba77 |
54 | if (strpos($orig, $delimiter)) { |
55 | $old_dir = substr($orig, 0, strrpos($orig, $delimiter)); |
56 | } else { |
57 | $old_dir = ''; |
58 | } |
d92b6f31 |
59 | |
1c52ba77 |
60 | if ($old_dir != '') { |
61 | $newone = $old_dir . $delimiter . $new_name; |
62 | } else { |
63 | $newone = $new_name; |
64 | } |
d92b6f31 |
65 | |
b7f83b61 |
66 | // Renaming a folder doesn't rename the folder but leaves you unsubscribed |
1c52ba77 |
67 | // at least on Cyrus IMAP servers. |
68 | if (isset($isfolder)) { |
69 | $newone = $newone.$delimiter; |
70 | $orig = $orig.$delimiter; |
71 | } |
72 | sqimap_mailbox_rename( $imapConnection, $orig, $newone ); |
d92b6f31 |
73 | |
1c52ba77 |
74 | // Log out this session |
75 | sqimap_logout($imapConnection); |
d92b6f31 |
76 | |
1c52ba77 |
77 | } |
b7f83b61 |
78 | |
79 | header ('Location: ' . get_location() . '/folders.php?success=rename'); |
80 | |
525b7ae6 |
81 | ?> |