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
. 'src/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 displayPageHeader($color, 'None');
32 echo "<html><body bgcolor=$color[4]>";
33 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);
38 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
39 $boxes = sqimap_mailbox_list ($imap_stream);
40 global $delimiter, $delete_folder;
42 if (substr($mailbox, -1) == $delimiter)
43 $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1);
45 $mailbox_no_dm = $mailbox;
47 /** lets see if we CAN move folders to the trash.. otherwise,
48 ** just delete them **/
50 /* Courier IMAP doesn't like subfolders of Trash */
51 if (strtolower($imap_server_type) == "courier") {
52 $can_move_to_trash = false;
55 /* If global options say we can't move it into Trash */
56 else if(isset($delete_folder) && $delete_folder == true) {
57 $can_move_to_trash = false;
60 /* If it's already a subfolder of trash, we'll have to delete it */
61 else if(eregi("^".$trash_folder.".+", $mailbox)) {
63 $can_move_to_trash = false;
67 /* Otherwise, check if trash folder exits and support sub-folders */
69 for ($i = 0; $i < count($boxes); $i++
) {
70 if ($boxes[$i]["unformatted"] == $trash_folder) {
71 $can_move_to_trash = !in_array('noinferiors', $boxes[$i]['flags']);
76 /** First create the top node in the tree **/
77 for ($i = 0;$i < count($boxes);$i++
) {
78 if (($boxes[$i]["unformatted-dm"] == $mailbox) && (strlen($boxes[$i]["unformatted-dm"]) == strlen($mailbox))) {
79 $foldersTree[0]["value"] = $mailbox;
80 $foldersTree[0]["doIHaveChildren"] = false;
84 /* Now create the nodes for subfolders of the parent folder
85 You can tell that it is a subfolder by tacking the mailbox delimiter
86 on the end of the $mailbox string, and compare to that. */
88 for ($i = 0;$i < count($boxes);$i++
) {
89 if (substr($boxes[$i]["unformatted"], 0, strlen($mailbox_no_dm . $delimiter)) == ($mailbox_no_dm . $delimiter)) {
90 addChildNodeToTree($boxes[$i]["unformatted"], $boxes[$i]["unformatted-dm"], $foldersTree);
93 /* simpleWalkTreePre(0, $foldersTree); */
95 /** Lets start removing the folders and messages **/
96 if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/
97 walkTreeInPostOrderCreatingFoldersUnderTrash(0, $imap_stream, $foldersTree, $mailbox);
98 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
99 } else { /** if they do NOT wish to move messages to the trash (or cannot)**/
100 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
103 /** Log out this session **/
104 sqimap_logout($imap_stream);
106 $location = get_location();
107 header ("Location: $location/folders.php?success=delete");
109 echo "<BR><BR><BR><CENTER><B>";
110 echo _("Folder Deleted!");
112 echo _("The folder has been successfully deleted.");
113 echo "<BR><A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>";
114 echo _("Click here");
116 echo _("to continue.");
119 echo "</BODY></HTML>";