put the send button back at the top
[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
d92b6f31 11 echo "<HTML><BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
91f999f6 12 displayPageHeader($color, "None");
13
b235d629 14 $imapConnection = loginToImapServer($username, $key, $imapServerAddress, 0);
7ce342dc 15 getFolderList($imapConnection, $boxes);
d92b6f31 16
17 $dm = findMailboxDelimeter($imapConnection);
18 /** lets see if we CAN move folders to the trash.. otherwise, just delete them **/
7ce342dc 19 for ($i = 0; $i < count($boxes[$i]["UNFORMATTED"]); $i++) {
20 if ($boxes[$i]["UNFORMATTED"] == $trash_folder)
21 $tmp_trash_folder = $boxes[$i]["RAW"];
d92b6f31 22 }
23
91f999f6 24 $tmpflags = getMailboxFlags($imapConnection, $tmp_trash_folder);
d92b6f31 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 }
54e3c1d8 30
31 /** Lets start removing the folders and messages **/
d92b6f31 32 if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/
54e3c1d8 33 /** Creates the subfolders under $trash_folder **/
7ce342dc 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);
91f999f6 38 $flags = getMailboxFlags($imapConnection, $boxes[$i]["RAW"]);
d92b6f31 39 for ($b = 0; $b < count($flags); $b++) {
40 $type = $flags[$b];
41 }
42 createFolder($imapConnection, "$trash_folder" . $dm . "$folderWithoutINBOX", $type);
54e3c1d8 43 }
44 }
7ce342dc 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"]);
54e3c1d8 50
51 if ($numMessages > 0)
d92b6f31 52 $success = copyMessages($imapConnection, 1, $numMessages, "$trash_folder" . $dm . "$folder");
54e3c1d8 53 else
54 $success = true;
55
56 if ($success == true)
7ce342dc 57 removeFolder($imapConnection, $boxes[$i]["UNFORMATTED"]);
54e3c1d8 58 }
59 }
d92b6f31 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") {
7ce342dc 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"]);
d92b6f31 68 }
54e3c1d8 69 }
d92b6f31 70 fputs($imapConnection, "1 LIST \"$mailbox\" *\n");
71 $data = imapReadData($imapConnection , "1", false, $response, $message);
54e3c1d8 72 }
8c7dfc99 73 }
b40316f9 74
54e3c1d8 75 /** Log out this session **/
8c7dfc99 76 fputs($imapConnection, "1 logout");
b40316f9 77
91f999f6 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
f8f9bed9 83 echo "</BODY></HTML>";
b40316f9 84?>
85
86