phpdoc blocks
[squirrelmail.git] / src / folders_delete.php
... / ...
CommitLineData
1<?php
2
3/**
4 * folders_delete.php
5 *
6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Deletes folders from the IMAP server.
10 * Called from the folders.php
11 *
12 * $Id$
13 * @package squirrelmail
14 */
15
16/** Path for SquirrelMail required files. */
17define('SM_PATH','../');
18
19/* SquirrelMail required files. */
20require_once(SM_PATH . 'include/validate.php');
21require_once(SM_PATH . 'functions/global.php');
22require_once(SM_PATH . 'functions/imap.php');
23require_once(SM_PATH . 'functions/tree.php');
24require_once(SM_PATH . 'functions/display_messages.php');
25require_once(SM_PATH . 'functions/html.php');
26
27/*
28 * Incoming values:
29 * $mailbox - selected mailbox from the form
30 */
31
32/* globals */
33sqgetGlobalVar('key', $key, SQ_COOKIE);
34sqgetGlobalVar('username', $username, SQ_SESSION);
35sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
36sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
37sqgetGlobalVar('mailbox', $mailbox, SQ_POST);
38/* end globals */
39
40if ($mailbox == '') {
41 displayPageHeader($color, 'None');
42
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);
45 exit;
46}
47
48if ( sqgetGlobalVar('backingout', $tmp, SQ_POST) ) {
49 $location = get_location();
50 header ("Location: $location/folders.php");
51 exit;
52}
53
54if( !sqgetGlobalVar('confirmed', $tmp, SQ_POST) ) {
55 displayPageHeader($color, 'None');
56
57 echo '<br>' .
58 html_tag( 'table', '', 'center', '', 'width="95%" border="0"' ) .
59 html_tag( 'tr',
60 html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[0] )
61 ) .
62 html_tag( 'tr' ) .
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>'.
66
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>';
71
72 exit;
73}
74
75$imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
76
77$boxes = sqimap_mailbox_list ($imap_stream);
78$numboxes = count($boxes);
79
80global $delete_folder;
81
82if (substr($mailbox, -1) == $delimiter)
83 $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1);
84else
85 $mailbox_no_dm = $mailbox;
86
87/** lets see if we CAN move folders to the trash.. otherwise,
88 ** just delete them **/
89
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 */
93if (strtolower($imap_server_type) == 'courier' ||
94 (isset($delete_folder) && $delete_folder) ||
95 eregi('^'.$trash_folder.'.+', $mailbox) )
96{
97 $can_move_to_trash = FALSE;
98}
99
100/* Otherwise, check if trash folder exits and support sub-folders */
101else {
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']);
105 }
106 }
107}
108
109/** First create the top node in the tree **/
110for ($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;
114 continue;
115 }
116}
117
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. */
121for ($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);
124 }
125}
126
127/** Lets start removing the folders and messages **/
128if (($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);
133}
134
135/** Log out this session **/
136sqimap_logout($imap_stream);
137
138$location = get_location();
139header ("Location: $location/folders.php?success=delete");
140
141?>