Fixed some bugs in folder deleting
[squirrelmail.git] / src / empty_trash.php
1 <?
2 include("../config/config.php");
3 include("../functions/strings.php");
4 include("../functions/page_header.php");
5 include("../functions/display_messages.php");
6 include("../functions/imap.php");
7 include("../functions/array.php");
8
9 if (!isset($tree_php))
10 include("../functions/tree.php");
11
12 include("../src/load_prefs.php");
13
14 $imap_stream = sqimap_login($username, $key, $imapServerAddress, 0);
15
16 sqimap_mailbox_list($imap_stream, $boxes);
17
18 $mailbox = $trash_folder;
19 $boxes = sqimap_mailbox_list($imap_stream);
20 $dm = sqimap_get_delimiter($imap_stream);
21
22 // According to RFC2060, a DELETE command should NOT remove inferiors (sub folders)
23 // so lets go through the list of subfolders and remove them before removing the
24 // parent.
25
26 /** First create the top node in the tree **/
27 for ($i = 0;$i < count($boxes);$i++) {
28 if (($boxes[$i]["unformatted"] == $mailbox) && (strlen($boxes[$i]["unformatted"]) == strlen($mailbox))) {
29 $foldersTree[0]["value"] = $mailbox;
30 $foldersTree[0]["doIHaveChildren"] = false;
31 continue;
32 }
33 }
34 // Now create the nodes for subfolders of the parent folder
35 // You can tell that it is a subfolder by tacking the mailbox delimiter
36 // on the end of the $mailbox string, and compare to that.
37 $j = 0;
38 for ($i = 0;$i < count($boxes);$i++) {
39 if (substr($boxes[$i]["unformatted"], 0, strlen($mailbox . $dm)) == ($mailbox . $dm)) {
40 addChildNodeToTree($boxes[$i]["unformatted"], $foldersTree);
41 }
42 }
43
44 // now lets go through the tree and delete the folders
45 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
46 // now lets create a new, fresh trash folder
47 sqimap_mailbox_create($imap_stream, "$trash_folder", "");
48
49 sqimap_mailbox_select($imap_stream, $trash_folder, $numMessages);
50 echo "<HTML><BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
51 displayPageHeader($color, $mailbox);
52 messages_deleted_message($trash_folder, $sort, $startMessage, $color);
53 sqimap_logout($imap_stream);
54 ?>