fixed a couple of bugs in folder manipulation, in particular:
[squirrelmail.git] / src / folders_delete.php
CommitLineData
b40316f9 1<?
2 include("../config/config.php");
3 include("../functions/strings.php");
4 include("../functions/page_header.php");
5 include("../functions/imap.php");
597d8f1d 6 include("../functions/mailbox.php");
7ce342dc 7 include("../functions/array.php");
b40316f9 8
d3cdb279 9 include("../src/load_prefs.php");
10
aff57ea5 11 echo "<HTML>";
12 echo "<BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
91f999f6 13 displayPageHeader($color, "None");
14
b235d629 15 $imapConnection = loginToImapServer($username, $key, $imapServerAddress, 0);
7ce342dc 16 getFolderList($imapConnection, $boxes);
d92b6f31 17
18 $dm = findMailboxDelimeter($imapConnection);
19 /** lets see if we CAN move folders to the trash.. otherwise, just delete them **/
7ce342dc 20 for ($i = 0; $i < count($boxes[$i]["UNFORMATTED"]); $i++) {
21 if ($boxes[$i]["UNFORMATTED"] == $trash_folder)
22 $tmp_trash_folder = $boxes[$i]["RAW"];
d92b6f31 23 }
24
91f999f6 25 $tmpflags = getMailboxFlags($imapConnection, $tmp_trash_folder);
d92b6f31 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 }
54e3c1d8 31
32 /** Lets start removing the folders and messages **/
d92b6f31 33 if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/
54e3c1d8 34 /** Creates the subfolders under $trash_folder **/
7ce342dc 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);
91f999f6 39 $flags = getMailboxFlags($imapConnection, $boxes[$i]["RAW"]);
d92b6f31 40 for ($b = 0; $b < count($flags); $b++) {
41 $type = $flags[$b];
42 }
43 createFolder($imapConnection, "$trash_folder" . $dm . "$folderWithoutINBOX", $type);
54e3c1d8 44 }
45 }
7ce342dc 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"]);
54e3c1d8 51
52 if ($numMessages > 0)
d92b6f31 53 $success = copyMessages($imapConnection, 1, $numMessages, "$trash_folder" . $dm . "$folder");
54e3c1d8 54 else
55 $success = true;
56
57 if ($success == true)
7ce342dc 58 removeFolder($imapConnection, $boxes[$i]["UNFORMATTED"]);
54e3c1d8 59 }
60 }
d92b6f31 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") {
7ce342dc 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"]);
d92b6f31 69 }
54e3c1d8 70 }
d92b6f31 71 fputs($imapConnection, "1 LIST \"$mailbox\" *\n");
72 $data = imapReadData($imapConnection , "1", false, $response, $message);
54e3c1d8 73 }
8c7dfc99 74 }
b40316f9 75
54e3c1d8 76 /** Log out this session **/
8c7dfc99 77 fputs($imapConnection, "1 logout");
b40316f9 78
91f999f6 79 echo "<FONT FACE=\"Arial,Helvetica\">";
aff57ea5 80 echo "<BR><BR><BR><CENTER><B>";
81 echo _("Folder Deleted!");
82 echo "</B><BR><BR>";
83 echo _("The folder has been successfully deleted.");
bd8bf491 84 echo "<BR><A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>";
aff57ea5 85 echo _("Click here");
bd8bf491 86 echo "</A> ";
aff57ea5 87 echo _("to continue.");
91f999f6 88 echo "</CENTER></FONT>";
89
f8f9bed9 90 echo "</BODY></HTML>";
b40316f9 91?>
92
93