* @copyright © 1999-2006 The SquirrelMail Project Team
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id$
* @package squirrelmail
* @see folders.php
*/
/**
* Helper function for the functions below; checks if the user entered
* folder name is valid according to the IMAP standard. If not, it
* bails out with an error and cleanly terminates the IMAP connection.
*/
function folders_checkname($imapConnection, $folder_name, $delimiter)
{
if (substr_count($folder_name, '"') || substr_count($folder_name, "\\") ||
substr_count($folder_name, $delimiter) || ($folder_name == '')) {
global $color;
error_box(_("Illegal folder name.") . "
\n" .
sprintf(_("The name may not contain any of the following: %s"), '" \\ '.$delimiter.'')
. "
\n" .
_("Please select a different name.").
'
'.
_("Click here to go back") . '.', $color);
sqimap_logout($imapConnection);
exit;
}
}
/**
* Called from folders.php to create a new folder.
*/
function folders_create ($imapConnection, $delimiter, $folder_name, $subfolder, $contain_subs)
{
folders_checkname($imapConnection, $folder_name, $delimiter);
global $folder_prefix;
$folder_name = imap_utf7_encode_local($folder_name);
if ( ! empty($contain_subs) ) {
$folder_name = $folder_name . $delimiter;
}
if ($folder_prefix && (substr($folder_prefix, -1) != $delimiter)) {
$folder_prefix = $folder_prefix . $delimiter;
}
if ($folder_prefix && (substr($subfolder, 0, strlen($folder_prefix)) != $folder_prefix)) {
$subfolder_orig = $subfolder;
$subfolder = $folder_prefix . $subfolder;
} else {
$subfolder_orig = $subfolder;
}
if (trim($subfolder_orig) == '') {
sqimap_mailbox_create ($imapConnection, $folder_prefix.$folder_name, '');
} else {
sqimap_mailbox_create ($imapConnection, $subfolder.$delimiter.$folder_name, '');
}
return;
}
/**
* Called from folders.php, given a folder name, ask the user what this
* folder should be renamed to.
*/
function folders_rename_getname ($imapConnection, $delimiter, $old) {
global $color,$default_folder_prefix;
if ( $old == '' ) {
plain_error_message(_("You have not selected a folder to rename. Please do so.").
'
'._("Click here to go back").'.', $color);
sqimap_logout($imapConnection);
exit;
}
if (substr($old, strlen($old) - strlen($delimiter)) == $delimiter) {
$isfolder = TRUE;
$old = substr($old, 0, strlen($old) - 1);
} else {
$isfolder = FALSE;
}
$old = imap_utf7_decode_local($old);
if (strpos($old, $delimiter)) {
$old_name = substr($old, strrpos($old, $delimiter)+1, strlen($old));
// hide default prefix (INBOX., mail/ or other)
$quoted_prefix=preg_quote($default_folder_prefix,'/');
$prefix_length=(preg_match("/^$quoted_prefix/",$old) ? strlen($default_folder_prefix) : 0);
if ($prefix_length>strrpos($old, $delimiter)) {
$old_parent = '';
} else {
$old_parent = substr($old, $prefix_length, (strrpos($old, $delimiter)-$prefix_length))
. ' ' . $delimiter;
}
} else {
$old_name = $old;
$old_parent = '';
}
echo '
' .
html_tag( 'table', '', 'center', '', 'width="95%" border="0"' ) .
html_tag( 'tr',
html_tag( 'td', '' . _("Rename a folder") . '', 'center', $color[0] )
) .
html_tag( 'tr' ) .
html_tag( 'td', '', 'center', $color[4] ) .
addForm('folders.php').
addHidden('smaction', 'rename').
_("New name:").
'
' . htmlspecialchars($old_parent) . '' .
addInput('new_name', $old_name, 25) . '
' . "\n";
if ( $isfolder ) {
echo addHidden('isfolder', 'true');
}
echo addHidden('orig', $old).
addHidden('old_name', $old_name).
'\n".
'\n".
'
';
echo "\n\n\n\n