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