6 * Copyright (c) 1999-2004 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
13 * @package squirrelmail
16 /** Path for SquirrelMail required files. */
17 define('SM_PATH','../');
19 /* SquirrelMail required files. */
20 require_once(SM_PATH
. 'include/validate.php');
21 require_once(SM_PATH
. 'functions/global.php');
22 require_once(SM_PATH
. 'functions/imap.php');
23 require_once(SM_PATH
. 'functions/tree.php');
24 require_once(SM_PATH
. 'functions/display_messages.php');
25 require_once(SM_PATH
. 'functions/html.php');
29 * $mailbox - selected mailbox from the form
33 sqgetGlobalVar('key', $key, SQ_COOKIE
);
34 sqgetGlobalVar('username', $username, SQ_SESSION
);
35 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
36 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
37 sqgetGlobalVar('mailbox', $mailbox, SQ_POST
);
41 displayPageHeader($color, 'None');
43 plain_error_message(_("You have not selected a folder to delete. Please do so.").
44 '<BR><A HREF="../src/folders.php">'._("Click here to go back").'</A>.', $color);
48 if ( sqgetGlobalVar('backingout', $tmp, SQ_POST
) ) {
49 $location = get_location();
50 header ("Location: $location/folders.php");
54 if( !sqgetGlobalVar('confirmed', $tmp, SQ_POST
) ) {
55 displayPageHeader($color, 'None');
58 html_tag( 'table', '', 'center', '', 'width="95%" border="0"' ) .
60 html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[0] )
63 html_tag( 'td', '', 'center', $color[4] ) .
64 sprintf(_("Are you sure you want to delete %s?"), imap_utf7_decode_local($mailbox)).
65 '<FORM ACTION="folders_delete.php" METHOD="POST"><p>'.
67 '<INPUT TYPE=HIDDEN NAME="mailbox" VALUE="' . htmlspecialchars($mailbox) . "\">\n" .
68 '<INPUT TYPE=SUBMIT NAME="confirmed" VALUE="'._("Yes")."\">\n".
69 '<INPUT TYPE=SUBMIT NAME="backingout" VALUE="'._("No")."\">\n".
70 '</p></FORM><BR></td></tr></table>';
75 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
77 $boxes = sqimap_mailbox_list ($imap_stream);
78 $numboxes = count($boxes);
80 global $delete_folder;
82 if (substr($mailbox, -1) == $delimiter)
83 $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1);
85 $mailbox_no_dm = $mailbox;
87 /** lets see if we CAN move folders to the trash.. otherwise,
88 ** just delete them **/
90 /* Courier IMAP doesn't like subfolders of Trash
91 * If global options say we can't move it into Trash
92 * If it's already a subfolder of trash, we'll have to delete it */
93 if (strtolower($imap_server_type) == 'courier' ||
94 (isset($delete_folder) && $delete_folder) ||
95 eregi('^'.$trash_folder.'.+', $mailbox) )
97 $can_move_to_trash = FALSE;
100 /* Otherwise, check if trash folder exits and support sub-folders */
102 for ($i = 0; $i < $numboxes; $i++
) {
103 if ($boxes[$i]['unformatted'] == $trash_folder) {
104 $can_move_to_trash = !in_array('noinferiors', $boxes[$i]['flags']);
109 /** First create the top node in the tree **/
110 for ($i = 0; $i < $numboxes; $i++
) {
111 if (($boxes[$i]['unformatted-dm'] == $mailbox) && (strlen($boxes[$i]['unformatted-dm']) == strlen($mailbox))) {
112 $foldersTree[0]['value'] = $mailbox;
113 $foldersTree[0]['doIHaveChildren'] = false;
118 /* Now create the nodes for subfolders of the parent folder
119 You can tell that it is a subfolder by tacking the mailbox delimiter
120 on the end of the $mailbox string, and compare to that. */
121 for ($i = 0; $i < $numboxes; $i++
) {
122 if (substr($boxes[$i]['unformatted'], 0, strlen($mailbox_no_dm . $delimiter)) == ($mailbox_no_dm . $delimiter)) {
123 addChildNodeToTree($boxes[$i]["unformatted"], $boxes[$i]['unformatted-dm'], $foldersTree);
127 /** Lets start removing the folders and messages **/
128 if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/
129 walkTreeInPostOrderCreatingFoldersUnderTrash(0, $imap_stream, $foldersTree, $mailbox);
130 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
131 } else { /** if they do NOT wish to move messages to the trash (or cannot)**/
132 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
135 /** Log out this session **/
136 sqimap_logout($imap_stream);
138 $location = get_location();
139 header ("Location: $location/folders.php?success=delete");