6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * Deletes folders from the IMAP server.
10 * Called from the folders.php
15 /* Path for SquirrelMail required files. */
16 define('SM_PATH','../');
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 require_once(SM_PATH
. 'functions/html.php');
28 * $mailbox - selected mailbox from the form
32 $username = $_SESSION['username'];
33 $key = $_COOKIE['key'];
34 $delimiter = $_SESSION['delimiter'];
35 $onetimepad = $_SESSION['onetimepad'];
37 $mailbox = $_POST['mailbox'];
42 displayPageHeader($color, 'None');
44 plain_error_message(_("You have not selected a folder to delete. Please do so.").
45 '<BR><A HREF="../src/folders.php">'._("Click here to go back").'</A>.', $color);
49 if (isset($_POST['backingout'])) {
50 $location = get_location();
51 header ("Location: $location/folders.php");
55 if(!isset($_POST['confirmed'])) {
56 displayPageHeader($color, 'None');
59 html_tag( 'table', '', 'center', '', 'width="95%" border="0"' ) .
61 html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[0] )
64 html_tag( 'td', '', 'center', $color[4] ) .
65 sprintf(_("Are you sure you want to delete %s?"), $mailbox).
66 '<FORM ACTION="folders_delete.php" METHOD="POST"><p>'.
68 '<INPUT TYPE=HIDDEN NAME="mailbox" VALUE="'.$mailbox."\">\n" .
69 '<INPUT TYPE=SUBMIT NAME="confirmed" VALUE="'._("Yes")."\">\n".
70 '<INPUT TYPE=SUBMIT NAME="backingout" VALUE="'._("No")."\">\n".
71 '</p></FORM><BR></td></tr></table>';
76 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
78 $boxes = sqimap_mailbox_list ($imap_stream);
79 $numboxes = count($boxes);
81 global $delete_folder;
83 if (substr($mailbox, -1) == $delimiter)
84 $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1);
86 $mailbox_no_dm = $mailbox;
88 /** lets see if we CAN move folders to the trash.. otherwise,
89 ** just delete them **/
91 /* Courier IMAP doesn't like subfolders of Trash
92 * If global options say we can't move it into Trash
93 * If it's already a subfolder of trash, we'll have to delete it */
94 if (strtolower($imap_server_type) == 'courier' ||
95 (isset($delete_folder) && $delete_folder) ||
96 eregi('^'.$trash_folder.'.+', $mailbox) )
98 $can_move_to_trash = FALSE;
101 /* Otherwise, check if trash folder exits and support sub-folders */
103 for ($i = 0; $i < $numboxes; $i++
) {
104 if ($boxes[$i]['unformatted'] == $trash_folder) {
105 $can_move_to_trash = !in_array('noinferiors', $boxes[$i]['flags']);
110 /** First create the top node in the tree **/
111 for ($i = 0; $i < $numboxes; $i++
) {
112 if (($boxes[$i]['unformatted-dm'] == $mailbox) && (strlen($boxes[$i]['unformatted-dm']) == strlen($mailbox))) {
113 $foldersTree[0]['value'] = $mailbox;
114 $foldersTree[0]['doIHaveChildren'] = false;
119 /* Now create the nodes for subfolders of the parent folder
120 You can tell that it is a subfolder by tacking the mailbox delimiter
121 on the end of the $mailbox string, and compare to that. */
122 for ($i = 0; $i < $numboxes; $i++
) {
123 if (substr($boxes[$i]['unformatted'], 0, strlen($mailbox_no_dm . $delimiter)) == ($mailbox_no_dm . $delimiter)) {
124 addChildNodeToTree($boxes[$i]["unformatted"], $boxes[$i]['unformatted-dm'], $foldersTree);
128 /** Lets start removing the folders and messages **/
129 if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/
130 walkTreeInPostOrderCreatingFoldersUnderTrash(0, $imap_stream, $foldersTree, $mailbox);
131 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
132 } else { /** if they do NOT wish to move messages to the trash (or cannot)**/
133 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
136 /** Log out this session **/
137 sqimap_logout($imap_stream);
139 $location = get_location();
140 header ("Location: $location/folders.php?success=delete");