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