Fixed some bugs in folder deleting
[squirrelmail.git] / src / folders_delete.php
1 <?
2 /*
3 * Incoming values:
4 * $mailbox - selected mailbox from the form
5 */
6
7 if (!isset($config_php))
8 include("../config/config.php");
9 if (!isset($strings_php))
10 include("../functions/strings.php");
11 if (!isset($page_header_php))
12 include("../functions/page_header.php");
13 if (!isset($imap_php))
14 include("../functions/imap.php");
15 if (!isset($array_php))
16 include("../functions/array.php");
17 if (!isset($tree_php))
18 include("../functions/tree.php");
19
20 include("../src/load_prefs.php");
21
22 echo "<HTML>";
23 echo "<BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
24 displayPageHeader($color, "None");
25
26
27 $imap_stream = sqimap_login($username, $key, $imapServerAddress, 0);
28 $boxes = sqimap_mailbox_list ($imap_stream);
29 $dm = sqimap_get_delimiter($imap_stream);
30 if (substr($mailbox, -1) == $dm)
31 $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1);
32 else
33 $mailbox_no_dm = $mailbox;
34
35 /** lets see if we CAN move folders to the trash.. otherwise, just delete them **/
36 for ($i = 0; $i < count($boxes); $i++) {
37 if ($boxes[$i]["unformatted"] == $trash_folder) {
38 $can_move_to_trash = true;
39 for ($j = 0; $j < count($boxes[$i]["flags"]); $j++) {
40 if (strtolower($boxes[$i]["flags"][$j]) == "noinferiors")
41 $can_move_to_trash = false;
42 }
43 }
44 }
45
46
47 /** First create the top node in the tree **/
48 for ($i = 0;$i < count($boxes);$i++) {
49 if (($boxes[$i]["unformatted-dm"] == $mailbox) && (strlen($boxes[$i]["unformatted-dm"]) == strlen($mailbox))) {
50 $foldersTree[0]["value"] = $mailbox;
51 $foldersTree[0]["doIHaveChildren"] = false;
52 continue;
53 }
54 }
55 // Now create the nodes for subfolders of the parent folder
56 // You can tell that it is a subfolder by tacking the mailbox delimiter
57 // on the end of the $mailbox string, and compare to that.
58 $j = 0;
59 for ($i = 0;$i < count($boxes);$i++) {
60 if (substr($boxes[$i]["unformatted"], 0, strlen($mailbox_no_dm . $dm)) == ($mailbox_no_dm . $dm)) {
61 // echo "<B>".$boxes[$i]["unformatted-dm"] . "</b><BR>";
62 addChildNodeToTree($boxes[$i]["unformatted"], $boxes[$i]["unformatted-dm"], $foldersTree);
63 }
64 }
65 // simpleWalkTreePre(0, $foldersTree);
66
67 /** Lets start removing the folders and messages **/
68 if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/
69 walkTreeInPostOrderCreatingFoldersUnderTrash(0, $imap_stream, $foldersTree, $dm, $mailbox);
70 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
71 } else { /** if they do NOT wish to move messages to the trash (or cannot)**/
72 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
73 }
74
75 /** Log out this session **/
76 sqimap_logout($imap_stream);
77
78 echo "<FONT FACE=\"Arial,Helvetica\">";
79 echo "<BR><BR><BR><CENTER><B>";
80 echo _("Folder Deleted!");
81 echo "</B><BR><BR>";
82 echo _("The folder has been successfully deleted.");
83 echo "<BR><A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>";
84 echo _("Click here");
85 echo "</A> ";
86 echo _("to continue.");
87 echo "</CENTER></FONT>";
88
89 echo "</BODY></HTML>";
90 ?>