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