tree functionality
[squirrelmail.git] / src / folders_delete.php
CommitLineData
b40316f9 1<?
d068c0ec 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");
b40316f9 12
d3cdb279 13 include("../src/load_prefs.php");
14
aff57ea5 15 echo "<HTML>";
16 echo "<BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
91f999f6 17 displayPageHeader($color, "None");
18
813eba2f 19 $imapConnection = sqimap_login($username, $key, $imapServerAddress, 0);
20 $boxes = sqimap_mailbox_list ($imapConnection);
21 $dm = sqimap_get_delimiter($imapConnection);
d92b6f31 22
d92b6f31 23 /** lets see if we CAN move folders to the trash.. otherwise, just delete them **/
813eba2f 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 }
d92b6f31 32 }
54e3c1d8 33
34 /** Lets start removing the folders and messages **/
d92b6f31 35 if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/
54e3c1d8 36 /** Creates the subfolders under $trash_folder **/
7ce342dc 37 for ($i = 0; $i < count($boxes); $i++) {
813eba2f 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"]);
d92b6f31 42 for ($b = 0; $b < count($flags); $b++) {
43 $type = $flags[$b];
44 }
45 createFolder($imapConnection, "$trash_folder" . $dm . "$folderWithoutINBOX", $type);
54e3c1d8 46 }
47 }
7ce342dc 48 for ($i = 0; $i < count($boxes); $i++) {
813eba2f 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"];
54e3c1d8 53
54 if ($numMessages > 0)
813eba2f 55 $success = sqimap_messages_copy($imapConnection, 1, $folder);
54e3c1d8 56 else
57 $success = true;
58
59 if ($success == true)
813eba2f 60 sqimap_mailbox_delete($imapConnection, $boxes[$i]["unformatted"]);
d2f34a3d 61 if ($auto_expunge)
62 sqimap_mailbox_expunge($imapConnection, $mailbox);
54e3c1d8 63 }
64 }
d92b6f31 65 } else { /** if they do NOT wish to move messages to the trash (or cannot)**/
66 fputs($imapConnection, "1 LIST \"$mailbox\" *\n");
813eba2f 67 $data = sqimap_read_data($imapConnection, "1", false, $response, $message);
d92b6f31 68 while (substr($data[0], strpos($data[0], " ")+1, 4) == "LIST") {
7ce342dc 69 for ($i = 0; $i < count($boxes); $i++) {
813eba2f 70 if (($boxes[$i]["unformatted"] == $mailbox) ||
71 (substr($boxes[$i]["unformatted"], 0, strlen($mailbox . $dm)) == $mailbox . $dm)) {
72 sqimap_mailbox_delete($imapConnection, $boxes[$i]["unformatted"], $dm);
d92b6f31 73 }
54e3c1d8 74 }
d2f34a3d 75 if ($auto_expunge)
76 sqimap_mailbox_expunge($imapConnection, $mailbox);
d92b6f31 77 fputs($imapConnection, "1 LIST \"$mailbox\" *\n");
813eba2f 78 $data = sqimap_read_data($imapConnection , "1", false, $response, $message);
54e3c1d8 79 }
8c7dfc99 80 }
b40316f9 81
54e3c1d8 82 /** Log out this session **/
8c7dfc99 83 fputs($imapConnection, "1 logout");
b40316f9 84
91f999f6 85 echo "<FONT FACE=\"Arial,Helvetica\">";
aff57ea5 86 echo "<BR><BR><BR><CENTER><B>";
87 echo _("Folder Deleted!");
88 echo "</B><BR><BR>";
89 echo _("The folder has been successfully deleted.");
bd8bf491 90 echo "<BR><A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>";
aff57ea5 91 echo _("Click here");
bd8bf491 92 echo "</A> ";
aff57ea5 93 echo _("to continue.");
91f999f6 94 echo "</CENTER></FONT>";
95
f8f9bed9 96 echo "</BODY></HTML>";
b40316f9 97?>