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