6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * Creates folders on the IMAP server.
10 * Called from folders.php
15 /* Path for SquirrelMail required files. */
16 define('SM_PATH','../');
18 /* SquirrelMail required files. */
19 require_once(SM_PATH
. 'include/validate.php');
20 require_once(SM_PATH
. 'functions/global.php');
21 require_once(SM_PATH
. 'functions/imap.php');
22 require_once(SM_PATH
. 'functions/display_messages.php');
24 /* get globals we may need */
25 sqgetGlobalVar('key', $key, SQ_COOKIE
);
26 sqgetGlobalVar('username', $username, SQ_SESSION
);
27 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION
);
28 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
29 sqgetGlobalVar('folder_name', $folder_name, SQ_POST
);
30 sqgetGlobalVar('subfolder', $subfolder, SQ_POST
);
31 sqgetGlobalVar('contain_subs', $contain_subs, SQ_POST
);
32 /* end of get globals */
34 $folder_name = trim($folder_name);
36 if (substr_count($folder_name, '"') ||
substr_count($folder_name, "\\") ||
37 substr_count($folder_name, $delimiter) ||
($folder_name == '')) {
38 displayPageHeader($color, 'None');
40 plain_error_message(_("Illegal folder name. Please select a different name.").
41 '<BR><A HREF="../src/folders.php">'._("Click here to go back").'</A>.', $color);
46 $folder_name = imap_utf7_encode_local($folder_name);
48 if (isset($contain_subs) && $contain_subs ) {
49 $folder_name = $folder_name . $delimiter;
52 if ($folder_prefix && (substr($folder_prefix, -1) != $delimiter)) {
53 $folder_prefix = $folder_prefix . $delimiter;
55 if ($folder_prefix && (substr($subfolder, 0, strlen($folder_prefix)) != $folder_prefix)){
56 $subfolder_orig = $subfolder;
57 $subfolder = $folder_prefix . $subfolder;
59 $subfolder_orig = $subfolder;
62 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
64 if (trim($subfolder_orig) == '') {
65 sqimap_mailbox_create ($imapConnection, $folder_prefix.$folder_name, '');
67 sqimap_mailbox_create ($imapConnection, $subfolder.$delimiter.$folder_name, '');
70 sqimap_logout($imapConnection);
72 $location = get_location();
73 header ("Location: $location/folders.php?success=create");