Fix download link for vcard.
[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');
86725763 20require_once(SM_PATH . 'functions/imap.php');
86725763 21require_once(SM_PATH . 'functions/tree.php');
22require_once(SM_PATH . 'functions/display_messages.php');
b7f83b61 23require_once(SM_PATH . 'functions/html.php');
2a32fc83 24
1c52ba77 25/*
b7f83b61 26 * Incoming values:
27 * $mailbox - selected mailbox from the form
28 */
1c52ba77 29
a32985a5 30/* globals */
1e12d1ff 31sqgetGlobalVar('key', $key, SQ_COOKIE);
32sqgetGlobalVar('username', $username, SQ_SESSION);
33sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
34sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
35sqgetGlobalVar('mailbox', $mailbox, SQ_POST);
a32985a5 36/* end globals */
37
0037f048 38if ($mailbox == '') {
39 displayPageHeader($color, 'None');
b7f83b61 40
41 plain_error_message(_("You have not selected a folder to delete. Please do so.").
42 '<BR><A HREF="../src/folders.php">'._("Click here to go back").'</A>.', $color);
43 exit;
44}
45
1e12d1ff 46if ( sqgetGlobalVar('backingout', $tmp, SQ_POST) ) {
b7f83b61 47 $location = get_location();
48 header ("Location: $location/folders.php");
0037f048 49 exit;
50}
51
1e12d1ff 52if( !sqgetGlobalVar('confirmed', $tmp, SQ_POST) ) {
b7f83b61 53 displayPageHeader($color, 'None');
54
55 echo '<br>' .
56 html_tag( 'table', '', 'center', '', 'width="95%" border="0"' ) .
57 html_tag( 'tr',
58 html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[0] )
59 ) .
60 html_tag( 'tr' ) .
61 html_tag( 'td', '', 'center', $color[4] ) .
334a77f8 62 sprintf(_("Are you sure you want to delete %s?"), imap_utf7_decode_local($mailbox)).
b7f83b61 63 '<FORM ACTION="folders_delete.php" METHOD="POST"><p>'.
64
65 '<INPUT TYPE=HIDDEN NAME="mailbox" VALUE="'.$mailbox."\">\n" .
66 '<INPUT TYPE=SUBMIT NAME="confirmed" VALUE="'._("Yes")."\">\n".
67 '<INPUT TYPE=SUBMIT NAME="backingout" VALUE="'._("No")."\">\n".
68 '</p></FORM><BR></td></tr></table>';
69
70 exit;
71}
0037f048 72
1c52ba77 73$imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
b7f83b61 74
1c52ba77 75$boxes = sqimap_mailbox_list ($imap_stream);
b7f83b61 76$numboxes = count($boxes);
77
a32985a5 78global $delete_folder;
1c52ba77 79
80if (substr($mailbox, -1) == $delimiter)
81 $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1);
82else
83 $mailbox_no_dm = $mailbox;
84
85/** lets see if we CAN move folders to the trash.. otherwise,
2c1dc652 86 ** just delete them **/
b140c154 87
b7f83b61 88/* Courier IMAP doesn't like subfolders of Trash
89 * If global options say we can't move it into Trash
90 * If it's already a subfolder of trash, we'll have to delete it */
91if (strtolower($imap_server_type) == 'courier' ||
92 (isset($delete_folder) && $delete_folder) ||
93 eregi('^'.$trash_folder.'.+', $mailbox) )
94{
95 $can_move_to_trash = FALSE;
1c52ba77 96}
b140c154 97
0037f048 98/* Otherwise, check if trash folder exits and support sub-folders */
1c52ba77 99else {
b7f83b61 100 for ($i = 0; $i < $numboxes; $i++) {
101 if ($boxes[$i]['unformatted'] == $trash_folder) {
e54e0b89 102 $can_move_to_trash = !in_array('noinferiors', $boxes[$i]['flags']);
1c52ba77 103 }
104 }
105}
106
107/** First create the top node in the tree **/
b7f83b61 108for ($i = 0; $i < $numboxes; $i++) {
109 if (($boxes[$i]['unformatted-dm'] == $mailbox) && (strlen($boxes[$i]['unformatted-dm']) == strlen($mailbox))) {
110 $foldersTree[0]['value'] = $mailbox;
111 $foldersTree[0]['doIHaveChildren'] = false;
1c52ba77 112 continue;
113 }
114}
b7f83b61 115
0037f048 116/* Now create the nodes for subfolders of the parent folder
117 You can tell that it is a subfolder by tacking the mailbox delimiter
118 on the end of the $mailbox string, and compare to that. */
b7f83b61 119for ($i = 0; $i < $numboxes; $i++) {
120 if (substr($boxes[$i]['unformatted'], 0, strlen($mailbox_no_dm . $delimiter)) == ($mailbox_no_dm . $delimiter)) {
121 addChildNodeToTree($boxes[$i]["unformatted"], $boxes[$i]['unformatted-dm'], $foldersTree);
1c52ba77 122 }
123}
b40316f9 124
1c52ba77 125/** Lets start removing the folders and messages **/
126if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/
127 walkTreeInPostOrderCreatingFoldersUnderTrash(0, $imap_stream, $foldersTree, $mailbox);
128 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
129} else { /** if they do NOT wish to move messages to the trash (or cannot)**/
130 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
131}
132
133/** Log out this session **/
134sqimap_logout($imap_stream);
135
136$location = get_location();
137header ("Location: $location/folders.php?success=delete");
b7f83b61 138
525b7ae6 139?>