Lots of changes for variable initialization - clean up, really,
[squirrelmail.git] / src / folders_rename_do.php
CommitLineData
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. */
16define('SM_PATH','../');
17
18/* SquirrelMail required files. */
08185f2a 19require_once(SM_PATH . 'include/validate.php');
86725763 20require_once(SM_PATH . 'functions/imap.php');
b7f83b61 21require_once(SM_PATH . 'functions/display_messages.php');
5bdd7223 22
a32985a5 23/* globals */
1e12d1ff 24sqgetGlobalVar('key', $key, SQ_COOKIE);
25sqgetGlobalVar('username', $username, SQ_SESSION);
26sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
27sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
28sqgetGlobalVar('orig', $orig, SQ_POST);
29sqgetGlobalVar('old_name', $old_name, SQ_POST);
30sqgetGlobalVar('new_name', $new_name, SQ_POST);
a32985a5 31/* end globals */
08185f2a 32
c6ee68f5 33$new_name = trim($new_name);
34
b7f83b61 35if (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
e429f014 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
1c52ba77 49if ($old_name <> $new_name) {
5bdd7223 50
1c52ba77 51 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
ef870322 52
1c52ba77 53 if (strpos($orig, $delimiter)) {
54 $old_dir = substr($orig, 0, strrpos($orig, $delimiter));
55 } else {
56 $old_dir = '';
57 }
d92b6f31 58
1c52ba77 59 if ($old_dir != '') {
60 $newone = $old_dir . $delimiter . $new_name;
61 } else {
62 $newone = $new_name;
63 }
d92b6f31 64
b7f83b61 65 // Renaming a folder doesn't rename the folder but leaves you unsubscribed
1c52ba77 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 );
d92b6f31 72
1c52ba77 73 // Log out this session
74 sqimap_logout($imapConnection);
d92b6f31 75
1c52ba77 76}
b7f83b61 77
78header ('Location: ' . get_location() . '/folders.php?success=rename');
79
525b7ae6 80?>