fix mbstring overloading issue with passwords (#929644).
[squirrelmail.git] / src / folders.php
CommitLineData
59177427 1<?php
895905c0 2
35586184 3/**
4 * folders.php
5 *
6c84ba1e 6 * Copyright (c) 1999-2005 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 *
30967a1e 13 * @version $Id$
8f6f9ba5 14 * @package squirrelmail
35586184 15 */
16
30967a1e 17/**
18 * Path for SquirrelMail required files.
19 * @ignore
20 */
86725763 21define('SM_PATH','../');
22
23/* SquirrelMail required files. */
08185f2a 24require_once(SM_PATH . 'include/validate.php');
86725763 25require_once(SM_PATH . 'functions/imap.php');
32aa0074 26require_once(SM_PATH . 'functions/folder_manip.php');
86725763 27require_once(SM_PATH . 'functions/plugin.php');
28require_once(SM_PATH . 'functions/html.php');
62366261 29require_once(SM_PATH . 'functions/forms.php');
d3cdb279 30
e634431a 31displayPageHeader($color, 'None');
aa42fbfb 32
a32985a5 33/* get globals we may need */
34
f38b7cf0 35sqgetGlobalVar('username', $username, SQ_SESSION);
36sqgetGlobalVar('key', $key, SQ_COOKIE);
37sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
38sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
39
32aa0074 40sqgetGlobalVar('smaction', $action, SQ_POST);
a32985a5 41
42/* end of get globals */
43
ff0969a0 44echo '<br />' .
6206f6c4 45 html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) .
2441907d 46 html_tag( 'tr' ) .
47 html_tag( 'td', '', 'center' ) . '<b>' . _("Folders") . '</b>' .
48 html_tag( 'table', '', 'center', '', 'width="100%" cellpadding="5" cellspacing="0" border="0"' ) .
49 html_tag( 'tr' ) .
50 html_tag( 'td', '', 'center', $color[4] );
aa42fbfb 51
32aa0074 52$imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
b7f83b61 53
32aa0074 54/* switch to the right function based on what the user selected */
55if ( sqgetGlobalVar('smaction', $action, SQ_POST) ) {
b7f83b61 56
32aa0074 57 switch ($action)
b7f83b61 58 {
32aa0074 59 case 'create':
60 sqgetGlobalVar('folder_name', $folder_name, SQ_POST);
61 sqgetGlobalVar('subfolder', $subfolder, SQ_POST);
62 sqgetGlobalVar('contain_subs', $contain_subs, SQ_POST);
63 folders_create($imapConnection, $delimiter, $folder_name, $subfolder, $contain_subs);
64 $td_str = _("Created folder successfully.");
b7f83b61 65 break;
32aa0074 66 case 'rename':
67 if ( sqgetGlobalVar('cancelbutton', $dummy, SQ_POST) ) {
68 break;
69 }
70 if ( ! sqgetGlobalVar('new_name', $new_name, SQ_POST) ) {
71 sqgetGlobalVar('old_name', $old_name, SQ_POST);
72 folders_rename_getname($imapConnection, $delimiter, $old_name);
73 } else {
74 sqgetGlobalVar('orig', $orig, SQ_POST);
75 sqgetGlobalVar('old_name', $old_name, SQ_POST);
76 folders_rename_do($imapConnection, $delimiter, $orig, $old_name, $new_name);
77 $td_str = _("Renamed successfully!");
78 }
b7f83b61 79 break;
80 case 'delete':
32aa0074 81 if ( sqgetGlobalVar('cancelbutton', $dummy, SQ_POST) ) {
82 break;
83 }
84 sqgetGlobalVar('folder_name', $folder_name, SQ_POST);
85 if ( sqgetGlobalVar('confirmed', $dummy, SQ_POST) ) {
86 folders_delete_do($imapConnection, $delimiter, $folder_name);
87 $td_str = _("Deleted folder successfully.");
88 } else {
89 folders_delete_ask($imapConnection, $folder_name);
90 }
b7f83b61 91 break;
32aa0074 92 case 'subscribe':
93 sqgetGlobalVar('folder_names', $folder_names, SQ_POST);
94 folders_subscribe($imapConnection, $folder_names);
95 $td_str = _("Subscribed successfully.");
b7f83b61 96 break;
32aa0074 97 case 'unsubscribe':
98 sqgetGlobalVar('folder_names', $folder_names, SQ_POST);
99 folders_unsubscribe($imapConnection, $folder_names);
100 $td_str = _("Unsubscribed successfully.");
b7f83b61 101 break;
32aa0074 102 }
dcc1cc82 103
104 echo html_tag( 'table',
105 html_tag( 'tr',
32aa0074 106 html_tag( 'td', '<b>' . $td_str . "</b><br />\n" .
39bfea8f 107 '<a href="../src/left_main.php" target="left">' .
dcc1cc82 108 _("refresh folder list") . '</a>' ,
109 'center' )
110 ) ,
111 'center', '', 'width="100%" cellpadding="4" cellspacing="0" border="0"' );
e634431a 112}
b7f83b61 113
ff0969a0 114echo "\n<br />";
b7f83b61 115
cedd503c 116$boxes = sqimap_mailbox_list($imapConnection,true);
e634431a 117
118/** CREATING FOLDERS **/
ac50138c 119echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
50ed645b 120 html_tag( 'tr',
121 html_tag( 'td', '<b>' . _("Create Folder") . '</b>', 'center', $color[9] )
122 ) .
123 html_tag( 'tr' ) .
124 html_tag( 'td', '', 'center', $color[0] ) .
32aa0074 125 addForm('folders.php', 'post', 'cf').
126 addHidden('smaction','create').
62366261 127 addInput('folder_name', '', 25).
ff0969a0 128 "<br />\n". _("as a subfolder of"). '<br />'.
129 "<tt><select name=\"subfolder\">\n";
7f0a2c23 130
45f836eb 131$show_selected = array();
132$skip_folders = array();
7f0a2c23 133$server_type = strtolower($imap_server_type);
134if ( $server_type == 'courier' ) {
45f836eb 135 array_push($skip_folders, 'inbox.trash');
7c8b7b4f 136 if ( $default_folder_prefix == 'INBOX.' ) {
99e400a4 137 array_push($skip_folders, 'INBOX');
7c8b7b4f 138 }
7f0a2c23 139}
140
141if ( $default_sub_of_inbox == false ) {
ff0969a0 142 echo '<option selected="selected" value="">[ '._("None")." ]</option>\n";
e634431a 143} else {
ff0969a0 144 echo '<option value="">[ '._("None")." ]</option>\n";
be2d5495 145 $show_selected = array('inbox');
146}
be2d5495 147
6e2ae264 148// Call sqimap_mailbox_option_list, using existing connection to IMAP server,
91e0dccc 149// the arrays of folders to include or skip (assembled above),
59a8e3e8 150// use 'noinferiors' as a mailbox filter to leave out folders that can not contain other folders.
151// use the long format to show subfolders in an intelligible way if parent is missing (special folder)
152echo sqimap_mailbox_option_list($imapConnection, $show_selected, $skip_folders, $boxes, 'noinferiors', true);
be2d5495 153
ff0969a0 154echo "</select></tt>\n";
e634431a 155if ($show_contain_subfolders_option) {
ff0969a0 156 echo '<br />'.
62366261 157 addCheckBox('contain_subs', FALSE, '1') .' &nbsp;'
b7f83b61 158 . _("Let this folder contain subfolders")
ff0969a0 159 . '<br />';
1c52ba77 160}
ff0969a0 161echo "<input type=\"submit\" value=\""._("Create")."\" />\n";
162echo "</form></td></tr>\n";
e634431a 163
50ed645b 164echo html_tag( 'tr',
165 html_tag( 'td', '&nbsp;', 'left', $color[4] )
166 ) ."\n";
0037f048 167
168/** count special folders **/
74fff934 169
170// FIX ME, why not check if the folders are defined IMHO move_to_sent, move_to_trash has nothing todo with it
0037f048 171$count_special_folders = 0;
172$num_max = 1;
173if (strtolower($imap_server_type) == "courier" || $move_to_trash) {
45f836eb 174 $num_max++;
0037f048 175}
176if ($move_to_sent) {
45f836eb 177 $num_max++;
0037f048 178}
179if ($save_as_draft) {
45f836eb 180 $num_max++;
0037f048 181}
74fff934 182
183// What if move_to_sent = false and $sent_folder is set? Should it still be skipped?
184
336155db 185for ($p = 0, $cnt = count($boxes); $p < $cnt && $count_special_folders < $num_max; $p++) {
134e4174 186 switch ($boxes[$p]['unformatted']) {
187 case (strtoupper($boxes[$p]['unformatted']) == 'INBOX'):
188 ++$count_special_folders;
189 $skip_folders[] = $boxes[$p]['unformatted'];
190 break;
191 // FIX ME inbox.trash should be set in conf.pl
192 case 'inbox.trash':
193 if (strtolower($imap_server_type) == 'courier') {
194 ++$count_special_folders;
195 }
196 break;
197 case $trash_folder:
198 ++$count_special_folders;
199 $skip_folders[] = $trash_folder;
200 break;
201 case $sent_folder:
202 ++$count_special_folders;
203 $skip_folders[] = $sent_folder;
204 break;
205 case $draft_folder:
206 ++$count_special_folders;
207 $skip_folders[] = $draft_folder;
208 break;
209 default: break;
210 }
0037f048 211}
212
213
e634431a 214/** RENAMING FOLDERS **/
50ed645b 215echo html_tag( 'tr',
216 html_tag( 'td', '<b>' . _("Rename a Folder") . '</b>', 'center', $color[9] )
217 ) .
218 html_tag( 'tr' ) .
219 html_tag( 'td', '', 'center', $color[0] );
220
32aa0074 221/* show only if we have folders to rename */
0037f048 222if ($count_special_folders < count($boxes)) {
32aa0074 223 echo addForm('folders.php')
224 . addHidden('smaction', 'rename')
225 . "<tt><select name=\"old_name\">\n"
ff0969a0 226 . ' <option value="">[ ' . _("Select a folder") . " ]</option>\n";
be2d5495 227
91e0dccc 228 // use existing IMAP connection, we have no special values to show,
59a8e3e8 229 // but we do include values to skip. Use the pre-created $boxes to save an IMAP query.
230 // send NULL for the flag - ALL folders are eligible for rename!
231 // use long format to make sure folder names make sense when parents may be missing.
232 echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes, NULL, true);
be2d5495 233
ff0969a0 234 echo "</select></tt>\n".
235 '<input type="submit" value="'.
1c52ba77 236 _("Rename").
ff0969a0 237 "\" />\n".
238 "</form></td></tr>\n";
e634431a 239} else {
ff0969a0 240 echo _("No folders found") . '<br /><br /></td></tr>';
e634431a 241}
e634431a 242
50ed645b 243echo html_tag( 'tr',
244 html_tag( 'td', '&nbsp;', 'left', $color[4] )
245 ) ."\n";
e634431a 246
247/** DELETING FOLDERS **/
50ed645b 248echo html_tag( 'tr',
249 html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[9] )
250 ) .
251 html_tag( 'tr' ) .
252 html_tag( 'td', '', 'center', $color[0] );
e634431a 253
32aa0074 254/* show only if we have folders to delete */
e634431a 255if ($count_special_folders < count($boxes)) {
32aa0074 256 echo addForm('folders.php')
257 . addHidden('smaction', 'delete')
258 . "<tt><select name=\"folder_name\">\n"
ff0969a0 259 . ' <option value="">[ ' . _("Select a folder") . " ]</option>\n";
be2d5495 260
59a8e3e8 261 // send NULL for the flag - ALL folders are eligible for delete (except what we've got in skiplist)
262 // use long format to make sure folder names make sense when parents may be missing.
263 echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes, NULL, true);
be2d5495 264
ff0969a0 265 echo "</select></tt>\n"
266 . '<input type="submit" value="'
b7f83b61 267 . _("Delete")
ff0969a0 268 . "\" />\n"
b7f83b61 269 . "</form></td></tr>\n";
e634431a 270} else {
ff0969a0 271 echo _("No folders found") . "<br /><br /></td></tr>";
e634431a 272}
50ed645b 273
274echo html_tag( 'tr',
275 html_tag( 'td', '&nbsp;', 'left', $color[4] )
276 ) ."</table>\n";
277
e634431a 278
4d5f2b31 279if ($show_only_subscribed_folders) {
50ed645b 280
4d5f2b31 281 /** UNSUBSCRIBE FOLDERS **/
282 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
283 html_tag( 'tr',
284 html_tag( 'td', '<b>' . _("Unsubscribe") . '/' . _("Subscribe") . '</b>', 'center', $color[9], 'colspan="2"' )
285 ) .
286 html_tag( 'tr' ) .
287 html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
288
289 if ($count_special_folders < count($boxes)) {
32aa0074 290 echo addForm('folders.php')
291 . addHidden('smaction', 'unsubscribe')
292 . "<tt><select name=\"folder_names[]\" multiple=\"multiple\" size=\"8\">\n";
293 foreach ( $boxes as $box ) {
4d5f2b31 294 $use_folder = true;
32aa0074 295 if ((strtolower($box["unformatted"]) != "inbox") &&
296 ($box['unformatted'] != $trash_folder) &&
297 ($box['unformatted'] != $sent_folder) &&
298 ($box['unformatted'] != $draft_folder)) {
299 $box_enc = htmlspecialchars($box['unformatted-dm']);
300 $box_disp = str_replace(' ', '&nbsp;',
301 htmlspecialchars(imap_utf7_decode_local($box["unformatted-disp"])));
302 echo " <option value=\"$box_enc\">$box_disp</option>\n";
4d5f2b31 303 }
304 }
305 echo "</select></tt><br /><br />\n"
306 . '<input type="submit" value="'
307 . _("Unsubscribe")
308 . "\" />\n"
309 . "</form></td>\n";
310 } else {
311 echo _("No folders were found to unsubscribe from!") . '</td>';
e634431a 312 }
4d5f2b31 313
314 /** SUBSCRIBE TO FOLDERS **/
315 echo html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
316 if(!$no_list_for_subscribe) {
32aa0074 317 $boxes_all = sqimap_mailbox_list_all ($imapConnection);
318
319 $subboxes = array();
320 // here we filter out all boxes we're already subscribed to,
321 // so we keep only the unsubscribed ones.
322 foreach ($boxes_all as $box_a) {
323
324 $use_folder = true;
325 foreach ( $boxes as $box ) {
326 if ($box_a['unformatted'] == $box['unformatted'] ||
327 $box_a['unformatted-dm'] == $folder_prefix ) {
328 $use_folder = false;
329 }
330 }
331
332 if ($use_folder == true) {
333 $box_enc = htmlspecialchars($box_a['unformatted-dm']);
334 $box_disp = htmlspecialchars(imap_utf7_decode_local($box_a['unformatted-disp']));
335 $subboxes[$box_enc] = $box_disp;
4d5f2b31 336 }
337 }
32aa0074 338
339 if ( count($subboxes) > 0 ) {
340 echo addForm('folders.php')
341 . addHidden('smaction', 'subscribe')
342 . '<tt><select name="folder_names[]" multiple="multiple" size="8">';
343
344 foreach($subboxes as $subbox_enc => $subbox_disp) {
345 echo ' <option value="' . $subbox_enc . '">'.$subbox_disp."</option>\n";
346 }
e634431a 347
32aa0074 348 echo '</select></tt><br /><br />'
349 . '<input type="submit" value="'. _("Subscribe") . "\" />\n"
350 . "</form></td></tr></table><br />\n";
351 } else {
352 echo _("No folders were found to subscribe to.") . '</td></tr></table>';
4d5f2b31 353 }
4d5f2b31 354 } else {
32aa0074 355 /* don't perform the list action -- this is much faster */
356 echo addForm('folders.php')
357 . addHidden('smaction', 'subscribe')
4d5f2b31 358 . _("Subscribe to:") . '<br />'
32aa0074 359 . '<tt><input type="text" name="folder_names[]" size="35" />'
4d5f2b31 360 . '<input type="submit" value="'. _("Subscribe") . "\" />\n"
361 . "</form></td></tr></table><br />\n";
e634431a 362 }
e634431a 363}
e7db48af 364
b7f83b61 365do_hook('folders_bottom');
32aa0074 366sqimap_logout($imapConnection);
bd9bbfef 367?>
e7db48af 368 </td></tr>
369 </table>
e7db48af 370</td></tr>
371</table>
4d5f2b31 372</body></html>