rebuild mailbox cache when trash is emptied. cleans cached trash subfolders
[squirrelmail.git] / src / empty_trash.php
1 <?php
2
3 /**
4 * empty_trash.php
5 *
6 * Handles deleting messages from the trash folder without
7 * deleting subfolders.
8 *
9 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @version $Id$
12 * @package squirrelmail
13 */
14
15 /**
16 * Path for SquirrelMail required files.
17 * @ignore
18 */
19 define('SM_PATH','../');
20
21 /* SquirrelMail required files. */
22 require_once(SM_PATH . 'include/validate.php');
23 require_once(SM_PATH . 'functions/display_messages.php');
24 require_once(SM_PATH . 'functions/imap.php');
25 require_once(SM_PATH . 'functions/tree.php');
26
27 /* get those globals */
28
29 sqgetGlobalVar('username', $username, SQ_SESSION);
30 sqgetGlobalVar('key', $key, SQ_COOKIE);
31 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
32 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
33
34 /* finished globals */
35
36 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
37
38 $mailbox = $trash_folder;
39 $boxes = sqimap_mailbox_list($imap_stream);
40
41 /*
42 * According to RFC2060, a DELETE command should NOT remove inferiors (sub folders)
43 * so lets go through the list of subfolders and remove them before removing the
44 * parent.
45 */
46
47 /** First create the top node in the tree **/
48 $numboxes = count($boxes);
49 for ($i = 0; $i < $numboxes; $i++) {
50 if (($boxes[$i]['unformatted'] == $mailbox) && (strlen($boxes[$i]['unformatted']) == strlen($mailbox))) {
51 $foldersTree[0]['value'] = $mailbox;
52 $foldersTree[0]['doIHaveChildren'] = false;
53 continue;
54 }
55 }
56 /*
57 * Now create the nodes for subfolders of the parent folder
58 * You can tell that it is a subfolder by tacking the mailbox delimiter
59 * on the end of the $mailbox string, and compare to that.
60 */
61 $j = 0;
62 for ($i = 0; $i < $numboxes; $i++) {
63 if (substr($boxes[$i]['unformatted'], 0, strlen($mailbox . $delimiter)) == ($mailbox . $delimiter)) {
64 addChildNodeToTree($boxes[$i]['unformatted'], $boxes[$i]['unformatted-dm'], $foldersTree);
65 }
66 }
67
68 // now lets go through the tree and delete the folders
69 walkTreeInPreOrderEmptyTrash(0, $imap_stream, $foldersTree);
70 // update mailbox cache
71 $mailboxes=sqimap_get_mailboxes($imap_stream,true,$show_only_subscribed_folders);
72 sqimap_logout($imap_stream);
73
74 // close session properly before redirecting
75 session_write_close();
76
77 $location = get_location();
78 header ("Location: $location/left_main.php");
79
80 ?>