added some preferences, and squashed soem bugs
[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";
2aa12d5e 12 $imapConnection = loginToImapServer($username, $key, $imapServerAddress);
7ce342dc 13 getFolderList($imapConnection, $boxes);
d92b6f31 14
15 $dm = findMailboxDelimeter($imapConnection);
16 /** lets see if we CAN move folders to the trash.. otherwise, just delete them **/
7ce342dc 17 for ($i = 0; $i < count($boxes[$i]["UNFORMATTED"]); $i++) {
18 if ($boxes[$i]["UNFORMATTED"] == $trash_folder)
19 $tmp_trash_folder = $boxes[$i]["RAW"];
d92b6f31 20 }
21
22 $tmpflags = getMailboxFlags($tmp_trash_folder);
23 $can_move_to_trash = true;
24 for ($i = 0; $i < count($tmpflags); $i++) {
25 if (strtolower($tmpflags[$i]) == "noinferiors")
26 $can_move_to_trash = false;
27 }
54e3c1d8 28
29 /** Lets start removing the folders and messages **/
d92b6f31 30 if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/
54e3c1d8 31 /** Creates the subfolders under $trash_folder **/
7ce342dc 32 for ($i = 0; $i < count($boxes); $i++) {
33 if (($boxes[$i]["UNFORMATTED"] == $mailbox) ||
34 (substr($boxes[$i]["UNFORMATTED"], 0, strlen($mailbox . $dm)) == $mailbox . $dm)) {
35 $folderWithoutINBOX = getFolderNameMinusINBOX($boxes[$i]["UNFORMATTED"], $dm);
36 $flags = getMailboxFlags($boxes[$i]["RAW"]);
d92b6f31 37 for ($b = 0; $b < count($flags); $b++) {
38 $type = $flags[$b];
39 }
40 createFolder($imapConnection, "$trash_folder" . $dm . "$folderWithoutINBOX", $type);
54e3c1d8 41 }
42 }
7ce342dc 43 for ($i = 0; $i < count($boxes); $i++) {
44 if (($boxes[$i]["UNFORMATTED"] == $mailbox) ||
45 (substr($boxes[$i]["UNFORMATTED"], 0, strlen($mailbox . $dm)) == $mailbox . $dm)) {
46 selectMailbox($imapConnection, $boxes[$i]["UNFORMATTED"], $numMessages);
47 $folder = getFolderNameMinusINBOX($boxes[$i]["UNFORMATTED"]);
54e3c1d8 48
49 if ($numMessages > 0)
d92b6f31 50 $success = copyMessages($imapConnection, 1, $numMessages, "$trash_folder" . $dm . "$folder");
54e3c1d8 51 else
52 $success = true;
53
54 if ($success == true)
7ce342dc 55 removeFolder($imapConnection, $boxes[$i]["UNFORMATTED"]);
54e3c1d8 56 }
57 }
d92b6f31 58 } else { /** if they do NOT wish to move messages to the trash (or cannot)**/
59 fputs($imapConnection, "1 LIST \"$mailbox\" *\n");
60 $data = imapReadData($imapConnection , "1", false, $response, $message);
61 while (substr($data[0], strpos($data[0], " ")+1, 4) == "LIST") {
7ce342dc 62 for ($i = 0; $i < count($boxes); $i++) {
63 if (($boxes[$i]["UNFORMATTED"] == $mailbox) ||
64 (substr($boxes[$i]["UNFORMATTED"], 0, strlen($mailbox . $dm)) == $mailbox . $dm)) {
65 removeFolder($imapConnection, $boxes[$i]["UNFORMATTED"]);
d92b6f31 66 }
54e3c1d8 67 }
d92b6f31 68 fputs($imapConnection, "1 LIST \"$mailbox\" *\n");
69 $data = imapReadData($imapConnection , "1", false, $response, $message);
54e3c1d8 70 }
8c7dfc99 71 }
b40316f9 72
54e3c1d8 73 /** Log out this session **/
8c7dfc99 74 fputs($imapConnection, "1 logout");
b40316f9 75
907165ca 76 echo "<BR><BR><A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>Return</A>";
f8f9bed9 77 echo "</BODY></HTML>";
b40316f9 78?>
79
80