c79b24d61682e4f70e5064aa990723250fe8edff
[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
31 /** lets see if we CAN move folders to the trash.. otherwise, just delete them **/
32 for ($i = 0; $i < count($boxes); $i++) {
33 if ($boxes[$i]["unformatted"] == $trash_folder) {
34 $can_move_to_trash = true;
35 for ($j = 0; $j < count($boxes[$i]["flags"]); $j++) {
36 if (strtolower($boxes[$i]["flags"][$j]) == "noinferiors")
37 $can_move_to_trash = false;
38 }
39 }
40 }
41
42
43 /** First create the top node in the tree **/
44 for ($i = 0;$i < count($boxes);$i++) {
45 if (($boxes[$i]["unformatted"] == $mailbox) && (strlen($boxes[$i]["unformatted"]) == strlen($mailbox))) {
46 $foldersTree[0]["value"] = $mailbox;
47 $foldersTree[0]["doIHaveChildren"] = false;
48 continue;
49 }
50 }
51 // Now create the nodes for subfolders of the parent folder
52 // You can tell that it is a subfolder by tacking the mailbox delimiter
53 // on the end of the $mailbox string, and compare to that.
54 $j = 0;
55 for ($i = 0;$i < count($boxes);$i++) {
56 if (substr($boxes[$i]["unformatted"], 0, strlen($mailbox . $dm)) == ($mailbox . $dm)) {
57 addChildNodeToTree($boxes[$i]["unformatted"], $foldersTree);
58 }
59 }
60
61 /** Lets start removing the folders and messages **/
62 if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/
63 walkTreeInPostOrderCreatingFoldersUnderTrash(0, $imap_stream, $foldersTree, $dm, $mailbox);
64 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
65 } else { /** if they do NOT wish to move messages to the trash (or cannot)**/
66 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
67 }
68
69 /** Log out this session **/
70 sqimap_logout($imap_stream);
71
72 echo "<FONT FACE=\"Arial,Helvetica\">";
73 echo "<BR><BR><BR><CENTER><B>";
74 echo _("Folder Deleted!");
75 echo "</B><BR><BR>";
76 echo _("The folder has been successfully deleted.");
77 echo "<BR><A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>";
78 echo _("Click here");
79 echo "</A> ";
80 echo _("to continue.");
81 echo "</CENTER></FONT>";
82
83 echo "</BODY></HTML>";
84 ?>