Deleting subfolders of trash works, but it's not very pretty
[squirrelmail.git] / src / empty_trash.php
CommitLineData
7a783442 1<?
2 include("../config/config.php");
3 include("../functions/mailbox.php");
4 include("../functions/strings.php");
5 include("../functions/page_header.php");
6 include("../functions/display_messages.php");
2aa12d5e 7 include("../functions/imap.php");
7a783442 8
2aa12d5e 9 $imapConnection = loginToImapServer($username, $key, $imapServerAddress);
7a783442 10
11 // switch to the mailbox, and get the number of messages in it.
12 selectMailbox($imapConnection, $mailbox, $numMessages);
13
14 if ($mailbox != $trash_folder) {
15 echo "ERROR -- I'm not in the trash folder!<BR>";
16 exit;
17 }
18
a11899fd 19
20 /** GET FOLDER ARRAY OF TRASH SUBFOLDERS **/
21 fputs($imapConnection, "1 list \"\" *\n");
22 $str = imapReadData($imapConnection);
23
24 for ($i = 0;$i < count($str); $i++) {
25 $box = Chop($str[$i]);
26 $mailbox = findMailboxName($box);
27
28 if (strpos($box, $trash_folder) > 0) {
29 $folders[$i] = $mailbox;
30 } else {
31 $folders[$i] = "NOPE";
32 }
33 }
34
7a783442 35 // mark them as deleted
36 setMessageFlag($imapConnection, 1, $numMessages, "Deleted");
37 expungeBox($imapConnection, $mailbox);
38
a11899fd 39 // remove subfolders
40 for ($i = 0; $i < count($folders); $i++) {
9a7d463e 41 if (($folders[$i] == "NOPE") || ($folders[$i] == "$trash_folder")) {
42 } else {
43 $thisfolder = getFolderNameMinusINBOX($folders[$i]);
44 $thisfolder = "user.$username.$thisfolder";
45 removeFolder($imapConnection, $thisfolder);
a11899fd 46 }
47 }
48
7a783442 49 // Log out this session
50 fputs($imapConnection, "1 logout");
51
52 echo "<HTML><BODY TEXT=\"#000000\" BGCOLOR=\"#FFFFFF\" LINK=\"#0000EE\" VLINK=\"#0000EE\" ALINK=\"#0000EE\">";
53 displayPageHeader($mailbox);
54
55 messages_deleted_message($mailbox, $sort, $startMessage);
2aa12d5e 56?>