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