Fixed some mistakes.
[squirrelmail.git] / src / folders_delete.php
CommitLineData
59177427 1<?php
895905c0 2
35586184 3/**
4 * folders_delete.php
5 *
76911253 6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
35586184 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
b7f83b61 9 * Deletes folders from the IMAP server.
35586184 10 * Called from the folders.php
11 *
12 * $Id$
13 */
14
86725763 15/* Path for SquirrelMail required files. */
16define('SM_PATH','../');
35586184 17
86725763 18/* SquirrelMail required files. */
08185f2a 19require_once(SM_PATH . 'include/validate.php');
8650e9e1 20require_once(SM_PATH . 'functions/global.php');
86725763 21require_once(SM_PATH . 'functions/imap.php');
86725763 22require_once(SM_PATH . 'functions/tree.php');
23require_once(SM_PATH . 'functions/display_messages.php');
b7f83b61 24require_once(SM_PATH . 'functions/html.php');
2a32fc83 25
1c52ba77 26/*
b7f83b61 27 * Incoming values:
28 * $mailbox - selected mailbox from the form
29 */
1c52ba77 30
a32985a5 31/* globals */
1e12d1ff 32sqgetGlobalVar('key', $key, SQ_COOKIE);
33sqgetGlobalVar('username', $username, SQ_SESSION);
34sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
35sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
36sqgetGlobalVar('mailbox', $mailbox, SQ_POST);
a32985a5 37/* end globals */
38
0037f048 39if ($mailbox == '') {
40 displayPageHeader($color, 'None');
b7f83b61 41
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);
44 exit;
45}
46
1e12d1ff 47if ( sqgetGlobalVar('backingout', $tmp, SQ_POST) ) {
b7f83b61 48 $location = get_location();
49 header ("Location: $location/folders.php");
0037f048 50 exit;
51}
52
1e12d1ff 53if( !sqgetGlobalVar('confirmed', $tmp, SQ_POST) ) {
b7f83b61 54 displayPageHeader($color, 'None');
55
56 echo '<br>' .
57 html_tag( 'table', '', 'center', '', 'width="95%" border="0"' ) .
58 html_tag( 'tr',
59 html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[0] )
60 ) .
61 html_tag( 'tr' ) .
62 html_tag( 'td', '', 'center', $color[4] ) .
334a77f8 63 sprintf(_("Are you sure you want to delete %s?"), imap_utf7_decode_local($mailbox)).
b7f83b61 64 '<FORM ACTION="folders_delete.php" METHOD="POST"><p>'.
65
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>';
70
71 exit;
72}
0037f048 73
1c52ba77 74$imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
b7f83b61 75
1c52ba77 76$boxes = sqimap_mailbox_list ($imap_stream);
b7f83b61 77$numboxes = count($boxes);
78
a32985a5 79global $delete_folder;
1c52ba77 80
81if (substr($mailbox, -1) == $delimiter)
82 $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1);
83else
84 $mailbox_no_dm = $mailbox;
85
86/** lets see if we CAN move folders to the trash.. otherwise,
2c1dc652 87 ** just delete them **/
b140c154 88
b7f83b61 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 */
92if (strtolower($imap_server_type) == 'courier' ||
93 (isset($delete_folder) && $delete_folder) ||
94 eregi('^'.$trash_folder.'.+', $mailbox) )
95{
96 $can_move_to_trash = FALSE;
1c52ba77 97}
b140c154 98
0037f048 99/* Otherwise, check if trash folder exits and support sub-folders */
1c52ba77 100else {
b7f83b61 101 for ($i = 0; $i < $numboxes; $i++) {
102 if ($boxes[$i]['unformatted'] == $trash_folder) {
e54e0b89 103 $can_move_to_trash = !in_array('noinferiors', $boxes[$i]['flags']);
1c52ba77 104 }
105 }
106}
107
108/** First create the top node in the tree **/
b7f83b61 109for ($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;
1c52ba77 113 continue;
114 }
115}
b7f83b61 116
0037f048 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. */
b7f83b61 120for ($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);
1c52ba77 123 }
124}
b40316f9 125
1c52ba77 126/** Lets start removing the folders and messages **/
127if (($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);
132}
133
134/** Log out this session **/
135sqimap_logout($imap_stream);
136
137$location = get_location();
138header ("Location: $location/folders.php?success=delete");
b7f83b61 139
525b7ae6 140?>