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 | * |
c997cbe6 |
9 | * @copyright 1999-2021 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 */ |
16 | define('PAGE_NAME', 'empty_trash'); |
17 | |
30967a1e |
18 | /** |
202bcbcc |
19 | * Include the SquirrelMail initialization file. |
30967a1e |
20 | */ |
202bcbcc |
21 | require('../include/init.php'); |
86725763 |
22 | |
202bcbcc |
23 | require(SM_PATH . 'functions/imap_general.php'); |
24 | require(SM_PATH . 'functions/imap_messages.php'); |
25 | require(SM_PATH . 'functions/tree.php'); |
d3cdb279 |
26 | |
a32985a5 |
27 | /* get those globals */ |
28 | |
f38b7cf0 |
29 | sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION); |
a32985a5 |
30 | |
31 | /* finished globals */ |
32 | |
ce102fcc |
33 | // first do a security check |
34 | sqgetGlobalVar('smtoken', $submitted_token, SQ_GET, ''); |
2cefa62a |
35 | sm_validate_security_token($submitted_token, -1, TRUE); |
ce102fcc |
36 | |
a9805897 |
37 | global $imap_stream_options; // in case not defined in config |
38 | $imap_stream = sqimap_login($username, false, $imapServerAddress, $imapPort, 0, $imap_stream_options); |
65c3ec94 |
39 | |
65c3ec94 |
40 | $mailbox = $trash_folder; |
41 | $boxes = sqimap_mailbox_list($imap_stream); |
d92b6f31 |
42 | |
65c3ec94 |
43 | /* |
44 | * According to RFC2060, a DELETE command should NOT remove inferiors (sub folders) |
45 | * so lets go through the list of subfolders and remove them before removing the |
46 | * parent. |
47 | */ |
48 | |
49 | /** First create the top node in the tree **/ |
c9acef51 |
50 | $numboxes = count($boxes); |
51 | for ($i = 0; $i < $numboxes; $i++) { |
52 | if (($boxes[$i]['unformatted'] == $mailbox) && (strlen($boxes[$i]['unformatted']) == strlen($mailbox))) { |
53 | $foldersTree[0]['value'] = $mailbox; |
54 | $foldersTree[0]['doIHaveChildren'] = false; |
65c3ec94 |
55 | continue; |
56 | } |
57 | } |
58 | /* |
59 | * Now create the nodes for subfolders of the parent folder |
60 | * You can tell that it is a subfolder by tacking the mailbox delimiter |
61 | * on the end of the $mailbox string, and compare to that. |
62 | */ |
63 | $j = 0; |
c9acef51 |
64 | for ($i = 0; $i < $numboxes; $i++) { |
65 | if (substr($boxes[$i]['unformatted'], 0, strlen($mailbox . $delimiter)) == ($mailbox . $delimiter)) { |
66 | addChildNodeToTree($boxes[$i]['unformatted'], $boxes[$i]['unformatted-dm'], $foldersTree); |
65c3ec94 |
67 | } |
68 | } |
0a1d5f3a |
69 | |
65c3ec94 |
70 | // now lets go through the tree and delete the folders |
71 | walkTreeInPreOrderEmptyTrash(0, $imap_stream, $foldersTree); |
0d2130f5 |
72 | // update mailbox cache |
73 | $mailboxes=sqimap_get_mailboxes($imap_stream,true,$show_only_subscribed_folders); |
a1eb6f89 |
74 | sqimap_logout($imap_stream); |
75 | |
76 | // close session properly before redirecting |
77 | session_write_close(); |
a11899fd |
78 | |
65c3ec94 |
79 | $location = get_location(); |
dcc1cc82 |
80 | header ("Location: $location/left_main.php"); |
e9f8ea4e |
81 | |