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