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