fix for save draft
[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
21 /*
22 * Incoming values:
23 * $mailbox - selected mailbox from the form
24 */
25
26 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
27 $boxes = sqimap_mailbox_list ($imap_stream);
28 global $delimiter, $delete_folder;
29
30 if (substr($mailbox, -1) == $delimiter)
31 $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1);
32 else
33 $mailbox_no_dm = $mailbox;
34
35 /** lets see if we CAN move folders to the trash.. otherwise,
36 ** just delete them **/
37
38 // Courier IMAP doesn't like subfolders of Trash
39 if (strtolower($imap_server_type) == "courier") {
40 $can_move_to_trash = false;
41 }
42
43 // If global options say we can't move it into Trash
44 else if(isset($delete_folder) && $delete_folder == true) {
45 $can_move_to_trash = false;
46 }
47
48 // If it's already a subfolder of trash, we'll have to delete it
49 else if(eregi("^".$trash_folder.".+", $mailbox)) {
50
51 $can_move_to_trash = false;
52
53 }
54
55 // Otherwise, check if trash folder exits and support sub-folders
56 else {
57 for ($i = 0; $i < count($boxes); $i++) {
58 if ($boxes[$i]["unformatted"] == $trash_folder) {
59 $can_move_to_trash = !in_array('noinferiors', $boxes[$i]['flags']);
60 }
61 }
62 }
63
64 /** First create the top node in the tree **/
65 for ($i = 0;$i < count($boxes);$i++) {
66 if (($boxes[$i]["unformatted-dm"] == $mailbox) && (strlen($boxes[$i]["unformatted-dm"]) == strlen($mailbox))) {
67 $foldersTree[0]["value"] = $mailbox;
68 $foldersTree[0]["doIHaveChildren"] = false;
69 continue;
70 }
71 }
72 // Now create the nodes for subfolders of the parent folder
73 // You can tell that it is a subfolder by tacking the mailbox delimiter
74 // on the end of the $mailbox string, and compare to that.
75 $j = 0;
76 for ($i = 0;$i < count($boxes);$i++) {
77 if (substr($boxes[$i]["unformatted"], 0, strlen($mailbox_no_dm . $delimiter)) == ($mailbox_no_dm . $delimiter)) {
78 addChildNodeToTree($boxes[$i]["unformatted"], $boxes[$i]["unformatted-dm"], $foldersTree);
79 }
80 }
81 // simpleWalkTreePre(0, $foldersTree);
82
83 /** Lets start removing the folders and messages **/
84 if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/
85 walkTreeInPostOrderCreatingFoldersUnderTrash(0, $imap_stream, $foldersTree, $mailbox);
86 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
87 } else { /** if they do NOT wish to move messages to the trash (or cannot)**/
88 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
89 }
90
91 /** Log out this session **/
92 sqimap_logout($imap_stream);
93
94 $location = get_location();
95 header ("Location: $location/folders.php?success=delete");
96 /*
97 echo "<BR><BR><BR><CENTER><B>";
98 echo _("Folder Deleted!");
99 echo "</B><BR><BR>";
100 echo _("The folder has been successfully deleted.");
101 echo "<BR><A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>";
102 echo _("Click here");
103 echo "</A> ";
104 echo _("to continue.");
105 echo "</CENTER>";
106
107 echo "</BODY></HTML>";
108 */
109 ?>