Lots of changes for variable initialization - clean up, really,
[squirrelmail.git] / src / empty_trash.php
1 <?php
2
3 /**
4 * empty_trash.php
5 *
6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Handles deleting messages from the trash folder without
10 * deleting subfolders.
11 *
12 * $Id$
13 */
14
15 /* Path for SquirrelMail required files. */
16 define('SM_PATH','../');
17
18 /* SquirrelMail required files. */
19 require_once(SM_PATH . 'include/validate.php');
20 require_once(SM_PATH . 'functions/display_messages.php');
21 require_once(SM_PATH . 'functions/imap.php');
22 require_once(SM_PATH . 'functions/tree.php');
23
24 /* get those globals */
25
26 $key = $_COOKIE['key'];
27 $username = $_SESSION['username'];
28 $onetimepad = $_SESSION['onetimepad'];
29 $delimiter = $_SESSION['delimiter'];
30
31 /* finished globals */
32
33 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
34
35 sqimap_mailbox_list($imap_stream);
36
37 $mailbox = $trash_folder;
38 $boxes = sqimap_mailbox_list($imap_stream);
39
40 /*
41 * According to RFC2060, a DELETE command should NOT remove inferiors (sub folders)
42 * so lets go through the list of subfolders and remove them before removing the
43 * parent.
44 */
45
46 /** First create the top node in the tree **/
47 $numboxes = count($boxes);
48 for ($i = 0; $i < $numboxes; $i++) {
49 if (($boxes[$i]['unformatted'] == $mailbox) && (strlen($boxes[$i]['unformatted']) == strlen($mailbox))) {
50 $foldersTree[0]['value'] = $mailbox;
51 $foldersTree[0]['doIHaveChildren'] = false;
52 continue;
53 }
54 }
55 /*
56 * Now create the nodes for subfolders of the parent folder
57 * You can tell that it is a subfolder by tacking the mailbox delimiter
58 * on the end of the $mailbox string, and compare to that.
59 */
60 $j = 0;
61 for ($i = 0; $i < $numboxes; $i++) {
62 if (substr($boxes[$i]['unformatted'], 0, strlen($mailbox . $delimiter)) == ($mailbox . $delimiter)) {
63 addChildNodeToTree($boxes[$i]['unformatted'], $boxes[$i]['unformatted-dm'], $foldersTree);
64 }
65 }
66
67 // now lets go through the tree and delete the folders
68 walkTreeInPreOrderEmptyTrash(0, $imap_stream, $foldersTree);
69
70 $location = get_location();
71 header ("Location: $location/left_main.php");
72
73 sqimap_logout($imap_stream);
74 ?>