6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * Deltes folders from the IMAP server.
10 * Called from the 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/imap.php');
21 require_once(SM_PATH
. 'functions/array.php');
22 require_once(SM_PATH
. 'functions/tree.php');
23 require_once(SM_PATH
. 'functions/display_messages.php');
27 * $mailbox - selected mailbox from the form
31 $username = $_SESSION['username'];
32 $key = $_COOKIE['key'];
33 $delimiter = $_SESSION['delimiter'];
34 $onetimepad = $_SESSION['onetimepad'];
36 $mailbox = $_POST['mailbox'];
41 displayPageHeader($color, 'None');
42 echo "<html><body bgcolor=$color[4]>";
43 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);
48 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
49 $boxes = sqimap_mailbox_list ($imap_stream);
50 global $delete_folder;
52 if (substr($mailbox, -1) == $delimiter)
53 $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1);
55 $mailbox_no_dm = $mailbox;
57 /** lets see if we CAN move folders to the trash.. otherwise,
58 ** just delete them **/
60 /* Courier IMAP doesn't like subfolders of Trash */
61 if (strtolower($imap_server_type) == "courier") {
62 $can_move_to_trash = false;
65 /* If global options say we can't move it into Trash */
66 else if(isset($delete_folder) && $delete_folder == true) {
67 $can_move_to_trash = false;
70 /* If it's already a subfolder of trash, we'll have to delete it */
71 else if(eregi("^".$trash_folder.".+", $mailbox)) {
73 $can_move_to_trash = false;
77 /* Otherwise, check if trash folder exits and support sub-folders */
79 for ($i = 0; $i < count($boxes); $i++
) {
80 if ($boxes[$i]["unformatted"] == $trash_folder) {
81 $can_move_to_trash = !in_array('noinferiors', $boxes[$i]['flags']);
86 /** First create the top node in the tree **/
87 for ($i = 0;$i < count($boxes);$i++
) {
88 if (($boxes[$i]["unformatted-dm"] == $mailbox) && (strlen($boxes[$i]["unformatted-dm"]) == strlen($mailbox))) {
89 $foldersTree[0]["value"] = $mailbox;
90 $foldersTree[0]["doIHaveChildren"] = false;
94 /* Now create the nodes for subfolders of the parent folder
95 You can tell that it is a subfolder by tacking the mailbox delimiter
96 on the end of the $mailbox string, and compare to that. */
98 for ($i = 0;$i < count($boxes);$i++
) {
99 if (substr($boxes[$i]["unformatted"], 0, strlen($mailbox_no_dm . $delimiter)) == ($mailbox_no_dm . $delimiter)) {
100 addChildNodeToTree($boxes[$i]["unformatted"], $boxes[$i]["unformatted-dm"], $foldersTree);
103 /* simpleWalkTreePre(0, $foldersTree); */
105 /** Lets start removing the folders and messages **/
106 if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/
107 walkTreeInPostOrderCreatingFoldersUnderTrash(0, $imap_stream, $foldersTree, $mailbox);
108 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
109 } else { /** if they do NOT wish to move messages to the trash (or cannot)**/
110 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
113 /** Log out this session **/
114 sqimap_logout($imap_stream);
116 $location = get_location();
117 header ("Location: $location/folders.php?success=delete");
119 echo "<BR><BR><BR><CENTER><B>";
120 echo _("Folder Deleted!");
122 echo _("The folder has been successfully deleted.");
123 echo "<BR><A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>";
124 echo _("Click here");
126 echo _("to continue.");
129 echo "</BODY></HTML>";