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