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
16 require_once('../src/validate.php');
17 require_once('../functions/imap.php');
18 require_once('../functions/array.php');
19 require_once('../functions/tree.php');
20 require_once('../functions/display_messages.php');
24 * $mailbox - selected mailbox from the form
28 displayPageHeader($color, 'None');
29 echo "<html><body bgcolor=$color[4]>";
30 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);
35 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
36 $boxes = sqimap_mailbox_list ($imap_stream);
37 global $delimiter, $delete_folder;
39 if (substr($mailbox, -1) == $delimiter)
40 $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1);
42 $mailbox_no_dm = $mailbox;
44 /** lets see if we CAN move folders to the trash.. otherwise,
45 ** just delete them **/
47 /* Courier IMAP doesn't like subfolders of Trash */
48 if (strtolower($imap_server_type) == "courier") {
49 $can_move_to_trash = false;
52 /* If global options say we can't move it into Trash */
53 else if(isset($delete_folder) && $delete_folder == true) {
54 $can_move_to_trash = false;
57 /* If it's already a subfolder of trash, we'll have to delete it */
58 else if(eregi("^".$trash_folder.".+", $mailbox)) {
60 $can_move_to_trash = false;
64 /* Otherwise, check if trash folder exits and support sub-folders */
66 for ($i = 0; $i < count($boxes); $i++
) {
67 if ($boxes[$i]["unformatted"] == $trash_folder) {
68 $can_move_to_trash = !in_array('noinferiors', $boxes[$i]['flags']);
73 /** First create the top node in the tree **/
74 for ($i = 0;$i < count($boxes);$i++
) {
75 if (($boxes[$i]["unformatted-dm"] == $mailbox) && (strlen($boxes[$i]["unformatted-dm"]) == strlen($mailbox))) {
76 $foldersTree[0]["value"] = $mailbox;
77 $foldersTree[0]["doIHaveChildren"] = false;
81 /* Now create the nodes for subfolders of the parent folder
82 You can tell that it is a subfolder by tacking the mailbox delimiter
83 on the end of the $mailbox string, and compare to that. */
85 for ($i = 0;$i < count($boxes);$i++
) {
86 if (substr($boxes[$i]["unformatted"], 0, strlen($mailbox_no_dm . $delimiter)) == ($mailbox_no_dm . $delimiter)) {
87 addChildNodeToTree($boxes[$i]["unformatted"], $boxes[$i]["unformatted-dm"], $foldersTree);
90 /* simpleWalkTreePre(0, $foldersTree); */
92 /** Lets start removing the folders and messages **/
93 if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/
94 walkTreeInPostOrderCreatingFoldersUnderTrash(0, $imap_stream, $foldersTree, $mailbox);
95 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
96 } else { /** if they do NOT wish to move messages to the trash (or cannot)**/
97 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
100 /** Log out this session **/
101 sqimap_logout($imap_stream);
103 $location = get_location();
104 header ("Location: $location/folders.php?success=delete");
106 echo "<BR><BR><BR><CENTER><B>";
107 echo _("Folder Deleted!");
109 echo _("The folder has been successfully deleted.");
110 echo "<BR><A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>";
111 echo _("Click here");
113 echo _("to continue.");
116 echo "</BODY></HTML>";