Rewrote multipart/* algorithm to be recursive
[squirrelmail.git] / src / folders_delete.php
1 <?
2 include("../config/config.php");
3 include("../functions/strings.php");
4 include("../functions/page_header.php");
5 include("../functions/imap.php");
6 include("../functions/mailbox.php");
7 include("../functions/array.php");
8
9 echo "<HTML><BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
10 $imapConnection = loginToImapServer($username, $key, $imapServerAddress);
11 getFolderList($imapConnection, $boxes);
12
13 $dm = findMailboxDelimeter($imapConnection);
14 /** lets see if we CAN move folders to the trash.. otherwise, just delete them **/
15 for ($i = 0; $i < count($boxes[$i]["UNFORMATTED"]); $i++) {
16 if ($boxes[$i]["UNFORMATTED"] == $trash_folder)
17 $tmp_trash_folder = $boxes[$i]["RAW"];
18 }
19
20 $tmpflags = getMailboxFlags($tmp_trash_folder);
21 $can_move_to_trash = true;
22 for ($i = 0; $i < count($tmpflags); $i++) {
23 if (strtolower($tmpflags[$i]) == "noinferiors")
24 $can_move_to_trash = false;
25 }
26
27 /** Lets start removing the folders and messages **/
28 if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/
29 /** Creates the subfolders under $trash_folder **/
30 for ($i = 0; $i < count($boxes); $i++) {
31 if (($boxes[$i]["UNFORMATTED"] == $mailbox) ||
32 (substr($boxes[$i]["UNFORMATTED"], 0, strlen($mailbox . $dm)) == $mailbox . $dm)) {
33 $folderWithoutINBOX = getFolderNameMinusINBOX($boxes[$i]["UNFORMATTED"], $dm);
34 $flags = getMailboxFlags($boxes[$i]["RAW"]);
35 for ($b = 0; $b < count($flags); $b++) {
36 $type = $flags[$b];
37 }
38 createFolder($imapConnection, "$trash_folder" . $dm . "$folderWithoutINBOX", $type);
39 }
40 }
41 for ($i = 0; $i < count($boxes); $i++) {
42 if (($boxes[$i]["UNFORMATTED"] == $mailbox) ||
43 (substr($boxes[$i]["UNFORMATTED"], 0, strlen($mailbox . $dm)) == $mailbox . $dm)) {
44 selectMailbox($imapConnection, $boxes[$i]["UNFORMATTED"], $numMessages);
45 $folder = getFolderNameMinusINBOX($boxes[$i]["UNFORMATTED"]);
46
47 if ($numMessages > 0)
48 $success = copyMessages($imapConnection, 1, $numMessages, "$trash_folder" . $dm . "$folder");
49 else
50 $success = true;
51
52 if ($success == true)
53 removeFolder($imapConnection, $boxes[$i]["UNFORMATTED"]);
54 }
55 }
56 } else { /** if they do NOT wish to move messages to the trash (or cannot)**/
57 fputs($imapConnection, "1 LIST \"$mailbox\" *\n");
58 $data = imapReadData($imapConnection , "1", false, $response, $message);
59 while (substr($data[0], strpos($data[0], " ")+1, 4) == "LIST") {
60 for ($i = 0; $i < count($boxes); $i++) {
61 if (($boxes[$i]["UNFORMATTED"] == $mailbox) ||
62 (substr($boxes[$i]["UNFORMATTED"], 0, strlen($mailbox . $dm)) == $mailbox . $dm)) {
63 removeFolder($imapConnection, $boxes[$i]["UNFORMATTED"]);
64 }
65 }
66 fputs($imapConnection, "1 LIST \"$mailbox\" *\n");
67 $data = imapReadData($imapConnection , "1", false, $response, $message);
68 }
69 }
70
71 /** Log out this session **/
72 fputs($imapConnection, "1 logout");
73
74 echo "<BR><BR><A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>Return</A>";
75 echo "</BODY></HTML>";
76 ?>
77
78