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