6 * Copyright (c) 1999-2003 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/global.php');
21 require_once(SM_PATH
. 'functions/imap.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 sqgetGlobalVar('key', $key, SQ_COOKIE
);
33 sqgetGlobalVar('username', $username, SQ_SESSION
);
34 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
35 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
36 sqgetGlobalVar('mailbox', $mailbox, SQ_POST
);
40 displayPageHeader($color, 'None');
42 plain_error_message(_("You have not selected a folder to delete. Please do so.").
43 '<BR><A HREF="../src/folders.php">'._("Click here to go back").'</A>.', $color);
47 if ( sqgetGlobalVar('backingout', $tmp, SQ_POST
) ) {
48 $location = get_location();
49 header ("Location: $location/folders.php");
53 if( !sqgetGlobalVar('confirmed', $tmp, SQ_POST
) ) {
54 displayPageHeader($color, 'None');
57 html_tag( 'table', '', 'center', '', 'width="95%" border="0"' ) .
59 html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[0] )
62 html_tag( 'td', '', 'center', $color[4] ) .
63 sprintf(_("Are you sure you want to delete %s?"), imap_utf7_decode_local($mailbox)).
64 '<FORM ACTION="folders_delete.php" METHOD="POST"><p>'.
66 '<INPUT TYPE=HIDDEN NAME="mailbox" VALUE="'.$mailbox."\">\n" .
67 '<INPUT TYPE=SUBMIT NAME="confirmed" VALUE="'._("Yes")."\">\n".
68 '<INPUT TYPE=SUBMIT NAME="backingout" VALUE="'._("No")."\">\n".
69 '</p></FORM><BR></td></tr></table>';
74 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
76 $boxes = sqimap_mailbox_list ($imap_stream);
77 $numboxes = count($boxes);
79 global $delete_folder;
81 if (substr($mailbox, -1) == $delimiter)
82 $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1);
84 $mailbox_no_dm = $mailbox;
86 /** lets see if we CAN move folders to the trash.. otherwise,
87 ** just delete them **/
89 /* Courier IMAP doesn't like subfolders of Trash
90 * If global options say we can't move it into Trash
91 * If it's already a subfolder of trash, we'll have to delete it */
92 if (strtolower($imap_server_type) == 'courier' ||
93 (isset($delete_folder) && $delete_folder) ||
94 eregi('^'.$trash_folder.'.+', $mailbox) )
96 $can_move_to_trash = FALSE;
99 /* Otherwise, check if trash folder exits and support sub-folders */
101 for ($i = 0; $i < $numboxes; $i++
) {
102 if ($boxes[$i]['unformatted'] == $trash_folder) {
103 $can_move_to_trash = !in_array('noinferiors', $boxes[$i]['flags']);
108 /** First create the top node in the tree **/
109 for ($i = 0; $i < $numboxes; $i++
) {
110 if (($boxes[$i]['unformatted-dm'] == $mailbox) && (strlen($boxes[$i]['unformatted-dm']) == strlen($mailbox))) {
111 $foldersTree[0]['value'] = $mailbox;
112 $foldersTree[0]['doIHaveChildren'] = false;
117 /* Now create the nodes for subfolders of the parent folder
118 You can tell that it is a subfolder by tacking the mailbox delimiter
119 on the end of the $mailbox string, and compare to that. */
120 for ($i = 0; $i < $numboxes; $i++
) {
121 if (substr($boxes[$i]['unformatted'], 0, strlen($mailbox_no_dm . $delimiter)) == ($mailbox_no_dm . $delimiter)) {
122 addChildNodeToTree($boxes[$i]["unformatted"], $boxes[$i]['unformatted-dm'], $foldersTree);
126 /** Lets start removing the folders and messages **/
127 if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/
128 walkTreeInPostOrderCreatingFoldersUnderTrash(0, $imap_stream, $foldersTree, $mailbox);
129 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
130 } else { /** if they do NOT wish to move messages to the trash (or cannot)**/
131 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
134 /** Log out this session **/
135 sqimap_logout($imap_stream);
137 $location = get_location();
138 header ("Location: $location/folders.php?success=delete");