- Add ability to the Filters plugin to filter on Message Body, or both
the Headers and the Message Body.
- Update the message copy and move functions to allow for error handling.
- - Fix the filter plugin from halting the login process when copying errors occur
+ - Fix the filter plugin from halting the login process when copying errors
+ occur.
+ - Clean up the folder management (create, rename, subscribe) code.
Version 1.5.0
--------------------
--- /dev/null
+<?php
+
+/**
+* folder_manip.php
+*
+* Copyright (c) 1999-2005 The SquirrelMail Project Team
+* Licensed under the GNU GPL. For full terms see the file COPYING.
+*
+* Functions for IMAP folder manipulation:
+* (un)subscribe, create, rename, delete.
+*
+* @version $Id$
+* @package squirrelmail
+* @see folders.php
+* @author Thijs Kinkhorst - kink@squirrelmail.org
+*/
+
+
+/**
+ * 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;
+ plain_error_message(_("Illegal folder name. Please select a different name.").
+ '<br /><a href="../src/folders.php">'._("Click here to go back").'</a>.', $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;
+
+ if ( $old == '' ) {
+ plain_error_message(_("You have not selected a folder to rename. Please do so.").
+ '<br /><a href="../src/folders.php">'._("Click here to go back").'</a>.', $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));
+ $old_parent = substr($old, 0, strrpos($old, $delimiter));
+ } else {
+ $old_name = $old;
+ $old_parent = '';
+ }
+
+ echo '<br />' .
+ html_tag( 'table', '', 'center', '', 'width="95%" border="0"' ) .
+ html_tag( 'tr',
+ html_tag( 'td', '<b>' . _("Rename a folder") . '</b>', 'center', $color[0] )
+ ) .
+ html_tag( 'tr' ) .
+ html_tag( 'td', '', 'center', $color[4] ) .
+ addForm('folders.php').
+ addHidden('smaction', 'rename').
+ _("New name:").
+ '<br /><b>' . htmlspecialchars($old_parent) . ' ' . htmlspecialchars($delimiter) . '</b>' .
+ addInput('new_name', $old_name, 25) . '<br /><br />' . "\n";
+ if ( $isfolder ) {
+ echo addHidden('isfolder', 'true');
+ }
+ echo addHidden('orig', $old).
+ addHidden('old_name', $old_name).
+ '<input type="submit" value="'._("Rename")."\" />\n".
+ '<input type="submit" name="cancelbutton" value="'._("Cancel")."\" />\n".
+ '</form><br /></td></tr></table>';
+ echo "\n\n</body></html>";
+
+ sqimap_logout($imapConnection);
+ exit;
+}
+
+/**
+ * Given an old and new folder name, renames the folder.
+ */
+function folders_rename_do($imapConnection, $delimiter, $orig, $old_name, $new_name)
+{
+ folders_checkname($imapConnection, $new_name, $delimiter);
+
+ $orig = imap_utf7_encode_local($orig);
+ $old_name = imap_utf7_encode_local($old_name);
+ $new_name = imap_utf7_encode_local($new_name);
+
+ if ($old_name != $new_name) {
+
+ if (strpos($orig, $delimiter)) {
+ $old_dir = substr($orig, 0, strrpos($orig, $delimiter));
+ } else {
+ $old_dir = '';
+ }
+
+ if ($old_dir != '') {
+ $newone = $old_dir . $delimiter . $new_name;
+ } else {
+ $newone = $new_name;
+ }
+
+ // Renaming a folder doesn't rename the folder but leaves you unsubscribed
+ // at least on Cyrus IMAP servers.
+ if (isset($isfolder)) {
+ $newone = $newone.$delimiter;
+ $orig = $orig.$delimiter;
+ }
+ sqimap_mailbox_rename( $imapConnection, $orig, $newone );
+
+ }
+
+ return;
+}
+
+/**
+ * Presents a confirmation dialog to the user asking whether they're
+ * sure they want to delete this folder.
+ */
+function folders_delete_ask ($imapConnection, $folder_name)
+{
+ global $color;
+
+ if ($folder_name == '') {
+ plain_error_message(_("You have not selected a folder to delete. Please do so.").
+ '<br /><a href="../src/folders.php">'._("Click here to go back").'</a>.', $color);
+ exit;
+ }
+
+ echo '<br />' .
+ html_tag( 'table', '', 'center', '', 'width="95%" border="0"' ) .
+ html_tag( 'tr',
+ html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[0] )
+ ) .
+ html_tag( 'tr' ) .
+ html_tag( 'td', '', 'center', $color[4] ) .
+ sprintf(_("Are you sure you want to delete %s?"),
+ str_replace(array(' ','<','>'),array(' ','<','>'),
+ imap_utf7_decode_local($folder_name))).
+ addForm('folders.php', 'post')."<p>\n".
+ addHidden('smaction', 'delete').
+ addHidden('folder_name', $folder_name).
+ addSubmit(_("Yes"), 'confirmed').
+ addSubmit(_("No"), 'cancelbutton').
+ '</p></form><br /></td></tr></table>';
+
+ echo "\n\n</body></html>";
+
+ sqimap_logout($imapConnection);
+ exit;
+}
+
+/**
+ * Given a folder, moves it to trash (and all subfolders of it too).
+ */
+function folders_delete_do ($imapConnection, $delimiter, $folder_name)
+{
+ require_once(SM_PATH . 'functions/tree.php');
+
+ $boxes = sqimap_mailbox_list ($imapConnection);
+
+ global $delete_folder, $imap_server_type, $trash_folder, $move_to_trash;
+
+ if (substr($folder_name, -1) == $delimiter) {
+ $folder_name_no_dm = substr($folder_name, 0, strlen($folder_name) - 1);
+ } else {
+ $folder_name_no_dm = $folder_name;
+ }
+
+ /** lets see if we CAN move folders to the trash.. otherwise,
+ ** just delete them **/
+
+ /* Courier IMAP doesn't like subfolders of Trash
+ * If global options say we can't move it into Trash
+ * If it's already a subfolder of trash, we'll have to delete it */
+ if (strtolower($imap_server_type) == 'courier' ||
+ (isset($delete_folder) && $delete_folder) ||
+ eregi('^'.$trash_folder.'.+', $folder_name) )
+ {
+ $can_move_to_trash = FALSE;
+ }
+ /* Otherwise, check if trash folder exits and support sub-folders */
+ else {
+ 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;
+ continue;
+ }
+ }
+
+ /* 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)) {
+ addChildNodeToTree($box['unformatted'], $box['unformatted-dm'], $foldersTree);
+ }
+ }
+
+ /** 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 **/
+ walkTreeInPostOrderCreatingFoldersUnderTrash(0, $imapConnection, $foldersTree, $folder_name);
+ walkTreeInPreOrderDeleteFolders(0, $imapConnection, $foldersTree);
+ } else { /** if they do NOT wish to move messages to the trash (or cannot)**/
+ walkTreeInPreOrderDeleteFolders(0, $imapConnection, $foldersTree);
+ }
+
+ return;
+}
+
+/**
+ * Given an array of folder_names, subscribes to each of them.
+ */
+function folders_subscribe($imapConnection, $folder_names)
+{
+ global $color;
+
+ if (count($folder_names) == 0 || $folder_names[0] == '') {
+ plain_error_message(_("You have not selected a folder to subscribe. Please do so.").
+ '<br /><a href="../src/folders.php">'._("Click here to go back").'</a>.', $color);
+ sqimap_logout($imapConnection);
+ exit;
+ }
+
+ global $no_list_for_subscribe, $imap_server_type;
+
+ 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. */
+ if(!sqimap_mailbox_exists($imapConnection, $folder_names[0])) {
+ plain_error_message(_("Subscription Unsuccessful - Folder does not exist.").
+ '<br /><a href="../src/folders.php">'._("Click here to go back").'</a>.', $color);
+ sqimap_logout($imapConnection);
+ exit;
+
+ }
+ }
+ foreach ( $folder_names as $folder_name ) {
+ sqimap_subscribe ($imapConnection, $folder_name);
+ }
+
+ return;
+}
+
+/**
+ * Given a list of folder names, unsubscribes from each of them.
+ */
+function folders_unsubscribe($imapConnection, $folder_names)
+{
+ global $color;
+
+ if (count($folder_names) == 0 || $folder_names[0] == '') {
+ plain_error_message(_("You have not selected a folder to unsubscribe. Please do so.").
+ '<br /><a href="../src/folders.php">'._("Click here to go back").'</a>.', $color);
+ sqimap_logout($imapConnection);
+ exit;
+ }
+
+ foreach ( $folder_names as $folder_name ) {
+ sqimap_unsubscribe ($imapConnection, $folder_name);
+ }
+
+ return;
+}
+
+
+?>
/* SquirrelMail required files. */
require_once(SM_PATH . 'include/validate.php');
require_once(SM_PATH . 'functions/imap.php');
+require_once(SM_PATH . 'functions/folder_manip.php');
require_once(SM_PATH . 'functions/plugin.php');
require_once(SM_PATH . 'functions/html.php');
require_once(SM_PATH . 'functions/forms.php');
sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
-sqgetGlobalVar('success', $success, SQ_GET);
+sqgetGlobalVar('smaction', $action, SQ_POST);
/* end of get globals */
html_tag( 'tr' ) .
html_tag( 'td', '', 'center', $color[4] );
-if ( isset($success) && $success ) {
+$imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
- $td_str = '<b>';
+/* switch to the right function based on what the user selected */
+if ( sqgetGlobalVar('smaction', $action, SQ_POST) ) {
- switch ($success)
+ switch ($action)
{
- case 'subscribe':
- $td_str .= _("Subscribed successfully!");
+ case 'create':
+ sqgetGlobalVar('folder_name', $folder_name, SQ_POST);
+ sqgetGlobalVar('subfolder', $subfolder, SQ_POST);
+ sqgetGlobalVar('contain_subs', $contain_subs, SQ_POST);
+ folders_create($imapConnection, $delimiter, $folder_name, $subfolder, $contain_subs);
+ $td_str = _("Created folder successfully.");
break;
- case 'unsubscribe':
- $td_str .= _("Unsubscribed successfully!");
+ case 'rename':
+ if ( sqgetGlobalVar('cancelbutton', $dummy, SQ_POST) ) {
+ break;
+ }
+ if ( ! sqgetGlobalVar('new_name', $new_name, SQ_POST) ) {
+ sqgetGlobalVar('old_name', $old_name, SQ_POST);
+ folders_rename_getname($imapConnection, $delimiter, $old_name);
+ } else {
+ sqgetGlobalVar('orig', $orig, SQ_POST);
+ sqgetGlobalVar('old_name', $old_name, SQ_POST);
+ folders_rename_do($imapConnection, $delimiter, $orig, $old_name, $new_name);
+ $td_str = _("Renamed successfully!");
+ }
break;
case 'delete':
- $td_str .= _("Deleted folder successfully!");
- break;
- case 'create':
- $td_str .= _("Created folder successfully!");
+ if ( sqgetGlobalVar('cancelbutton', $dummy, SQ_POST) ) {
+ break;
+ }
+ sqgetGlobalVar('folder_name', $folder_name, SQ_POST);
+ if ( sqgetGlobalVar('confirmed', $dummy, SQ_POST) ) {
+ folders_delete_do($imapConnection, $delimiter, $folder_name);
+ $td_str = _("Deleted folder successfully.");
+ } else {
+ folders_delete_ask($imapConnection, $folder_name);
+ }
break;
- case 'rename':
- $td_str .= _("Renamed successfully!");
+ case 'subscribe':
+ sqgetGlobalVar('folder_names', $folder_names, SQ_POST);
+ folders_subscribe($imapConnection, $folder_names);
+ $td_str = _("Subscribed successfully.");
break;
- case 'subscribe-doesnotexist':
- $td_str .= _("Subscription Unsuccessful - Folder does not exist.");
+ case 'unsubscribe':
+ sqgetGlobalVar('folder_names', $folder_names, SQ_POST);
+ folders_unsubscribe($imapConnection, $folder_names);
+ $td_str = _("Unsubscribed successfully.");
break;
- }
-
- $td_str .= '</b><br />';
-
+ }
echo html_tag( 'table',
html_tag( 'tr',
- html_tag( 'td', $td_str .
+ html_tag( 'td', '<b>' . $td_str . "</b><br />\n" .
'<a href="../src/left_main.php" target="left">' .
_("refresh folder list") . '</a>' ,
'center' )
echo "\n<br />";
-$imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
$boxes = sqimap_mailbox_list($imapConnection,true);
/** CREATING FOLDERS **/
) .
html_tag( 'tr' ) .
html_tag( 'td', '', 'center', $color[0] ) .
- addForm('folders_create.php', 'post', 'cf').
+ addForm('folders.php', 'post', 'cf').
+ addHidden('smaction','create').
addInput('folder_name', '', 25).
"<br />\n". _("as a subfolder of"). '<br />'.
"<tt><select name=\"subfolder\">\n";
html_tag( 'tr' ) .
html_tag( 'td', '', 'center', $color[0] );
+/* show only if we have folders to rename */
if ($count_special_folders < count($boxes)) {
- echo addForm('folders_rename_getname.php')
- . "<tt><select name=\"old\">\n"
+ echo addForm('folders.php')
+ . addHidden('smaction', 'rename')
+ . "<tt><select name=\"old_name\">\n"
. ' <option value="">[ ' . _("Select a folder") . " ]</option>\n";
// use existing IMAP connection, we have no special values to show,
} else {
echo _("No folders found") . '<br /><br /></td></tr>';
}
-$boxes_sub = $boxes;
echo html_tag( 'tr',
html_tag( 'td', ' ', 'left', $color[4] )
html_tag( 'tr' ) .
html_tag( 'td', '', 'center', $color[0] );
+/* show only if we have folders to delete */
if ($count_special_folders < count($boxes)) {
- echo addForm('folders_delete.php')
- . "<tt><select name=\"mailbox\">\n"
+ echo addForm('folders.php')
+ . addHidden('smaction', 'delete')
+ . "<tt><select name=\"folder_name\">\n"
. ' <option value="">[ ' . _("Select a folder") . " ]</option>\n";
// send NULL for the flag - ALL folders are eligible for delete (except what we've got in skiplist)
html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
if ($count_special_folders < count($boxes)) {
- echo addForm('folders_subscribe.php?method=unsub')
- . "<tt><select name=\"mailbox[]\" multiple=\"multiple\" size=\"8\">\n";
- for ($i = 0; $i < count($boxes); $i++) {
+ echo addForm('folders.php')
+ . addHidden('smaction', 'unsubscribe')
+ . "<tt><select name=\"folder_names[]\" multiple=\"multiple\" size=\"8\">\n";
+ foreach ( $boxes as $box ) {
$use_folder = true;
- if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
- ($boxes[$i]["unformatted"] != $trash_folder) &&
- ($boxes[$i]["unformatted"] != $sent_folder) &&
- ($boxes[$i]["unformatted"] != $draft_folder)) {
- $box = htmlspecialchars($boxes[$i]["unformatted-dm"]);
- $box2 = str_replace(' ', ' ',
- htmlspecialchars(imap_utf7_decode_local($boxes[$i]["unformatted-disp"])));
- echo " <option value=\"$box\">$box2</option>\n";
+ if ((strtolower($box["unformatted"]) != "inbox") &&
+ ($box['unformatted'] != $trash_folder) &&
+ ($box['unformatted'] != $sent_folder) &&
+ ($box['unformatted'] != $draft_folder)) {
+ $box_enc = htmlspecialchars($box['unformatted-dm']);
+ $box_disp = str_replace(' ', ' ',
+ htmlspecialchars(imap_utf7_decode_local($box["unformatted-disp"])));
+ echo " <option value=\"$box_enc\">$box_disp</option>\n";
}
}
echo "</select></tt><br /><br />\n"
} else {
echo _("No folders were found to unsubscribe from!") . '</td>';
}
- $boxes_sub = $boxes;
/** SUBSCRIBE TO FOLDERS **/
echo html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
if(!$no_list_for_subscribe) {
- $boxes_all = sqimap_mailbox_list_all ($imapConnection);
-
- $box = '';
- $box2 = '';
- for ($i = 0, $q = 0; $i < count($boxes_all); $i++) {
- $use_folder = true;
- for ($p = 0; $p < count ($boxes); $p++) {
- if ($boxes_all[$i]['unformatted'] == $boxes[$p]['unformatted']) {
- $use_folder = false;
- continue;
- } else if ($boxes_all[$i]['unformatted-dm'] == $folder_prefix) {
- $use_folder = false;
+ $boxes_all = sqimap_mailbox_list_all ($imapConnection);
+
+ $subboxes = array();
+ // here we filter out all boxes we're already subscribed to,
+ // so we keep only the unsubscribed ones.
+ foreach ($boxes_all as $box_a) {
+
+ $use_folder = true;
+ foreach ( $boxes as $box ) {
+ if ($box_a['unformatted'] == $box['unformatted'] ||
+ $box_a['unformatted-dm'] == $folder_prefix ) {
+ $use_folder = false;
+ }
+ }
+
+ if ($use_folder == true) {
+ $box_enc = htmlspecialchars($box_a['unformatted-dm']);
+ $box_disp = htmlspecialchars(imap_utf7_decode_local($box_a['unformatted-disp']));
+ $subboxes[$box_enc] = $box_disp;
}
}
- if ($use_folder == true) {
- $box[$q] = htmlspecialchars($boxes_all[$i]['unformatted-dm']);
- $box2[$q] = htmlspecialchars(imap_utf7_decode_local($boxes_all[$i]['unformatted-disp']));
- $q++;
- }
- }
- if ($box && $box2) {
- echo addForm('folders_subscribe.php?method=sub')
- . '<tt><select name="mailbox[]" multiple="multiple" size="8">';
+
+ if ( count($subboxes) > 0 ) {
+ echo addForm('folders.php')
+ . addHidden('smaction', 'subscribe')
+ . '<tt><select name="folder_names[]" multiple="multiple" size="8">';
+
+ foreach($subboxes as $subbox_enc => $subbox_disp) {
+ echo ' <option value="' . $subbox_enc . '">'.$subbox_disp."</option>\n";
+ }
- for ($q = 0; $q < count($box); $q++) {
- echo ' <option value="' . $box[$q] . '">'.$box2[$q]."</option>\n";
+ echo '</select></tt><br /><br />'
+ . '<input type="submit" value="'. _("Subscribe") . "\" />\n"
+ . "</form></td></tr></table><br />\n";
+ } else {
+ echo _("No folders were found to subscribe to.") . '</td></tr></table>';
}
- echo '</select></tt><br /><br />'
- . '<input type="submit" value="'. _("Subscribe") . "\" />\n"
- . "</form></td></tr></table><br />\n";
- } else {
- echo _("No folders were found to subscribe to!") . '</td></tr></table>';
- }
} else {
- /* don't perform the list action -- this is much faster */
- echo addForm('folders_subscribe.php?method=sub')
+ /* don't perform the list action -- this is much faster */
+ echo addForm('folders.php')
+ . addHidden('smaction', 'subscribe')
. _("Subscribe to:") . '<br />'
- . '<tt><input type="text" name="mailbox[]" size="35" />'
+ . '<tt><input type="text" name="folder_names[]" size="35" />'
. '<input type="submit" value="'. _("Subscribe") . "\" />\n"
. "</form></td></tr></table><br />\n";
}
}
do_hook('folders_bottom');
+sqimap_logout($imapConnection);
?>
</td></tr>
</table>
</td></tr>
</table>
-<?php
- sqimap_logout($imapConnection);
-?>
</body></html>
+++ /dev/null
-<?php
-
-/**
- * folders_create.php
- *
- * Copyright (c) 1999-2005 The SquirrelMail Project Team
- * Licensed under the GNU GPL. For full terms see the file COPYING.
- *
- * Creates folders on the IMAP server.
- * Called from folders.php
- *
- * @version $Id$
- * @package squirrelmail
- */
-
-/**
- * Path for SquirrelMail required files.
- * @ignore
- */
-define('SM_PATH','../');
-
-/* SquirrelMail required files. */
-require_once(SM_PATH . 'include/validate.php');
-require_once(SM_PATH . 'functions/global.php');
-require_once(SM_PATH . 'functions/imap.php');
-require_once(SM_PATH . 'functions/display_messages.php');
-
-/* get globals we may need */
-sqgetGlobalVar('key', $key, SQ_COOKIE);
-sqgetGlobalVar('username', $username, SQ_SESSION);
-sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
-sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
-sqgetGlobalVar('folder_name', $folder_name, SQ_POST);
-sqgetGlobalVar('subfolder', $subfolder, SQ_POST);
-sqgetGlobalVar('contain_subs', $contain_subs, SQ_POST);
-/* end of get globals */
-
-$folder_name = trim($folder_name);
-
-if (substr_count($folder_name, '"') || substr_count($folder_name, "\\") ||
- substr_count($folder_name, $delimiter) || ($folder_name == '')) {
- displayPageHeader($color, 'None');
-
- plain_error_message(_("Illegal folder name. Please select a different name.").
- '<br /><a href="../src/folders.php">'._("Click here to go back").'</a>.', $color);
-
- exit;
-}
-
-$folder_name = imap_utf7_encode_local($folder_name);
-
-if (isset($contain_subs) && $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;
-}
-
-$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
-
-if (trim($subfolder_orig) == '') {
- sqimap_mailbox_create ($imapConnection, $folder_prefix.$folder_name, '');
-} else {
- sqimap_mailbox_create ($imapConnection, $subfolder.$delimiter.$folder_name, '');
-}
-
-sqimap_logout($imapConnection);
-
-$location = get_location();
-header ("Location: $location/folders.php?success=create");
-
-?>
\ No newline at end of file
+++ /dev/null
-<?php
-
-/**
- * folders_delete.php
- *
- * Copyright (c) 1999-2005 The SquirrelMail Project Team
- * Licensed under the GNU GPL. For full terms see the file COPYING.
- *
- * Deletes folders from the IMAP server.
- * Called from the folders.php
- *
- * @version $Id$
- * @package squirrelmail
- */
-
-/**
- * Path for SquirrelMail required files.
- * @ignore
- */
-define('SM_PATH','../');
-
-/* SquirrelMail required files. */
-require_once(SM_PATH . 'include/validate.php');
-require_once(SM_PATH . 'functions/global.php');
-require_once(SM_PATH . 'functions/imap.php');
-require_once(SM_PATH . 'functions/tree.php');
-require_once(SM_PATH . 'functions/display_messages.php');
-require_once(SM_PATH . 'functions/html.php');
-require_once(SM_PATH . 'functions/forms.php');
-
-/*
- * Incoming values:
- * $mailbox - selected mailbox from the form
- */
-
-/* globals */
-sqgetGlobalVar('key', $key, SQ_COOKIE);
-sqgetGlobalVar('username', $username, SQ_SESSION);
-sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
-sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
-sqgetGlobalVar('mailbox', $mailbox, SQ_POST);
-/* end globals */
-
-if ($mailbox == '') {
- displayPageHeader($color, 'None');
-
- plain_error_message(_("You have not selected a folder to delete. Please do so.").
- '<br /><a href="../src/folders.php">'._("Click here to go back").'</a>.', $color);
- exit;
-}
-
-if ( sqgetGlobalVar('backingout', $tmp, SQ_POST) ) {
- $location = get_location();
- header ("Location: $location/folders.php");
- exit;
-}
-
-if( !sqgetGlobalVar('confirmed', $tmp, SQ_POST) ) {
- displayPageHeader($color, 'None');
-
- echo '<br />' .
- html_tag( 'table', '', 'center', '', 'width="95%" border="0"' ) .
- html_tag( 'tr',
- html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[0] )
- ) .
- html_tag( 'tr' ) .
- html_tag( 'td', '', 'center', $color[4] ) .
- sprintf(_("Are you sure you want to delete %s?"), str_replace(array(' ','<','>'),array(' ','<','>'),imap_utf7_decode_local($mailbox))).
- addForm('folders_delete.php', 'post')."<p>\n".
- addHidden('mailbox', $mailbox).
- addSubmit(_("Yes"), 'confirmed').
- addSubmit(_("No"), 'backingout').
- '</p></form><br /></td></tr></table>';
-
- exit;
-}
-
-$imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
-
-$boxes = sqimap_mailbox_list ($imap_stream);
-$numboxes = count($boxes);
-
-global $delete_folder;
-
-if (substr($mailbox, -1) == $delimiter)
- $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1);
-else
- $mailbox_no_dm = $mailbox;
-
-/** lets see if we CAN move folders to the trash.. otherwise,
- ** just delete them **/
-
-/* Courier IMAP doesn't like subfolders of Trash
- * If global options say we can't move it into Trash
- * If it's already a subfolder of trash, we'll have to delete it */
-if (strtolower($imap_server_type) == 'courier' ||
- (isset($delete_folder) && $delete_folder) ||
- eregi('^'.$trash_folder.'.+', $mailbox) )
-{
- $can_move_to_trash = FALSE;
-}
-
-/* Otherwise, check if trash folder exits and support sub-folders */
-else {
- for ($i = 0; $i < $numboxes; $i++) {
- if ($boxes[$i]['unformatted'] == $trash_folder) {
- $can_move_to_trash = !in_array('noinferiors', $boxes[$i]['flags']);
- }
- }
-}
-
-/** First create the top node in the tree **/
-for ($i = 0; $i < $numboxes; $i++) {
- if (($boxes[$i]['unformatted-dm'] == $mailbox) && (strlen($boxes[$i]['unformatted-dm']) == strlen($mailbox))) {
- $foldersTree[0]['value'] = $mailbox;
- $foldersTree[0]['doIHaveChildren'] = false;
- continue;
- }
-}
-
-/* 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 $mailbox string, and compare to that. */
-for ($i = 0; $i < $numboxes; $i++) {
- if (substr($boxes[$i]['unformatted'], 0, strlen($mailbox_no_dm . $delimiter)) == ($mailbox_no_dm . $delimiter)) {
- addChildNodeToTree($boxes[$i]["unformatted"], $boxes[$i]['unformatted-dm'], $foldersTree);
- }
-}
-
-/** 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 **/
- walkTreeInPostOrderCreatingFoldersUnderTrash(0, $imap_stream, $foldersTree, $mailbox);
- walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
-} else { /** if they do NOT wish to move messages to the trash (or cannot)**/
- walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
-}
-
-/** Log out this session **/
-sqimap_logout($imap_stream);
-
-$location = get_location();
-header ("Location: $location/folders.php?success=delete");
-
-?>
\ No newline at end of file
+++ /dev/null
-<?php
-
-/**
- * folders_rename_do.php
- *
- * Copyright (c) 1999-2005 The SquirrelMail Project Team
- * Licensed under the GNU GPL. For full terms see the file COPYING.
- *
- * Does the actual renaming of files on the IMAP server.
- * Called from the folders.php
- *
- * @version $Id$
- * @package squirrelmail
- */
-
-/**
- * Path for SquirrelMail required files.
- * @ignore
- */
-define('SM_PATH','../');
-
-/* SquirrelMail required files. */
-require_once(SM_PATH . 'include/validate.php');
-require_once(SM_PATH . 'functions/global.php');
-require_once(SM_PATH . 'functions/imap.php');
-require_once(SM_PATH . 'functions/display_messages.php');
-
-/* globals */
-sqgetGlobalVar('key', $key, SQ_COOKIE);
-sqgetGlobalVar('username', $username, SQ_SESSION);
-sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
-sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
-sqgetGlobalVar('orig', $orig, SQ_POST);
-sqgetGlobalVar('old_name', $old_name, SQ_POST);
-sqgetGlobalVar('new_name', $new_name, SQ_POST);
-/* end globals */
-
-$new_name = trim($new_name);
-
-if (substr_count($new_name, '"') || substr_count($new_name, "\\") ||
- substr_count($new_name, $delimiter) || ($new_name == '')) {
- displayPageHeader($color, 'None');
-
- plain_error_message(_("Illegal folder name. Please select a different name.").
- '<br /><a href="../src/folders.php">'._("Click here to go back").'</a>.', $color);
-
- exit;
-}
-
-$orig = imap_utf7_encode_local($orig);
-$old_name = imap_utf7_encode_local($old_name);
-$new_name = imap_utf7_encode_local($new_name);
-
-if ($old_name <> $new_name) {
-
- $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
-
- if (strpos($orig, $delimiter)) {
- $old_dir = substr($orig, 0, strrpos($orig, $delimiter));
- } else {
- $old_dir = '';
- }
-
- if ($old_dir != '') {
- $newone = $old_dir . $delimiter . $new_name;
- } else {
- $newone = $new_name;
- }
-
- // Renaming a folder doesn't rename the folder but leaves you unsubscribed
- // at least on Cyrus IMAP servers.
- if (isset($isfolder)) {
- $newone = $newone.$delimiter;
- $orig = $orig.$delimiter;
- }
- sqimap_mailbox_rename( $imapConnection, $orig, $newone );
-
- // Log out this session
- sqimap_logout($imapConnection);
-
-}
-
-header ('Location: ' . get_location() . '/folders.php?success=rename');
-
-?>
\ No newline at end of file
+++ /dev/null
-<?php
-
-/**
- * folders_rename_getname.php
- *
- * Copyright (c) 1999-2005 The SquirrelMail Project Team
- * Licensed under the GNU GPL. For full terms see the file COPYING.
- *
- * Gets folder names and enables renaming
- * Called from folders.php
- *
- * @version $Id$
- * @package squirrelmail
- */
-
-/**
- * Path for SquirrelMail required files.
- * @ignore
- */
-define('SM_PATH','../');
-
-/* SquirrelMail required files. */
-require_once(SM_PATH . 'include/validate.php');
-require_once(SM_PATH . 'functions/global.php');
-require_once(SM_PATH . 'functions/imap_mailbox.php');
-require_once(SM_PATH . 'functions/html.php');
-require_once(SM_PATH . 'functions/display_messages.php');
-require_once(SM_PATH . 'functions/forms.php');
-
-/* get globals we may need */
-sqgetGlobalVar('key', $key, SQ_COOKIE);
-sqgetGlobalVar('username', $username, SQ_SESSION);
-sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
-sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
-sqgetGlobalVar('old', $old, SQ_POST);
-/* end of get globals */
-
-if ($old == '') {
- displayPageHeader($color, 'None');
-
- plain_error_message(_("You have not selected a folder to rename. Please do so.").
- '<br /><a href="../src/folders.php">'._("Click here to go back").'</a>.', $color);
- 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));
- $old_parent = substr($old, 0, strrpos($old, $delimiter));
-} else {
- $old_name = $old;
- $old_parent = '';
-}
-
-
-displayPageHeader($color, 'None');
-echo '<br />' .
- html_tag( 'table', '', 'center', '', 'width="95%" border="0"' ) .
- html_tag( 'tr',
- html_tag( 'td', '<b>' . _("Rename a folder") . '</b>', 'center', $color[0] )
- ) .
- html_tag( 'tr' ) .
- html_tag( 'td', '', 'center', $color[4] ) .
- addForm('folders_rename_do.php').
- _("New name:").
- '<br /><b>' . htmlspecialchars($old_parent) . ' ' . htmlspecialchars($delimiter) . '</b>' .
- addInput('new_name', $old_name, 25) . '<br />' . "\n";
-if ( $isfolder ) {
- echo addHidden('isfolder', 'true');
-}
-echo addHidden('orig', $old).
- addHidden('old_name', $old_name).
- '<input type="submit" value="'._("Submit")."\" />\n".
- '</form><br /></td></tr></table>';
-
-?>
\ No newline at end of file
+++ /dev/null
-<?php
-
-/**
- * folders_subscribe.php
- *
- * Copyright (c) 1999-2005 The SquirrelMail Project Team
- * Licensed under the GNU GPL. For full terms see the file COPYING.
- *
- * Subscribe and unsubcribe from folders.
- * Called from folders.php
- *
- * @version $Id$
- * @package squirrelmail
- */
-
-/**
- * Path for SquirrelMail required files.
- * @ignore
- */
-define('SM_PATH','../');
-
-/* SquirrelMail required files. */
-require_once(SM_PATH . 'include/validate.php');
-require_once(SM_PATH . 'functions/global.php');
-require_once(SM_PATH . 'functions/imap.php');
-require_once(SM_PATH . 'functions/display_messages.php');
-
-/* globals */
-sqgetGlobalVar('key', $key, SQ_COOKIE);
-sqgetGlobalVar('username', $username, SQ_SESSION);
-sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
-sqgetGlobalVar('method', $method, SQ_GET);
-sqgetGlobalVar('mailbox', $mailbox, SQ_POST);
-/* end globals */
-
-$location = get_location();
-
-if (!isset($mailbox) || !isset($mailbox[0]) || $mailbox[0] == '') {
- header("Location: $location/folders.php");
-
- exit(0);
-}
-
-$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
-
-if ($method == 'sub') {
- 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. */
- if(!sqimap_mailbox_exists($imapConnection, $mailbox[0])) {
- header("Location: $location/folders.php?success=subscribe-doesnotexist");
- sqimap_logout($imapConnection);
- exit(0);
- }
- }
- for ($i=0; $i < count($mailbox); $i++) {
- $mailbox[$i] = trim($mailbox[$i]);
- sqimap_subscribe ($imapConnection, $mailbox[$i]);
- }
- $success = 'subscribe';
-} else {
- for ($i=0; $i < count($mailbox); $i++) {
- $mailbox[$i] = trim($mailbox[$i]);
- sqimap_unsubscribe ($imapConnection, $mailbox[$i]);
- }
- $success = 'unsubscribe';
-}
-
-sqimap_logout($imapConnection);
-header("Location: $location/folders.php?success=$success");
-
-?>
\ No newline at end of file