NO it's not a habit from me.
[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 /* Path for SquirrelMail required files. */
16 define('SM_PATH','../');
17
18 /* SquirrelMail required files. */
19 require_once(SM_PATH . 'include/validate.php');
20 require_once(SM_PATH . 'functions/imap.php');
21 require_once(SM_PATH . 'functions/array.php');
22 require_once(SM_PATH . 'functions/tree.php');
23 require_once(SM_PATH . 'functions/display_messages.php');
24
25 /*
26 * Incoming values:
27 * $mailbox - selected mailbox from the form
28 */
29
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
40 if ($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
48 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
49 $boxes = sqimap_mailbox_list ($imap_stream);
50 global $delete_folder;
51
52 if (substr($mailbox, -1) == $delimiter)
53 $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1);
54 else
55 $mailbox_no_dm = $mailbox;
56
57 /** lets see if we CAN move folders to the trash.. otherwise,
58 ** just delete them **/
59
60 /* Courier IMAP doesn't like subfolders of Trash */
61 if (strtolower($imap_server_type) == "courier") {
62 $can_move_to_trash = false;
63 }
64
65 /* If global options say we can't move it into Trash */
66 else if(isset($delete_folder) && $delete_folder == true) {
67 $can_move_to_trash = false;
68 }
69
70 /* If it's already a subfolder of trash, we'll have to delete it */
71 else if(eregi("^".$trash_folder.".+", $mailbox)) {
72
73 $can_move_to_trash = false;
74
75 }
76
77 /* Otherwise, check if trash folder exits and support sub-folders */
78 else {
79 for ($i = 0; $i < count($boxes); $i++) {
80 if ($boxes[$i]["unformatted"] == $trash_folder) {
81 $can_move_to_trash = !in_array('noinferiors', $boxes[$i]['flags']);
82 }
83 }
84 }
85
86 /** First create the top node in the tree **/
87 for ($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 }
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. */
97 $j = 0;
98 for ($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 }
103 /* simpleWalkTreePre(0, $foldersTree); */
104
105 /** Lets start removing the folders and messages **/
106 if (($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 **/
114 sqimap_logout($imap_stream);
115
116 $location = get_location();
117 header ("Location: $location/folders.php?success=delete");
118 /*
119 echo "<BR><BR><BR><CENTER><B>";
120 echo _("Folder Deleted!");
121 echo "</B><BR><BR>";
122 echo _("The folder has been successfully deleted.");
123 echo "<BR><A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>";
124 echo _("Click here");
125 echo "</A> ";
126 echo _("to continue.");
127 echo "</CENTER>";
128
129 echo "</BODY></HTML>";
130 */
131 ?>