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