Added a constat to all files in functions/ to be able to chech whether the
[squirrelmail.git] / src / folders_delete.php
1 <?
2 if (!isset($config_php))
3 include("../config/config.php");
4 if (!isset($strings_php))
5 include("../functions/strings.php");
6 if (!isset($page_header_php))
7 include("../functions/page_header.php");
8 if (!isset($imap_php))
9 include("../functions/imap.php");
10 if (!isset($array_php))
11 include("../functions/array.php");
12
13 include("../src/load_prefs.php");
14
15 echo "<HTML>";
16 echo "<BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
17 displayPageHeader($color, "None");
18
19 $imapConnection = sqimap_login($username, $key, $imapServerAddress, 0);
20 $boxes = sqimap_mailbox_list ($imapConnection);
21 $dm = sqimap_get_delimiter($imapConnection);
22
23 /** lets see if we CAN move folders to the trash.. otherwise, just delete them **/
24 for ($i = 0; $i < count($boxes[$i]["unformatted"]); $i++) {
25 if ($boxes[$i]["unformatted"] == $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 }
33
34 /** Lets start removing the folders and messages **/
35 if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/
36 /** Creates the subfolders under $trash_folder **/
37 for ($i = 0; $i < count($boxes); $i++) {
38 if (($boxes[$i]["unformatted"] == $mailbox) ||
39 (substr($boxes[$i]["unformatted"], 0, strlen($mailbox . $dm)) == $mailbox . $dm)) {
40 $folderWithoutINBOX = getFolderNameMinusINBOX($boxes[$i]["unformatted"], $dm);
41 $flags = getMailboxFlags($imapConnection, $boxes[$i]["raw"]);
42 for ($b = 0; $b < count($flags); $b++) {
43 $type = $flags[$b];
44 }
45 createFolder($imapConnection, "$trash_folder" . $dm . "$folderWithoutINBOX", $type);
46 }
47 }
48 for ($i = 0; $i < count($boxes); $i++) {
49 if (($boxes[$i]["unformatted"] == $mailbox) ||
50 (substr($boxes[$i]["unformatted"], 0, strlen($mailbox . $dm)) == $mailbox . $dm)) {
51 sqimap_mailbox_create($imapConnection, $boxes[$i]["unformatted"], $numMessages);
52 $folder = $boxes[$i]["unformatted"];
53
54 if ($numMessages > 0)
55 $success = sqimap_messages_copy($imapConnection, 1, $folder);
56 else
57 $success = true;
58
59 if ($success == true)
60 sqimap_mailbox_delete($imapConnection, $boxes[$i]["unformatted"]);
61 }
62 }
63 } else { /** if they do NOT wish to move messages to the trash (or cannot)**/
64 fputs($imapConnection, "1 LIST \"$mailbox\" *\n");
65 $data = sqimap_read_data($imapConnection, "1", false, $response, $message);
66 while (substr($data[0], strpos($data[0], " ")+1, 4) == "LIST") {
67 for ($i = 0; $i < count($boxes); $i++) {
68 if (($boxes[$i]["unformatted"] == $mailbox) ||
69 (substr($boxes[$i]["unformatted"], 0, strlen($mailbox . $dm)) == $mailbox . $dm)) {
70 sqimap_mailbox_delete($imapConnection, $boxes[$i]["unformatted"], $dm);
71 }
72 }
73 fputs($imapConnection, "1 LIST \"$mailbox\" *\n");
74 $data = sqimap_read_data($imapConnection , "1", false, $response, $message);
75 }
76 }
77
78 /** Log out this session **/
79 fputs($imapConnection, "1 logout");
80
81 echo "<FONT FACE=\"Arial,Helvetica\">";
82 echo "<BR><BR><BR><CENTER><B>";
83 echo _("Folder Deleted!");
84 echo "</B><BR><BR>";
85 echo _("The folder has been successfully deleted.");
86 echo "<BR><A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>";
87 echo _("Click here");
88 echo "</A> ";
89 echo _("to continue.");
90 echo "</CENTER></FONT>";
91
92 echo "</BODY></HTML>";
93 ?>