Only show text/plain if show_html_default=0
[squirrelmail.git] / src / folders_delete.php
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
16 require_once('../src/validate.php');
17 require_once('../functions/imap.php');
18 require_once('../functions/array.php');
19 require_once('../functions/tree.php');
20 require_once('../functions/display_messages.php');
21
22 /*
23 * Incoming values:
24 * $mailbox - selected mailbox from the form
25 */
26
27 if ($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);
37 global $delimiter, $delete_folder;
38
39 if (substr($mailbox, -1) == $delimiter)
40 $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1);
41 else
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 */
48 if (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 */
53 else 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 */
58 else 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 */
65 else {
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 **/
74 for ($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;
85 for ($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 **/
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, $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 **/
101 sqimap_logout($imap_stream);
102
103 $location = get_location();
104 header ("Location: $location/folders.php?success=delete");
105 /*
106 echo "<BR><BR><BR><CENTER><B>";
107 echo _("Folder Deleted!");
108 echo "</B><BR><BR>";
109 echo _("The folder has been successfully deleted.");
110 echo "<BR><A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>";
111 echo _("Click here");
112 echo "</A> ";
113 echo _("to continue.");
114 echo "</CENTER>";
115
116 echo "</BODY></HTML>";
117 */
118 ?>