Allow more liberal reuse of tokens to avoid cross-frame conflicts
[squirrelmail.git] / src / empty_trash.php
CommitLineData
59177427 1<?php
895905c0 2
35586184 3/**
4 * empty_trash.php
5 *
35586184 6 * Handles deleting messages from the trash folder without
7 * deleting subfolders.
8 *
c0d96801 9 * @copyright 1999-2012 The SquirrelMail Project Team
4b4abf93 10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
30967a1e 11 * @version $Id$
8f6f9ba5 12 * @package squirrelmail
35586184 13 */
ef870322 14
ebd2391c 15/** This is the empty_trash page */
16define('PAGE_NAME', 'empty_trash');
17
30967a1e 18/**
202bcbcc 19 * Include the SquirrelMail initialization file.
30967a1e 20 */
202bcbcc 21require('../include/init.php');
86725763 22
202bcbcc 23require(SM_PATH . 'functions/imap_general.php');
24require(SM_PATH . 'functions/imap_messages.php');
25require(SM_PATH . 'functions/tree.php');
d3cdb279 26
a32985a5 27/* get those globals */
28
f38b7cf0 29sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
a32985a5 30
31/* finished globals */
32
ce102fcc 33// first do a security check
34sqgetGlobalVar('smtoken', $submitted_token, SQ_GET, '');
2cefa62a 35sm_validate_security_token($submitted_token, -1, TRUE);
ce102fcc 36
906f7e9f 37$imap_stream = sqimap_login($username, false, $imapServerAddress, $imapPort, 0);
65c3ec94 38
65c3ec94 39$mailbox = $trash_folder;
40$boxes = sqimap_mailbox_list($imap_stream);
d92b6f31 41
65c3ec94 42/*
43 * According to RFC2060, a DELETE command should NOT remove inferiors (sub folders)
44 * so lets go through the list of subfolders and remove them before removing the
45 * parent.
46 */
47
48/** First create the top node in the tree **/
c9acef51 49$numboxes = count($boxes);
50for ($i = 0; $i < $numboxes; $i++) {
51 if (($boxes[$i]['unformatted'] == $mailbox) && (strlen($boxes[$i]['unformatted']) == strlen($mailbox))) {
52 $foldersTree[0]['value'] = $mailbox;
53 $foldersTree[0]['doIHaveChildren'] = false;
65c3ec94 54 continue;
55 }
56}
57/*
58 * Now create the nodes for subfolders of the parent folder
59 * You can tell that it is a subfolder by tacking the mailbox delimiter
60 * on the end of the $mailbox string, and compare to that.
61 */
62$j = 0;
c9acef51 63for ($i = 0; $i < $numboxes; $i++) {
64 if (substr($boxes[$i]['unformatted'], 0, strlen($mailbox . $delimiter)) == ($mailbox . $delimiter)) {
65 addChildNodeToTree($boxes[$i]['unformatted'], $boxes[$i]['unformatted-dm'], $foldersTree);
65c3ec94 66 }
67}
0a1d5f3a 68
65c3ec94 69// now lets go through the tree and delete the folders
70walkTreeInPreOrderEmptyTrash(0, $imap_stream, $foldersTree);
0d2130f5 71// update mailbox cache
72$mailboxes=sqimap_get_mailboxes($imap_stream,true,$show_only_subscribed_folders);
a1eb6f89 73sqimap_logout($imap_stream);
74
75// close session properly before redirecting
76session_write_close();
a11899fd 77
65c3ec94 78$location = get_location();
dcc1cc82 79header ("Location: $location/left_main.php");
e9f8ea4e 80