Keep on going... rg=0
[squirrelmail.git] / src / folders_delete.php
CommitLineData
59177427 1<?php
895905c0 2
35586184 3/**
4 * folders_delete.php
5 *
15e6162e 6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
35586184 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Deltes folders from the IMAP server.
10 * Called from the folders.php
11 *
12 * $Id$
13 */
14
86725763 15/* Path for SquirrelMail required files. */
16define('SM_PATH','../');
35586184 17
86725763 18/* SquirrelMail required files. */
08185f2a 19require_once(SM_PATH . 'include/validate.php');
86725763 20require_once(SM_PATH . 'functions/imap.php');
21require_once(SM_PATH . 'functions/array.php');
22require_once(SM_PATH . 'functions/tree.php');
23require_once(SM_PATH . 'functions/display_messages.php');
2a32fc83 24
1c52ba77 25/*
26* Incoming values:
27* $mailbox - selected mailbox from the form
28*/
29
a32985a5 30/* globals */
31$username = $_SESSION['username'];
32$key = $_COOKIE['key'];
33$delimiter = $_SESSION['delimiter'];
34$onetimepad = $_SESSION['onetimepad'];
35
36$mailbox = $_POST['mailbox'];
37
38/* end globals */
39
0037f048 40if ($mailbox == '') {
41 displayPageHeader($color, 'None');
42 echo "<html><body bgcolor=$color[4]>";
43 plain_error_message(_("You have not selected a folder to delete. Please do so.")."<BR><A HREF=\"../src/folders.php\">"._("Click here to go back")."</A>.", $color);
44 exit;
45}
46
47
1c52ba77 48$imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
49$boxes = sqimap_mailbox_list ($imap_stream);
a32985a5 50global $delete_folder;
1c52ba77 51
52if (substr($mailbox, -1) == $delimiter)
53 $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1);
54else
55 $mailbox_no_dm = $mailbox;
56
57/** lets see if we CAN move folders to the trash.. otherwise,
2c1dc652 58 ** just delete them **/
b140c154 59
0037f048 60/* Courier IMAP doesn't like subfolders of Trash */
1c52ba77 61if (strtolower($imap_server_type) == "courier") {
62 $can_move_to_trash = false;
63}
b140c154 64
0037f048 65/* If global options say we can't move it into Trash */
4e85a37f 66else if(isset($delete_folder) && $delete_folder == true) {
67 $can_move_to_trash = false;
68}
69
0037f048 70/* If it's already a subfolder of trash, we'll have to delete it */
1c52ba77 71else if(eregi("^".$trash_folder.".+", $mailbox)) {
b140c154 72
1c52ba77 73 $can_move_to_trash = false;
b140c154 74
1c52ba77 75}
b140c154 76
0037f048 77/* Otherwise, check if trash folder exits and support sub-folders */
1c52ba77 78else {
79 for ($i = 0; $i < count($boxes); $i++) {
80 if ($boxes[$i]["unformatted"] == $trash_folder) {
e54e0b89 81 $can_move_to_trash = !in_array('noinferiors', $boxes[$i]['flags']);
1c52ba77 82 }
83 }
84}
85
86/** First create the top node in the tree **/
87for ($i = 0;$i < count($boxes);$i++) {
88 if (($boxes[$i]["unformatted-dm"] == $mailbox) && (strlen($boxes[$i]["unformatted-dm"]) == strlen($mailbox))) {
89 $foldersTree[0]["value"] = $mailbox;
90 $foldersTree[0]["doIHaveChildren"] = false;
91 continue;
92 }
93}
0037f048 94/* Now create the nodes for subfolders of the parent folder
95 You can tell that it is a subfolder by tacking the mailbox delimiter
96 on the end of the $mailbox string, and compare to that. */
1c52ba77 97$j = 0;
98for ($i = 0;$i < count($boxes);$i++) {
99 if (substr($boxes[$i]["unformatted"], 0, strlen($mailbox_no_dm . $delimiter)) == ($mailbox_no_dm . $delimiter)) {
100 addChildNodeToTree($boxes[$i]["unformatted"], $boxes[$i]["unformatted-dm"], $foldersTree);
101 }
102}
0037f048 103/* simpleWalkTreePre(0, $foldersTree); */
b40316f9 104
1c52ba77 105/** Lets start removing the folders and messages **/
106if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/
107 walkTreeInPostOrderCreatingFoldersUnderTrash(0, $imap_stream, $foldersTree, $mailbox);
108 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
109} else { /** if they do NOT wish to move messages to the trash (or cannot)**/
110 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
111}
112
113/** Log out this session **/
114sqimap_logout($imap_stream);
115
116$location = get_location();
117header ("Location: $location/folders.php?success=delete");
118/*
119echo "<BR><BR><BR><CENTER><B>";
120echo _("Folder Deleted!");
121echo "</B><BR><BR>";
122echo _("The folder has been successfully deleted.");
123echo "<BR><A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>";
124echo _("Click here");
125echo "</A> ";
126echo _("to continue.");
127echo "</CENTER>";
128
129echo "</BODY></HTML>";
130*/
525b7ae6 131?>