9b836009f8783fb5ca392e5c064c222c38403bd9
[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 include("../src/load_prefs.php");
10
11 echo "<HTML><BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
12 displayPageHeader($color, "None");
13
14 $imapConnection = loginToImapServer($username, $key, $imapServerAddress, 0);
15 getFolderList($imapConnection, $boxes);
16
17 $dm = findMailboxDelimeter($imapConnection);
18 /** lets see if we CAN move folders to the trash.. otherwise, just delete them **/
19 for ($i = 0; $i < count($boxes[$i]["UNFORMATTED"]); $i++) {
20 if ($boxes[$i]["UNFORMATTED"] == $trash_folder)
21 $tmp_trash_folder = $boxes[$i]["RAW"];
22 }
23
24 $tmpflags = getMailboxFlags($imapConnection, $tmp_trash_folder);
25 $can_move_to_trash = true;
26 for ($i = 0; $i < count($tmpflags); $i++) {
27 if (strtolower($tmpflags[$i]) == "noinferiors")
28 $can_move_to_trash = false;
29 }
30
31 /** Lets start removing the folders and messages **/
32 if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/
33 /** Creates the subfolders under $trash_folder **/
34 for ($i = 0; $i < count($boxes); $i++) {
35 if (($boxes[$i]["UNFORMATTED"] == $mailbox) ||
36 (substr($boxes[$i]["UNFORMATTED"], 0, strlen($mailbox . $dm)) == $mailbox . $dm)) {
37 $folderWithoutINBOX = getFolderNameMinusINBOX($boxes[$i]["UNFORMATTED"], $dm);
38 $flags = getMailboxFlags($imapConnection, $boxes[$i]["RAW"]);
39 for ($b = 0; $b < count($flags); $b++) {
40 $type = $flags[$b];
41 }
42 createFolder($imapConnection, "$trash_folder" . $dm . "$folderWithoutINBOX", $type);
43 }
44 }
45 for ($i = 0; $i < count($boxes); $i++) {
46 if (($boxes[$i]["UNFORMATTED"] == $mailbox) ||
47 (substr($boxes[$i]["UNFORMATTED"], 0, strlen($mailbox . $dm)) == $mailbox . $dm)) {
48 selectMailbox($imapConnection, $boxes[$i]["UNFORMATTED"], $numMessages);
49 $folder = getFolderNameMinusINBOX($boxes[$i]["UNFORMATTED"]);
50
51 if ($numMessages > 0)
52 $success = copyMessages($imapConnection, 1, $numMessages, "$trash_folder" . $dm . "$folder");
53 else
54 $success = true;
55
56 if ($success == true)
57 removeFolder($imapConnection, $boxes[$i]["UNFORMATTED"]);
58 }
59 }
60 } else { /** if they do NOT wish to move messages to the trash (or cannot)**/
61 fputs($imapConnection, "1 LIST \"$mailbox\" *\n");
62 $data = imapReadData($imapConnection , "1", false, $response, $message);
63 while (substr($data[0], strpos($data[0], " ")+1, 4) == "LIST") {
64 for ($i = 0; $i < count($boxes); $i++) {
65 if (($boxes[$i]["UNFORMATTED"] == $mailbox) ||
66 (substr($boxes[$i]["UNFORMATTED"], 0, strlen($mailbox . $dm)) == $mailbox . $dm)) {
67 removeFolder($imapConnection, $boxes[$i]["UNFORMATTED"]);
68 }
69 }
70 fputs($imapConnection, "1 LIST \"$mailbox\" *\n");
71 $data = imapReadData($imapConnection , "1", false, $response, $message);
72 }
73 }
74
75 /** Log out this session **/
76 fputs($imapConnection, "1 logout");
77
78 echo "<FONT FACE=\"Arial,Helvetica\">";
79 echo "<BR><BR><CENTER><B>" . _("Folder Deleted!") . "</B><BR><BR>";
80 echo _("You will be automatically forwarded.") . "<BR>" . _("If not,") . " <A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>" . _("click here") . "</A>";
81 echo "</CENTER></FONT>";
82
83 echo "</BODY></HTML>";
84 ?>
85
86