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