deleting folders is now recursive and should work more reliably
[squirrelmail.git] / src / empty_trash.php
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");
7 include("../functions/imap.php");
8 include("../functions/array.php");
9
10 include("../src/load_prefs.php");
11
12 $imapConnection = loginToImapServer($username, $key, $imapServerAddress, 0);
13
14 getFolderList($imapConnection, $boxes);
15
16 $mailbox = $trash_folder;
17 fputs($imapConnection, "1 LIST \"$mailbox\" *\n");
18 $data = imapReadData($imapConnection , "1", false, $response, $message);
19
20 $dm = findMailboxDelimeter($imapConnection);
21
22 // According to RFC2060, a DELETE command should NOT remove inferiors (sub folders)
23 // so lets go through the list of subfolders and remove them before removing the
24 // parent.
25 // BUG??? - what if a subfolder has a subfolder?? need to start at lowest level
26 // and work up.
27
28
29 // for ($i = 0; $i < count($boxes); $i++) {
30 // if (($boxes[$i]["UNFORMATTED"] == $mailbox) ||
31 // (substr($boxes[$i]["UNFORMATTED"], 0, strlen($mailbox . $dm)) == $mailbox . $dm)) {
32 // if (($boxes[$i]["UNFORMATTED"] != $mailbox) && (substr($boxes[$i]["UNFORMATTED"], 0, strlen($mailbox . $dm)) == $mailbox . $dm)) {
33 // removeFolder($imapConnection, $boxes[$i]["UNFORMATTED"], $dm);
34 // }
35 // }
36
37 // lets remove the trash folder
38 removeFolder($imapConnection, $mailbox, $dm);
39
40 createFolder($imapConnection, "$trash_folder", "");
41
42 selectMailbox($imapConnection, $trash_folder, $numMessages);
43 echo "<HTML><BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
44 displayPageHeader($color, $mailbox);
45 messages_deleted_message($trash_folder, $sort, $startMessage, $color);
46 fputs($imapConnection, "1 logout");
47 ?>