6 * Copyright (c) 1999-2005 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * Handles all interaction between the user and the other folder
10 * scripts which do most of the work. Also handles the Special
14 * @package squirrelmail
18 * Path for SquirrelMail required files.
21 define('SM_PATH','../');
23 /* SquirrelMail required files. */
24 require_once(SM_PATH
. 'include/validate.php');
25 require_once(SM_PATH
. 'functions/imap.php');
26 require_once(SM_PATH
. 'functions/folder_manip.php');
27 require_once(SM_PATH
. 'functions/plugin.php');
28 require_once(SM_PATH
. 'functions/html.php');
29 require_once(SM_PATH
. 'functions/forms.php');
31 displayPageHeader($color, 'None');
33 /* get globals we may need */
35 sqgetGlobalVar('username', $username, SQ_SESSION
);
36 sqgetGlobalVar('key', $key, SQ_COOKIE
);
37 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
38 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION
);
40 sqgetGlobalVar('smaction', $action, SQ_POST
);
42 /* end of get globals */
45 html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) .
47 html_tag( 'td', '', 'center' ) . '<b>' . _("Folders") . '</b>' .
48 html_tag( 'table', '', 'center', '', 'width="100%" cellpadding="5" cellspacing="0" border="0"' ) .
50 html_tag( 'td', '', 'center', $color[4] );
52 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
54 /* switch to the right function based on what the user selected */
55 if ( sqgetGlobalVar('smaction', $action, SQ_POST
) ) {
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.");
67 if ( sqgetGlobalVar('cancelbutton', $dummy, SQ_POST
) ) {
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);
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.");
81 if ( sqgetGlobalVar('cancelbutton', $dummy, SQ_POST
) ) {
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.");
89 folders_delete_ask($imapConnection, $folder_name);
93 sqgetGlobalVar('folder_names', $folder_names, SQ_POST
);
94 folders_subscribe($imapConnection, $folder_names);
95 $td_str = _("Subscribed successfully.");
98 sqgetGlobalVar('folder_names', $folder_names, SQ_POST
);
99 folders_unsubscribe($imapConnection, $folder_names);
100 $td_str = _("Unsubscribed successfully.");
104 // if there are any messages, output them.
105 if ( !empty($td_str) ) {
106 echo html_tag( 'table',
108 html_tag( 'td', '<b>' . $td_str . "</b><br />\n" .
109 '<a href="../src/left_main.php" target="left">' .
110 _("refresh folder list") . '</a>' ,
113 'center', '', 'width="100%" cellpadding="4" cellspacing="0" border="0"' );
119 $boxes = sqimap_mailbox_list($imapConnection,true);
121 /** CREATING FOLDERS **/
122 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
124 html_tag( 'td', '<b>' . _("Create Folder") . '</b>', 'center', $color[9] )
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";
134 $show_selected = array();
135 $skip_folders = array();
136 $server_type = strtolower($imap_server_type);
137 if ( $server_type == 'courier' ) {
138 array_push($skip_folders, 'inbox.trash');
139 if ( $default_folder_prefix == 'INBOX.' ) {
140 array_push($skip_folders, 'INBOX');
144 if ( $default_sub_of_inbox == false ) {
145 echo '<option selected="selected" value="">[ '._("None")." ]</option>\n";
147 echo '<option value="">[ '._("None")." ]</option>\n";
148 $show_selected = array('inbox');
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)
155 echo sqimap_mailbox_option_list($imapConnection, $show_selected, $skip_folders, $boxes, 'noinferiors', true);
157 echo "</select></tt>\n";
158 if ($show_contain_subfolders_option) {
160 addCheckBox('contain_subs', FALSE, '1') .' '
161 . _("Let this folder contain subfolders")
164 echo "<input type=\"submit\" value=\""._("Create")."\" />\n";
165 echo "</form></td></tr>\n";
168 html_tag( 'td', ' ', 'left', $color[4] )
171 /** count special folders **/
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;
176 if (strtolower($imap_server_type) == "courier" ||
$move_to_trash) {
182 if ($save_as_draft) {
186 // What if move_to_sent = false and $sent_folder is set? Should it still be skipped?
188 for ($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'];
194 // FIX ME inbox.trash should be set in conf.pl
196 if (strtolower($imap_server_type) == 'courier') {
197 ++
$count_special_folders;
201 ++
$count_special_folders;
202 $skip_folders[] = $trash_folder;
205 ++
$count_special_folders;
206 $skip_folders[] = $sent_folder;
209 ++
$count_special_folders;
210 $skip_folders[] = $draft_folder;
217 /** RENAMING FOLDERS **/
219 html_tag( 'td', '<b>' . _("Rename a Folder") . '</b>', 'center', $color[9] )
222 html_tag( 'td', '', 'center', $color[0] );
224 /* show only if we have folders to rename */
225 if ($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";
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);
237 echo "</select></tt>\n".
238 '<input type="submit" value="'.
241 "</form></td></tr>\n";
243 echo _("No folders found") . '<br /><br /></td></tr>';
247 html_tag( 'td', ' ', 'left', $color[4] )
250 /** DELETING FOLDERS **/
252 html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[9] )
255 html_tag( 'td', '', 'center', $color[0] );
257 /* show only if we have folders to delete */
258 if ($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";
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);
268 echo "</select></tt>\n"
269 . '<input type="submit" value="'
272 . "</form></td></tr>\n";
274 echo _("No folders found") . "<br /><br /></td></tr>";
278 html_tag( 'td', ' ', 'left', $color[4] )
282 if ($show_only_subscribed_folders) {
284 /** UNSUBSCRIBE FOLDERS **/
285 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
287 html_tag( 'td', '<b>' . _("Unsubscribe") . '/' . _("Subscribe") . '</b>', 'center', $color[9], 'colspan="2"' )
290 html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
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 ) {
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(' ', ' ',
304 htmlspecialchars(imap_utf7_decode_local($box["unformatted-disp"])));
305 echo " <option value=\"$box_enc\">$box_disp</option>\n";
308 echo "</select></tt><br /><br />\n"
309 . '<input type="submit" value="'
314 echo _("No folders were found to unsubscribe from.") . '</td>';
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);
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) {
328 foreach ( $boxes as $box ) {
329 if ($box_a['unformatted'] == $box['unformatted'] ||
330 $box_a['unformatted-dm'] == $folder_prefix ) {
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;
342 if ( count($subboxes) > 0 ) {
343 echo addForm('folders.php')
344 . addHidden('smaction', 'subscribe')
345 . '<tt><select name="folder_names[]" multiple="multiple" size="8">';
347 foreach($subboxes as $subbox_enc => $subbox_disp) {
348 echo ' <option value="' . $subbox_enc . '">'.$subbox_disp."</option>\n";
351 echo '</select></tt><br /><br />'
352 . '<input type="submit" value="'. _("Subscribe") . "\" />\n"
353 . "</form></td></tr></table><br />\n";
355 echo _("No folders were found to subscribe to.") . '</td></tr></table>';
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";
368 do_hook('folders_bottom');
369 sqimap_logout($imapConnection);