check if safe_mode is enabled (putenv is not allowed then) and
[squirrelmail.git] / src / folders_delete.php
CommitLineData
59177427 1<?php
ef870322 2 /**
3 ** folders_delete.php
4 **
5 ** Copyright (c) 1999-2000 The SquirrelMail development team
6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
7 **
8 ** Deltes folders from the IMAP server.
9 ** Called from the folders.php
10 **/
11
2a32fc83 12 session_start();
13
97dd6a62 14 /*
15 * Incoming values:
16 * $mailbox - selected mailbox from the form
17 */
18
d068c0ec 19 if (!isset($config_php))
20 include("../config/config.php");
21 if (!isset($strings_php))
22 include("../functions/strings.php");
23 if (!isset($page_header_php))
24 include("../functions/page_header.php");
25 if (!isset($imap_php))
26 include("../functions/imap.php");
27 if (!isset($array_php))
28 include("../functions/array.php");
97dd6a62 29 if (!isset($tree_php))
30 include("../functions/tree.php");
b40316f9 31
d3cdb279 32 include("../src/load_prefs.php");
33
91f999f6 34
e1469126 35 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
97dd6a62 36 $boxes = sqimap_mailbox_list ($imap_stream);
37 $dm = sqimap_get_delimiter($imap_stream);
7aaa81fc 38 $mailbox = sqStripSlashes($mailbox);
cdee225a 39
abddc974 40 if (substr($mailbox, -1) == $dm)
41 $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1);
42 else
43 $mailbox_no_dm = $mailbox;
d92b6f31 44
2c1dc652 45 /** lets see if we CAN move folders to the trash.. otherwise,
46 ** just delete them **/
b140c154 47
48 // Courier IMAP doesn't like subfolders of Trash
2c1dc652 49 if (strtolower($imap_server_type) == "courier") {
2c1dc652 50 $can_move_to_trash = false;
b140c154 51 }
52
53 // If it's already a subfolder of trash, we'll have to delete it
54 else if(eregi("^".$trash_folder.".+", $mailbox)) {
55
56 $can_move_to_trash = false;
57
58 }
59
60 // Otherwise, check if trash folder exits and support sub-folders
61 else {
2c1dc652 62 for ($i = 0; $i < count($boxes); $i++) {
63 if ($boxes[$i]["unformatted"] == $trash_folder) {
64 $can_move_to_trash = true;
65 for ($j = 0; $j < count($boxes[$i]["flags"]); $j++) {
b140c154 66 if (strtolower($boxes[$i]["flags"][$j]) == "noinferiors")
67 $can_move_to_trash = false;
2c1dc652 68 }
813eba2f 69 }
70 }
d92b6f31 71 }
54e3c1d8 72
97dd6a62 73 /** First create the top node in the tree **/
74 for ($i = 0;$i < count($boxes);$i++) {
abddc974 75 if (($boxes[$i]["unformatted-dm"] == $mailbox) && (strlen($boxes[$i]["unformatted-dm"]) == strlen($mailbox))) {
97dd6a62 76 $foldersTree[0]["value"] = $mailbox;
77 $foldersTree[0]["doIHaveChildren"] = false;
78 continue;
54e3c1d8 79 }
97dd6a62 80 }
81 // Now create the nodes for subfolders of the parent folder
82 // You can tell that it is a subfolder by tacking the mailbox delimiter
83 // on the end of the $mailbox string, and compare to that.
84 $j = 0;
85 for ($i = 0;$i < count($boxes);$i++) {
abddc974 86 if (substr($boxes[$i]["unformatted"], 0, strlen($mailbox_no_dm . $dm)) == ($mailbox_no_dm . $dm)) {
abddc974 87 addChildNodeToTree($boxes[$i]["unformatted"], $boxes[$i]["unformatted-dm"], $foldersTree);
54e3c1d8 88 }
8c7dfc99 89 }
abddc974 90// simpleWalkTreePre(0, $foldersTree);
b40316f9 91
97dd6a62 92 /** Lets start removing the folders and messages **/
93 if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/
94 walkTreeInPostOrderCreatingFoldersUnderTrash(0, $imap_stream, $foldersTree, $dm, $mailbox);
95 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
96 } else { /** if they do NOT wish to move messages to the trash (or cannot)**/
97 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
98 }
99
54e3c1d8 100 /** Log out this session **/
97dd6a62 101 sqimap_logout($imap_stream);
b40316f9 102
1195c340 103 $location = get_location();
104 header ("Location: $location/folders.php?success=delete");
105 /*
aff57ea5 106 echo "<BR><BR><BR><CENTER><B>";
107 echo _("Folder Deleted!");
108 echo "</B><BR><BR>";
109 echo _("The folder has been successfully deleted.");
9f2215a1 110 echo "<BR><A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>";
aff57ea5 111 echo _("Click here");
bd8bf491 112 echo "</A> ";
aff57ea5 113 echo _("to continue.");
aae41ae9 114 echo "</CENTER>";
91f999f6 115
f8f9bed9 116 echo "</BODY></HTML>";
1195c340 117 */
b40316f9 118?>