Source for file folder_manip.php
Documentation is available at folder_manip.php
* Functions for IMAP folder manipulation:
* (un)subscribe, create, rename, delete.
* @author Thijs Kinkhorst <kink at squirrelmail.org>
* @copyright © 1999-2006 The SquirrelMail Project Team
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: folder_manip.php,v 1.16 2006/08/09 18:01:22 stevetruckstuff Exp $
* 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.
substr_count($folder_name, $delimiter) ||
($folder_name ==
'')) {
global $color, $oTemplate;
error_box(_("Illegal folder name.") .
"<br />\n" .
sprintf(_("The name may not contain any of the following: %s"), '<tt>" \\ '.
$delimiter.
'</tt>')
_("Please select a different name.").
'<br /><a href="folders.php">'.
_("Click here to go back") .
'</a>.');
$oTemplate->display('footer.tpl');
* Called from folders.php to create a new folder.
* @param stream $imapConnection imap connection resource
* @param string $delimiter delimiter
* @param string $folder_name new folder name
* @param string $subfolder folder that stores new folder
* @param string $contain_subs if not empty, creates folder that can store subfolders
function folders_create ($imapConnection, $delimiter, $folder_name, $subfolder, $contain_subs)
if ( ! empty($contain_subs) ) {
$folder_type =
'noselect';
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;
$subfolder_orig =
$subfolder;
if (trim($subfolder_orig) ==
'') {
* Called from folders.php, given a folder name, ask the user what this
* folder should be renamed to.
'<br /><a href="../src/folders.php">'.
_("Click here to go back").
'</a>.', $color);
$oTemplate->display('footer.tpl');
if (strpos($old, $delimiter)) {
// 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 =
substr($old, $prefix_length, (strrpos($old, $delimiter)-
$prefix_length))
$oTemplate->assign('dialog_type', 'rename');
$oTemplate->assign('is_folder', $isfolder);
$oTemplate->display('folder_manip_dialog.tpl');
$oTemplate->display('footer.tpl');
* Given an old and new folder name, renames the folder.
if ($old_name !=
$new_name) {
if (strpos($orig, $delimiter)) {
$newone =
$old_dir .
$delimiter .
$new_name;
// Renaming a folder doesn't rename the folder but leaves you unsubscribed
// at least on Cyrus IMAP servers.
$newone =
$newone.
$delimiter;
$orig =
$orig.
$delimiter;
* Presents a confirmation dialog to the user asking whether they're
* sure they want to delete this folder.
if ($folder_name ==
'') {
'<br /><a href="../src/folders.php">'.
_("Click here to go back").
'</a>.', $color);
$oTemplate->display('footer.tpl');
// hide default folder prefix (INBOX., mail/ or other)
$quoted_prefix =
preg_quote($default_folder_prefix,'/');
$prefix_length =
(preg_match("/^$quoted_prefix/",$visible_folder_name) ?
strlen($default_folder_prefix) :
0);
$visible_folder_name =
substr($visible_folder_name,$prefix_length);
$oTemplate->assign('dialog_type', 'delete');
$oTemplate->assign('visible_folder_name', htmlspecialchars($visible_folder_name));
$oTemplate->display('folder_manip_dialog.tpl');
$oTemplate->display('footer.tpl');
* Given a folder, moves it to trash (and all subfolders of it too).
include(SM_PATH .
'functions/tree.php');
if (substr($folder_name, -
1) ==
$delimiter) {
$folder_name_no_dm =
substr($folder_name, 0, strlen($folder_name) -
1);
$folder_name_no_dm =
$folder_name;
/** lets see if we CAN move folders to the trash.. otherwise,
if ($delete_folder ||
eregi('^'.
$trash_folder.
'.+', $folder_name) ) {
$can_move_to_trash =
FALSE;
/* Otherwise, check if trash folder exits and support sub-folders */
foreach($boxes as $box) {
if ($box['unformatted'] ==
$trash_folder) {
$can_move_to_trash =
!in_array('noinferiors', $box['flags']);
/** First create the top node in the tree **/
foreach($boxes as $box) {
if (($box['unformatted-dm'] ==
$folder_name) &&
(strlen($box['unformatted-dm']) ==
strlen($folder_name))) {
$foldersTree[0]['value'] =
$folder_name;
$foldersTree[0]['doIHaveChildren'] =
false;
/* Now create the nodes for subfolders of the parent folder
You can tell that it is a subfolder by tacking the mailbox delimiter
on the end of the $folder_name string, and compare to that. */
foreach($boxes as $box) {
if (substr($box['unformatted'], 0, strlen($folder_name_no_dm .
$delimiter)) ==
($folder_name_no_dm .
$delimiter)) {
/** Lets start removing the folders and messages **/
if (($move_to_trash ==
true) &&
($can_move_to_trash ==
true)) { /** if they wish to move messages to the trash **/
} else { /** if they do NOT wish to move messages to the trash (or cannot)**/
* Given an array of folder_names, subscribes to each of them.
global $color, $oTemplate;
if (count($folder_names) ==
0 ||
$folder_names[0] ==
'') {
'<br /><a href="../src/folders.php">'.
_("Click here to go back").
'</a>.', $color);
$oTemplate->display('footer.tpl');
if($no_list_for_subscribe &&
$imap_server_type ==
'cyrus') {
/* Cyrus, atleast, does not typically allow subscription to
* nonexistent folders (this is an optional part of IMAP),
* lets catch it here and report back cleanly. */
'<br /><a href="../src/folders.php">'.
_("Click here to go back").
'</a>.', $color);
foreach ( $folder_names as $folder_name ) {
* Given a list of folder names, unsubscribes from each of them.
global $color, $oTemplate;
if (count($folder_names) ==
0 ||
$folder_names[0] ==
'') {
'<br /><a href="../src/folders.php">'.
_("Click here to go back").
'</a>.', $color);
$oTemplate->display('footer.tpl');
foreach ( $folder_names as $folder_name ) {
Documentation generated on Sat, 07 Oct 2006 16:11:05 +0300 by phpDocumentor 1.3.0RC6