XHTML fixes and making use of forms.php
[squirrelmail.git] / src / folders_delete.php
CommitLineData
59177427 1<?php
895905c0 2
35586184 3/**
4 * folders_delete.php
5 *
82d304a0 6 * Copyright (c) 1999-2004 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 *
30967a1e 12 * @version $Id$
8f6f9ba5 13 * @package squirrelmail
35586184 14 */
15
30967a1e 16/**
17 * Path for SquirrelMail required files.
18 * @ignore
19 */
86725763 20define('SM_PATH','../');
35586184 21
86725763 22/* SquirrelMail required files. */
08185f2a 23require_once(SM_PATH . 'include/validate.php');
8650e9e1 24require_once(SM_PATH . 'functions/global.php');
86725763 25require_once(SM_PATH . 'functions/imap.php');
86725763 26require_once(SM_PATH . 'functions/tree.php');
27require_once(SM_PATH . 'functions/display_messages.php');
b7f83b61 28require_once(SM_PATH . 'functions/html.php');
62366261 29require_once(SM_PATH . 'functions/forms.php');
2a32fc83 30
1c52ba77 31/*
b7f83b61 32 * Incoming values:
33 * $mailbox - selected mailbox from the form
34 */
1c52ba77 35
a32985a5 36/* globals */
1e12d1ff 37sqgetGlobalVar('key', $key, SQ_COOKIE);
38sqgetGlobalVar('username', $username, SQ_SESSION);
39sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
40sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
41sqgetGlobalVar('mailbox', $mailbox, SQ_POST);
a32985a5 42/* end globals */
43
0037f048 44if ($mailbox == '') {
45 displayPageHeader($color, 'None');
b7f83b61 46
47 plain_error_message(_("You have not selected a folder to delete. Please do so.").
ff0969a0 48 '<br /><a href="../src/folders.php">'._("Click here to go back").'</a>.', $color);
b7f83b61 49 exit;
50}
51
1e12d1ff 52if ( sqgetGlobalVar('backingout', $tmp, SQ_POST) ) {
b7f83b61 53 $location = get_location();
54 header ("Location: $location/folders.php");
0037f048 55 exit;
56}
57
1e12d1ff 58if( !sqgetGlobalVar('confirmed', $tmp, SQ_POST) ) {
b7f83b61 59 displayPageHeader($color, 'None');
60
ff0969a0 61 echo '<br />' .
b7f83b61 62 html_tag( 'table', '', 'center', '', 'width="95%" border="0"' ) .
63 html_tag( 'tr',
64 html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[0] )
65 ) .
66 html_tag( 'tr' ) .
67 html_tag( 'td', '', 'center', $color[4] ) .
cf1c6e17 68 sprintf(_("Are you sure you want to delete %s?"), str_replace(array(' ','<','>'),array('&nbsp;','&lt;','&gt;'),imap_utf7_decode_local($mailbox))).
4eb9284b 69 addForm('folders_delete.php', 'post')."<p>\n".
ff0969a0 70 addHidden('mailbox', $mailbox).
4eb9284b 71 addSubmit(_("Yes"), 'confirmed').
72 addSubmit(_("No"), 'backingout').
ff0969a0 73 '</p></form><br /></td></tr></table>';
b7f83b61 74
75 exit;
76}
0037f048 77
1c52ba77 78$imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
b7f83b61 79
1c52ba77 80$boxes = sqimap_mailbox_list ($imap_stream);
b7f83b61 81$numboxes = count($boxes);
82
a32985a5 83global $delete_folder;
1c52ba77 84
85if (substr($mailbox, -1) == $delimiter)
86 $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1);
87else
88 $mailbox_no_dm = $mailbox;
89
90/** lets see if we CAN move folders to the trash.. otherwise,
2c1dc652 91 ** just delete them **/
b140c154 92
b7f83b61 93/* Courier IMAP doesn't like subfolders of Trash
94 * If global options say we can't move it into Trash
95 * If it's already a subfolder of trash, we'll have to delete it */
96if (strtolower($imap_server_type) == 'courier' ||
97 (isset($delete_folder) && $delete_folder) ||
98 eregi('^'.$trash_folder.'.+', $mailbox) )
99{
100 $can_move_to_trash = FALSE;
1c52ba77 101}
b140c154 102
0037f048 103/* Otherwise, check if trash folder exits and support sub-folders */
1c52ba77 104else {
b7f83b61 105 for ($i = 0; $i < $numboxes; $i++) {
106 if ($boxes[$i]['unformatted'] == $trash_folder) {
e54e0b89 107 $can_move_to_trash = !in_array('noinferiors', $boxes[$i]['flags']);
1c52ba77 108 }
109 }
110}
111
112/** First create the top node in the tree **/
b7f83b61 113for ($i = 0; $i < $numboxes; $i++) {
114 if (($boxes[$i]['unformatted-dm'] == $mailbox) && (strlen($boxes[$i]['unformatted-dm']) == strlen($mailbox))) {
115 $foldersTree[0]['value'] = $mailbox;
116 $foldersTree[0]['doIHaveChildren'] = false;
1c52ba77 117 continue;
118 }
119}
b7f83b61 120
0037f048 121/* Now create the nodes for subfolders of the parent folder
122 You can tell that it is a subfolder by tacking the mailbox delimiter
123 on the end of the $mailbox string, and compare to that. */
b7f83b61 124for ($i = 0; $i < $numboxes; $i++) {
125 if (substr($boxes[$i]['unformatted'], 0, strlen($mailbox_no_dm . $delimiter)) == ($mailbox_no_dm . $delimiter)) {
126 addChildNodeToTree($boxes[$i]["unformatted"], $boxes[$i]['unformatted-dm'], $foldersTree);
1c52ba77 127 }
128}
b40316f9 129
1c52ba77 130/** Lets start removing the folders and messages **/
131if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/
132 walkTreeInPostOrderCreatingFoldersUnderTrash(0, $imap_stream, $foldersTree, $mailbox);
133 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
134} else { /** if they do NOT wish to move messages to the trash (or cannot)**/
135 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
136}
137
138/** Log out this session **/
139sqimap_logout($imap_stream);
140
141$location = get_location();
142header ("Location: $location/folders.php?success=delete");
b7f83b61 143
ff0969a0 144?>