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');
23 * $mailbox - selected mailbox from the form
27 displayPageHeader($color, 'None');
28 echo "<html><body bgcolor=$color[4]>";
29 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);
34 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
35 $boxes = sqimap_mailbox_list ($imap_stream);
36 global $delimiter, $delete_folder;
38 if (substr($mailbox, -1) == $delimiter)
39 $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1);
41 $mailbox_no_dm = $mailbox;
43 /** lets see if we CAN move folders to the trash.. otherwise,
44 ** just delete them **/
46 /* Courier IMAP doesn't like subfolders of Trash */
47 if (strtolower($imap_server_type) == "courier") {
48 $can_move_to_trash = false;
51 /* If global options say we can't move it into Trash */
52 else if(isset($delete_folder) && $delete_folder == true) {
53 $can_move_to_trash = false;
56 /* If it's already a subfolder of trash, we'll have to delete it */
57 else if(eregi("^".$trash_folder.".+", $mailbox)) {
59 $can_move_to_trash = false;
63 /* Otherwise, check if trash folder exits and support sub-folders */
65 for ($i = 0; $i < count($boxes); $i++
) {
66 if ($boxes[$i]["unformatted"] == $trash_folder) {
67 $can_move_to_trash = !in_array('noinferiors', $boxes[$i]['flags']);
72 /** First create the top node in the tree **/
73 for ($i = 0;$i < count($boxes);$i++
) {
74 if (($boxes[$i]["unformatted-dm"] == $mailbox) && (strlen($boxes[$i]["unformatted-dm"]) == strlen($mailbox))) {
75 $foldersTree[0]["value"] = $mailbox;
76 $foldersTree[0]["doIHaveChildren"] = false;
80 /* Now create the nodes for subfolders of the parent folder
81 You can tell that it is a subfolder by tacking the mailbox delimiter
82 on the end of the $mailbox string, and compare to that. */
84 for ($i = 0;$i < count($boxes);$i++
) {
85 if (substr($boxes[$i]["unformatted"], 0, strlen($mailbox_no_dm . $delimiter)) == ($mailbox_no_dm . $delimiter)) {
86 addChildNodeToTree($boxes[$i]["unformatted"], $boxes[$i]["unformatted-dm"], $foldersTree);
89 /* simpleWalkTreePre(0, $foldersTree); */
91 /** Lets start removing the folders and messages **/
92 if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/
93 walkTreeInPostOrderCreatingFoldersUnderTrash(0, $imap_stream, $foldersTree, $mailbox);
94 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
95 } else { /** if they do NOT wish to move messages to the trash (or cannot)**/
96 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
99 /** Log out this session **/
100 sqimap_logout($imap_stream);
102 $location = get_location();
103 header ("Location: $location/folders.php?success=delete");
105 echo "<BR><BR><BR><CENTER><B>";
106 echo _("Folder Deleted!");
108 echo _("The folder has been successfully deleted.");
109 echo "<BR><A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>";
110 echo _("Click here");
112 echo _("to continue.");
115 echo "</BODY></HTML>";