allow_call_time_pass_reference = Off
[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
35586184 15
16require_once('../src/validate.php');
17require_once('../functions/imap.php');
18require_once('../functions/array.php');
19require_once('../functions/tree.php');
04e7c05f 20require_once('../functions/display_messages.php');
2a32fc83 21
1c52ba77 22/*
23* Incoming values:
24* $mailbox - selected mailbox from the form
25*/
26
0037f048 27if ($mailbox == '') {
28 displayPageHeader($color, 'None');
29 echo "<html><body bgcolor=$color[4]>";
30 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);
31 exit;
32}
33
34
1c52ba77 35$imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
36$boxes = sqimap_mailbox_list ($imap_stream);
4e85a37f 37global $delimiter, $delete_folder;
1c52ba77 38
39if (substr($mailbox, -1) == $delimiter)
40 $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1);
41else
42 $mailbox_no_dm = $mailbox;
43
44/** lets see if we CAN move folders to the trash.. otherwise,
2c1dc652 45 ** just delete them **/
b140c154 46
0037f048 47/* Courier IMAP doesn't like subfolders of Trash */
1c52ba77 48if (strtolower($imap_server_type) == "courier") {
49 $can_move_to_trash = false;
50}
b140c154 51
0037f048 52/* If global options say we can't move it into Trash */
4e85a37f 53else if(isset($delete_folder) && $delete_folder == true) {
54 $can_move_to_trash = false;
55}
56
0037f048 57/* If it's already a subfolder of trash, we'll have to delete it */
1c52ba77 58else if(eregi("^".$trash_folder.".+", $mailbox)) {
b140c154 59
1c52ba77 60 $can_move_to_trash = false;
b140c154 61
1c52ba77 62}
b140c154 63
0037f048 64/* Otherwise, check if trash folder exits and support sub-folders */
1c52ba77 65else {
66 for ($i = 0; $i < count($boxes); $i++) {
67 if ($boxes[$i]["unformatted"] == $trash_folder) {
e54e0b89 68 $can_move_to_trash = !in_array('noinferiors', $boxes[$i]['flags']);
1c52ba77 69 }
70 }
71}
72
73/** First create the top node in the tree **/
74for ($i = 0;$i < count($boxes);$i++) {
75 if (($boxes[$i]["unformatted-dm"] == $mailbox) && (strlen($boxes[$i]["unformatted-dm"]) == strlen($mailbox))) {
76 $foldersTree[0]["value"] = $mailbox;
77 $foldersTree[0]["doIHaveChildren"] = false;
78 continue;
79 }
80}
0037f048 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. */
1c52ba77 84$j = 0;
85for ($i = 0;$i < count($boxes);$i++) {
86 if (substr($boxes[$i]["unformatted"], 0, strlen($mailbox_no_dm . $delimiter)) == ($mailbox_no_dm . $delimiter)) {
87 addChildNodeToTree($boxes[$i]["unformatted"], $boxes[$i]["unformatted-dm"], $foldersTree);
88 }
89}
0037f048 90/* simpleWalkTreePre(0, $foldersTree); */
b40316f9 91
1c52ba77 92/** Lets start removing the folders and messages **/
93if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/
94 walkTreeInPostOrderCreatingFoldersUnderTrash(0, $imap_stream, $foldersTree, $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
100/** Log out this session **/
101sqimap_logout($imap_stream);
102
103$location = get_location();
104header ("Location: $location/folders.php?success=delete");
105/*
106echo "<BR><BR><BR><CENTER><B>";
107echo _("Folder Deleted!");
108echo "</B><BR><BR>";
109echo _("The folder has been successfully deleted.");
110echo "<BR><A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>";
111echo _("Click here");
112echo "</A> ";
113echo _("to continue.");
114echo "</CENTER>";
115
116echo "</BODY></HTML>";
117*/
525b7ae6 118?>