development work on the Deliver class.
[squirrelmail.git] / src / folders_delete.php
... / ...
CommitLineData
1<?php
2
3/**
4 * folders_delete.php
5 *
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
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
15
16require_once('../src/validate.php');
17require_once('../functions/imap.php');
18require_once('../functions/array.php');
19require_once('../functions/tree.php');
20require_once('../functions/display_messages.php');
21
22/*
23* Incoming values:
24* $mailbox - selected mailbox from the form
25*/
26
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
35$imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
36$boxes = sqimap_mailbox_list ($imap_stream);
37global $delimiter, $delete_folder;
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,
45 ** just delete them **/
46
47/* Courier IMAP doesn't like subfolders of Trash */
48if (strtolower($imap_server_type) == "courier") {
49 $can_move_to_trash = false;
50}
51
52/* If global options say we can't move it into Trash */
53else if(isset($delete_folder) && $delete_folder == true) {
54 $can_move_to_trash = false;
55}
56
57/* If it's already a subfolder of trash, we'll have to delete it */
58else if(eregi("^".$trash_folder.".+", $mailbox)) {
59
60 $can_move_to_trash = false;
61
62}
63
64/* Otherwise, check if trash folder exits and support sub-folders */
65else {
66 for ($i = 0; $i < count($boxes); $i++) {
67 if ($boxes[$i]["unformatted"] == $trash_folder) {
68 $can_move_to_trash = !in_array('noinferiors', $boxes[$i]['flags']);
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}
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;
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}
90/* simpleWalkTreePre(0, $foldersTree); */
91
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*/
118?>