Lots of changes for variable initialization - clean up, really,
[squirrelmail.git] / src / folders_create.php
1 <?php
2
3 /**
4 * folders_create.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 * Creates folders on the IMAP server.
10 * Called from 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 /* get globals we may need */
24 sqgetGlobalVar('key', $key, SQ_COOKIE);
25 sqgetGlobalVar('username', $username, SQ_SESSION);
26 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
27 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
28 sqgetGlobalVar('folder_name', $folder_name, SQ_POST);
29 sqgetGlobalVar('subfolder', $subfolder, SQ_POST);
30 sqgetGlobalVar('contain_subs', $contain_subs, SQ_POST);
31 /* end of get globals */
32
33 $folder_name = trim($folder_name);
34
35 if (substr_count($folder_name, '"') || substr_count($folder_name, "\\") ||
36 substr_count($folder_name, $delimiter) || ($folder_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 $folder_name = imap_utf7_encode_local($folder_name);
46
47 if (isset($contain_subs) && $contain_subs ) {
48 $folder_name = $folder_name . $delimiter;
49 }
50
51 if ($folder_prefix && (substr($folder_prefix, -1) != $delimiter)) {
52 $folder_prefix = $folder_prefix . $delimiter;
53 }
54 if ($folder_prefix && (substr($subfolder, 0, strlen($folder_prefix)) != $folder_prefix)){
55 $subfolder_orig = $subfolder;
56 $subfolder = $folder_prefix . $subfolder;
57 } else {
58 $subfolder_orig = $subfolder;
59 }
60
61 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
62
63 if (trim($subfolder_orig) == '') {
64 sqimap_mailbox_create ($imapConnection, $folder_prefix.$folder_name, '');
65 } else {
66 sqimap_mailbox_create ($imapConnection, $subfolder.$delimiter.$folder_name, '');
67 }
68
69 sqimap_logout($imapConnection);
70
71 $location = get_location();
72 header ("Location: $location/folders.php?success=create");
73
74 ?>