submitted a patch from Andreas Dahl to make folder deleting work with
[squirrelmail.git] / src / folders_delete.php
1 <?php
2 /**
3 ** folders_delete.php
4 **
5 ** Copyright (c) 1999-2000 The SquirrelMail development team
6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
7 **
8 ** Deltes folders from the IMAP server.
9 ** Called from the folders.php
10 **/
11
12 session_start();
13
14 /*
15 * Incoming values:
16 * $mailbox - selected mailbox from the form
17 */
18
19 if (!isset($config_php))
20 include("../config/config.php");
21 if (!isset($strings_php))
22 include("../functions/strings.php");
23 if (!isset($page_header_php))
24 include("../functions/page_header.php");
25 if (!isset($imap_php))
26 include("../functions/imap.php");
27 if (!isset($array_php))
28 include("../functions/array.php");
29 if (!isset($tree_php))
30 include("../functions/tree.php");
31
32 include("../src/load_prefs.php");
33
34
35 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
36 $boxes = sqimap_mailbox_list ($imap_stream);
37 $dm = sqimap_get_delimiter($imap_stream);
38 $mailbox = sqStripSlashes($mailbox);
39
40 if (substr($mailbox, -1) == $dm)
41 $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1);
42 else
43 $mailbox_no_dm = $mailbox;
44
45 /** lets see if we CAN move folders to the trash.. otherwise,
46 ** just delete them **/
47 if (strtolower($imap_server_type) == "courier") {
48 // Courier IMAP doesn't like subfolders of Trash
49 $can_move_to_trash = false;
50 } else {
51 for ($i = 0; $i < count($boxes); $i++) {
52 if ($boxes[$i]["unformatted"] == $trash_folder) {
53 $can_move_to_trash = true;
54 for ($j = 0; $j < count($boxes[$i]["flags"]); $j++) {
55 if (strtolower($boxes[$i]["flags"][$j]) == "noinferiors")
56 $can_move_to_trash = false;
57 }
58 }
59 }
60 }
61
62 /** First create the top node in the tree **/
63 for ($i = 0;$i < count($boxes);$i++) {
64 if (($boxes[$i]["unformatted-dm"] == $mailbox) && (strlen($boxes[$i]["unformatted-dm"]) == strlen($mailbox))) {
65 $foldersTree[0]["value"] = $mailbox;
66 $foldersTree[0]["doIHaveChildren"] = false;
67 continue;
68 }
69 }
70 // Now create the nodes for subfolders of the parent folder
71 // You can tell that it is a subfolder by tacking the mailbox delimiter
72 // on the end of the $mailbox string, and compare to that.
73 $j = 0;
74 for ($i = 0;$i < count($boxes);$i++) {
75 if (substr($boxes[$i]["unformatted"], 0, strlen($mailbox_no_dm . $dm)) == ($mailbox_no_dm . $dm)) {
76 addChildNodeToTree($boxes[$i]["unformatted"], $boxes[$i]["unformatted-dm"], $foldersTree);
77 }
78 }
79 // simpleWalkTreePre(0, $foldersTree);
80
81 /** Lets start removing the folders and messages **/
82 if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/
83 walkTreeInPostOrderCreatingFoldersUnderTrash(0, $imap_stream, $foldersTree, $dm, $mailbox);
84 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
85 } else { /** if they do NOT wish to move messages to the trash (or cannot)**/
86 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
87 }
88
89 /** Log out this session **/
90 sqimap_logout($imap_stream);
91
92 $location = get_location();
93 header ("Location: $location/folders.php?success=delete");
94 /*
95 echo "<BR><BR><BR><CENTER><B>";
96 echo _("Folder Deleted!");
97 echo "</B><BR><BR>";
98 echo _("The folder has been successfully deleted.");
99 echo "<BR><A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>";
100 echo _("Click here");
101 echo "</A> ";
102 echo _("to continue.");
103 echo "</CENTER>";
104
105 echo "</BODY></HTML>";
106 */
107 ?>