If stream is FALSE also don't logout
[squirrelmail.git] / src / folders.php
CommitLineData
59177427 1<?php
895905c0 2
35586184 3/**
4 * folders.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 *
9 * Handles all interaction between the user and the other folder
10 * scripts which do most of the work. Also handles the Special
11 * Folders.
12 *
13 * $Id$
14 */
15
86725763 16/* Path for SquirrelMail required files. */
17define('SM_PATH','../');
18
19/* SquirrelMail required files. */
08185f2a 20require_once(SM_PATH . 'include/validate.php');
86725763 21require_once(SM_PATH . 'functions/imap_utf7_decode_local.php');
22require_once(SM_PATH . 'functions/imap.php');
23require_once(SM_PATH . 'functions/array.php');
24require_once(SM_PATH . 'functions/plugin.php');
25require_once(SM_PATH . 'functions/html.php');
d3cdb279 26
e634431a 27displayPageHeader($color, 'None');
aa42fbfb 28
a32985a5 29/* get globals we may need */
30
31$username = $_SESSION['username'];
32$key = $_COOKIE['key'];
33$delimiter = $_SESSION['delimiter'];
34$onetimepad = $_SESSION['onetimepad'];
35if (isset($_GET['success'])) {
36 $success = $_GET['success'];
37}
38
39/* end of get globals */
40
2441907d 41echo '<br>' .
6206f6c4 42 html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) .
2441907d 43 html_tag( 'tr' ) .
44 html_tag( 'td', '', 'center' ) . '<b>' . _("Folders") . '</b>' .
45 html_tag( 'table', '', 'center', '', 'width="100%" cellpadding="5" cellspacing="0" border="0"' ) .
46 html_tag( 'tr' ) .
47 html_tag( 'td', '', 'center', $color[4] );
aa42fbfb 48
1c52ba77 49if ((isset($success) && $success) ||
50 (isset($sent_create) && $sent_create == 'true') ||
51 (isset($trash_create) && $trash_create == 'true')) {
e634431a 52 if ($success == "subscribe") {
50ed645b 53 $td_str = "<b>" . _("Subscribed successfully!") . "</b><br>";
e634431a 54 } else if ($success == "unsubscribe") {
50ed645b 55 $td_str = "<b>" . _("Unsubscribed successfully!") . "</b><br>";
e634431a 56 } else if ($success == "delete") {
50ed645b 57 $td_str = "<b>" . _("Deleted folder successfully!") . "</b><br>";
e634431a 58 } else if ($success == "create") {
50ed645b 59 $td_str = "<b>" . _("Created folder successfully!") . "</b><br>";
e634431a 60 } else if ($success == "rename") {
50ed645b 61 $td_str = "<b>" . _("Renamed successfully!") . "</b><br>";
52ed2f88 62 } else if ($success == "subscribe-doesnotexist") {
63 $td_str = "<b>" .
64 _("Subscription Unsuccessful - Folder does not exist.") .
65 "</b><br>";
e634431a 66 }
67
50ed645b 68 echo html_tag( 'table',
69 html_tag( 'tr',
70 html_tag( 'td', $td_str .
71 "<a href=\"../src/left_main.php\" target=left>" . _("refresh folder list") . "</a>" ,
72 'center' )
73 ) ,
74 'center', '', 'width="100%" cellpadding="4" cellspacing="0" border="0"' ) . "<br>\n";
e634431a 75} else {
76 echo "<br>";
77}
78$imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
79$boxes = sqimap_mailbox_list($imapConnection);
80
81/** CREATING FOLDERS **/
ac50138c 82echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
50ed645b 83 html_tag( 'tr',
84 html_tag( 'td', '<b>' . _("Create Folder") . '</b>', 'center', $color[9] )
85 ) .
86 html_tag( 'tr' ) .
87 html_tag( 'td', '', 'center', $color[0] ) .
88
1c52ba77 89 "<FORM NAME=cf ACTION=\"folders_create.php\" METHOD=\"POST\">\n".
6b4bd11f 90 "<input type=TEXT SIZE=25 NAME=folder_name><BR>\n".
1c52ba77 91 _("as a subfolder of").
92 "<BR>".
93 "<TT><SELECT NAME=subfolder>\n";
e634431a 94if ($default_sub_of_inbox == false) {
95 echo '<OPTION SELECTED VALUE="">[ '._("None")." ]\n";
96} else {
97 echo '<OPTION VALUE="">[ '._("None")." ]\n";
98}
99
336155db 100for ($i = 0, $cnt=count($boxes); $i < $cnt; $i++) {
e634431a 101 if (!in_array('noinferiors', $boxes[$i]['flags'])) {
1c52ba77 102 if ((strtolower($boxes[$i]['unformatted']) == 'inbox') &&
103 $default_sub_of_inbox) {
994163eb 104
1c52ba77 105 $box = $boxes[$i]['unformatted'];
46bc57c1 106 $box2 = str_replace(' ', '&nbsp;',
107 imap_utf7_decode_local($boxes[$i]['unformatted-disp']));
1c52ba77 108 echo "<OPTION SELECTED VALUE=\"$box\">$box2</option>\n";
e634431a 109 } else {
1c52ba77 110 $box = $boxes[$i]['unformatted'];
46bc57c1 111 $box2 = str_replace(' ', '&nbsp;',
112 imap_utf7_decode_local($boxes[$i]['unformatted-disp']));
1c52ba77 113 if (strtolower($imap_server_type) != 'courier' ||
e634431a 114 strtolower($box) != "inbox.trash")
1c52ba77 115 echo "<OPTION VALUE=\"$box\">$box2</option>\n";
e634431a 116 }
117 }
118}
119echo "</SELECT></TT>\n";
120if ($show_contain_subfolders_option) {
6b4bd11f 121 echo "<br><input type=CHECKBOX NAME=\"contain_subs\"> &nbsp;";
e634431a 122 echo _("Let this folder contain subfolders");
123 echo "<BR>";
1c52ba77 124}
6b4bd11f 125echo "<input type=SUBMIT VALUE=\""._("Create")."\">\n";
126echo "</FORM></td></tr>\n";
e634431a 127
50ed645b 128echo html_tag( 'tr',
129 html_tag( 'td', '&nbsp;', 'left', $color[4] )
130 ) ."\n";
0037f048 131
132/** count special folders **/
133$count_special_folders = 0;
134$num_max = 1;
135if (strtolower($imap_server_type) == "courier" || $move_to_trash) {
136 $num_max++;
137}
138if ($move_to_sent) {
139 $num_max++;
140}
141if ($save_as_draft) {
142 $num_max++;
143}
336155db 144for ($p = 0, $cnt = count($boxes); $p < $cnt && $count_special_folders < $num_max; $p++) {
0037f048 145 if (strtolower($boxes[$p]['unformatted']) == 'inbox')
146 $count_special_folders++;
147 else if (strtolower($imap_server_type) == 'courier' &&
148 strtolower($boxes[$p]['unformatted']) == 'inbox.trash')
149 $count_special_folders++;
150 else if ($boxes[$p]['unformatted'] == $trash_folder && $trash_folder)
151 $count_special_folders++;
152 else if ($boxes[$p]['unformatted'] == $sent_folder && $sent_folder)
153 $count_special_folders++;
154 else if ($boxes[$p]['unformatted'] == $draft_folder && $draft_folder)
155 $count_special_folders++;
156}
157
158
e634431a 159/** RENAMING FOLDERS **/
50ed645b 160echo html_tag( 'tr',
161 html_tag( 'td', '<b>' . _("Rename a Folder") . '</b>', 'center', $color[9] )
162 ) .
163 html_tag( 'tr' ) .
164 html_tag( 'td', '', 'center', $color[0] );
165
0037f048 166if ($count_special_folders < count($boxes)) {
167 echo "<FORM ACTION=\"folders_rename_getname.php\" METHOD=\"POST\">\n"
168 . "<TT><SELECT NAME=old>\n"
169 . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
e634431a 170 for ($i = 0; $i < count($boxes); $i++) {
171 $use_folder = true;
172
1c52ba77 173 if ((strtolower($boxes[$i]['unformatted']) != 'inbox') &&
174 ($boxes[$i]['unformatted'] != $trash_folder) &&
175 ($boxes[$i]['unformatted'] != $sent_folder) &&
176 ($boxes[$i]['unformatted'] != $draft_folder)) {
177 $box = $boxes[$i]['unformatted-dm'];
178
46bc57c1 179 $box2 = str_replace(' ', '&nbsp;',
180 imap_utf7_decode_local($boxes[$i]['unformatted-disp']));
1c52ba77 181 if (strtolower($imap_server_type) != 'courier' || strtolower($box) != 'inbox.trash') {
182 echo "<OPTION VALUE=\"$box\">$box2</option>\n";
183 }
e634431a 184 }
185 }
1c52ba77 186 echo "</SELECT></TT>\n".
6b4bd11f 187 "<input type=SUBMIT VALUE=\"".
1c52ba77 188 _("Rename").
189 "\">\n".
50ed645b 190 "</FORM></td></tr>\n";
e634431a 191} else {
192 echo _("No folders found") . "<br><br></td></tr>";
193}
194$boxes_sub = $boxes;
195
50ed645b 196echo html_tag( 'tr',
197 html_tag( 'td', '&nbsp;', 'left', $color[4] )
198 ) ."\n";
e634431a 199
200/** DELETING FOLDERS **/
50ed645b 201echo html_tag( 'tr',
202 html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[9] )
203 ) .
204 html_tag( 'tr' ) .
205 html_tag( 'td', '', 'center', $color[0] );
e634431a 206
e634431a 207if ($count_special_folders < count($boxes)) {
0037f048 208 echo "<FORM ACTION=\"folders_delete.php\" METHOD=\"POST\">\n"
209 . "<TT><SELECT NAME=mailbox>\n"
210 . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
e634431a 211 for ($i = 0; $i < count($boxes); $i++) {
212 $use_folder = true;
1c52ba77 213 if ((strtolower($boxes[$i]['unformatted']) != 'inbox') &&
214 ($boxes[$i]['unformatted'] != $trash_folder) &&
215 ($boxes[$i]['unformatted'] != $sent_folder) &&
216 ($boxes[$i]['unformatted'] != $draft_folder) &&
11f6f685 217 (!in_array('noselect', $boxes[$i]['flags'])) &&
1c52ba77 218 ((strtolower($imap_server_type) != 'courier') ||
219 (strtolower($boxes[$i]['unformatted']) != 'inbox.trash'))) {
220 $box = $boxes[$i]['unformatted-dm'];
46bc57c1 221 $box2 = str_replace(' ', '&nbsp;',
222 imap_utf7_decode_local($boxes[$i]['unformatted-disp']));
1c52ba77 223 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
e634431a 224 }
225 }
226 echo "</SELECT></TT>\n";
6b4bd11f 227 echo "<input type=SUBMIT VALUE=\"";
e634431a 228 echo _("Delete");
229 echo "\">\n";
6b4bd11f 230 echo "</form></td></tr>\n";
e634431a 231} else {
6b4bd11f 232 echo _("No folders found") . "<br><br></td></tr>";
e634431a 233}
50ed645b 234
235echo html_tag( 'tr',
236 html_tag( 'td', '&nbsp;', 'left', $color[4] )
237 ) ."</table>\n";
238
e634431a 239
240/** UNSUBSCRIBE FOLDERS **/
12ff1cab 241echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
50ed645b 242 html_tag( 'tr',
243 html_tag( 'td', '<b>' . _("Unsubscribe") . '/' . _("Subscribe") . '</b>', 'center', $color[9], 'colspan="2"' )
244 ) .
245 html_tag( 'tr' ) .
246 html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
247
e634431a 248if ($count_special_folders < count($boxes)) {
249 echo "<FORM ACTION=\"folders_subscribe.php?method=unsub\" METHOD=\"POST\">\n";
250 echo "<TT><SELECT NAME=\"mailbox[]\" multiple size=8>\n";
251 for ($i = 0; $i < count($boxes); $i++) {
252 $use_folder = true;
253 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
254 ($boxes[$i]["unformatted"] != $trash_folder) &&
255 ($boxes[$i]["unformatted"] != $sent_folder) &&
256 ($boxes[$i]["unformatted"] != $draft_folder)) {
257 $box = $boxes[$i]["unformatted-dm"];
46bc57c1 258 $box2 = str_replace(' ', '&nbsp;',
259 imap_utf7_decode_local($boxes[$i]["unformatted-disp"]));
e634431a 260 echo " <OPTION VALUE=\"$box\">$box2\n";
261 }
262 }
263 echo "</SELECT></TT><br><br>\n";
6b4bd11f 264 echo "<input type=SUBMIT VALUE=\"";
e634431a 265 echo _("Unsubscribe");
266 echo "\">\n";
50ed645b 267 echo "</FORM></td>\n";
e634431a 268} else {
269 echo _("No folders were found to unsubscribe from!") . "</td>";
270}
271$boxes_sub = $boxes;
272
273/** SUBSCRIBE TO FOLDERS **/
50ed645b 274echo html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
52ed2f88 275if(!$no_list_for_subscribe) {
336155db 276 $boxes_all = sqimap_mailbox_list_all ($imapConnection);
52ed2f88 277
278 $box = "";
279 $box2 = "";
280 for ($i = 0, $q = 0; $i < count($boxes_all); $i++) {
e634431a 281 $use_folder = true;
282 for ($p = 0; $p < count ($boxes); $p++) {
283 if ($boxes_all[$i]["unformatted"] == $boxes[$p]["unformatted"]) {
284 $use_folder = false;
285 continue;
286 } else if ($boxes_all[$i]["unformatted-dm"] == $folder_prefix) {
287 $use_folder = false;
288 }
289 }
7e235a1a 290 if ($use_folder == true) {
e634431a 291 $box[$q] = $boxes_all[$i]["unformatted-dm"];
994163eb 292 $box2[$q] = imap_utf7_decode_local($boxes_all[$i]["unformatted-disp"]);
e634431a 293 $q++;
294 }
52ed2f88 295 }
52ed2f88 296 if ($box && $box2) {
e634431a 297 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n";
298 echo "<tt><select name=\"mailbox[]\" multiple size=8>";
299
300 for ($q = 0; $q < count($box); $q++) {
301 echo " <OPTION VALUE=\"$box[$q]\">".$box2[$q]."\n";
302 }
303 echo "</select></tt><br><br>";
6b4bd11f 304 echo "<input type=SUBMIT VALUE=\"". _("Subscribe") . "\">\n";
50ed645b 305 echo "</FORM></td></tr></table><BR>\n";
52ed2f88 306 } else {
e634431a 307 echo _("No folders were found to subscribe to!") . "</td></tr></table>";
52ed2f88 308 }
309} else {
310 /* don't perform the list action -- this is much faster */
311 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n";
312 echo _("Subscribe to:") . "<br>";
313 echo "<tt><input type=\"text\" name=\"mailbox[]\" size=35>";
314 echo "<INPUT TYPE=SUBMIT VALUE=\"". _("Subscribe") . "\">\n";
315 echo "</FORM></TD></TR></TABLE><BR>\n";
e634431a 316}
e7db48af 317
bd9bbfef 318do_hook("folders_bottom");
319?>
e7db48af 320
60573cd9 321
e7db48af 322 </td></tr>
323 </table>
324
325</td></tr>
326</table>
327
328<?php
1195c340 329 sqimap_logout($imapConnection);
aa42fbfb 330?>
e7db48af 331
0037f048 332</body></html>