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 echo html_tag( 'table',
106 html_tag( 'td', '<b>' . $td_str . "</b><br />\n" .
107 '<a href="../src/left_main.php" target="left">' .
108 _("refresh folder list") . '</a>' ,
111 'center', '', 'width="100%" cellpadding="4" cellspacing="0" border="0"' );
116 $boxes = sqimap_mailbox_list($imapConnection,true);
118 /** CREATING FOLDERS **/
119 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
121 html_tag( 'td', '<b>' . _("Create Folder") . '</b>', 'center', $color[9] )
124 html_tag( 'td', '', 'center', $color[0] ) .
125 addForm('folders.php', 'post', 'cf').
126 addHidden('smaction','create').
127 addInput('folder_name', '', 25).
128 "<br />\n". _("as a subfolder of"). '<br />'.
129 "<tt><select name=\"subfolder\">\n";
131 $show_selected = array();
132 $skip_folders = array();
133 $server_type = strtolower($imap_server_type);
134 if ( $server_type == 'courier' ) {
135 array_push($skip_folders, 'inbox.trash');
136 if ( $default_folder_prefix == 'INBOX.' ) {
137 array_push($skip_folders, 'INBOX');
141 if ( $default_sub_of_inbox == false ) {
142 echo '<option selected="selected" value="">[ '._("None")." ]</option>\n";
144 echo '<option value="">[ '._("None")." ]</option>\n";
145 $show_selected = array('inbox');
148 // Call sqimap_mailbox_option_list, using existing connection to IMAP server,
149 // the arrays of folders to include or skip (assembled above),
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)
152 echo sqimap_mailbox_option_list($imapConnection, $show_selected, $skip_folders, $boxes, 'noinferiors', true);
154 echo "</select></tt>\n";
155 if ($show_contain_subfolders_option) {
157 addCheckBox('contain_subs', FALSE, '1') .' '
158 . _("Let this folder contain subfolders")
161 echo "<input type=\"submit\" value=\""._("Create")."\" />\n";
162 echo "</form></td></tr>\n";
165 html_tag( 'td', ' ', 'left', $color[4] )
168 /** count special folders **/
170 // FIX ME, why not check if the folders are defined IMHO move_to_sent, move_to_trash has nothing todo with it
171 $count_special_folders = 0;
173 if (strtolower($imap_server_type) == "courier" ||
$move_to_trash) {
179 if ($save_as_draft) {
183 // What if move_to_sent = false and $sent_folder is set? Should it still be skipped?
185 for ($p = 0, $cnt = count($boxes); $p < $cnt && $count_special_folders < $num_max; $p++
) {
186 switch ($boxes[$p]['unformatted']) {
187 case (strtoupper($boxes[$p]['unformatted']) == 'INBOX'):
188 ++
$count_special_folders;
189 $skip_folders[] = $boxes[$p]['unformatted'];
191 // FIX ME inbox.trash should be set in conf.pl
193 if (strtolower($imap_server_type) == 'courier') {
194 ++
$count_special_folders;
198 ++
$count_special_folders;
199 $skip_folders[] = $trash_folder;
202 ++
$count_special_folders;
203 $skip_folders[] = $sent_folder;
206 ++
$count_special_folders;
207 $skip_folders[] = $draft_folder;
214 /** RENAMING FOLDERS **/
216 html_tag( 'td', '<b>' . _("Rename a Folder") . '</b>', 'center', $color[9] )
219 html_tag( 'td', '', 'center', $color[0] );
221 /* show only if we have folders to rename */
222 if ($count_special_folders < count($boxes)) {
223 echo addForm('folders.php')
224 . addHidden('smaction', 'rename')
225 . "<tt><select name=\"old_name\">\n"
226 . ' <option value="">[ ' . _("Select a folder") . " ]</option>\n";
228 // use existing IMAP connection, we have no special values to show,
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);
234 echo "</select></tt>\n".
235 '<input type="submit" value="'.
238 "</form></td></tr>\n";
240 echo _("No folders found") . '<br /><br /></td></tr>';
244 html_tag( 'td', ' ', 'left', $color[4] )
247 /** DELETING FOLDERS **/
249 html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[9] )
252 html_tag( 'td', '', 'center', $color[0] );
254 /* show only if we have folders to delete */
255 if ($count_special_folders < count($boxes)) {
256 echo addForm('folders.php')
257 . addHidden('smaction', 'delete')
258 . "<tt><select name=\"folder_name\">\n"
259 . ' <option value="">[ ' . _("Select a folder") . " ]</option>\n";
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);
265 echo "</select></tt>\n"
266 . '<input type="submit" value="'
269 . "</form></td></tr>\n";
271 echo _("No folders found") . "<br /><br /></td></tr>";
275 html_tag( 'td', ' ', 'left', $color[4] )
279 if ($show_only_subscribed_folders) {
281 /** UNSUBSCRIBE FOLDERS **/
282 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
284 html_tag( 'td', '<b>' . _("Unsubscribe") . '/' . _("Subscribe") . '</b>', 'center', $color[9], 'colspan="2"' )
287 html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
289 if ($count_special_folders < count($boxes)) {
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 ) {
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(' ', ' ',
301 htmlspecialchars(imap_utf7_decode_local($box["unformatted-disp"])));
302 echo " <option value=\"$box_enc\">$box_disp</option>\n";
305 echo "</select></tt><br /><br />\n"
306 . '<input type="submit" value="'
311 echo _("No folders were found to unsubscribe from!") . '</td>';
314 /** SUBSCRIBE TO FOLDERS **/
315 echo html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
316 if(!$no_list_for_subscribe) {
317 $boxes_all = sqimap_mailbox_list_all ($imapConnection);
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) {
325 foreach ( $boxes as $box ) {
326 if ($box_a['unformatted'] == $box['unformatted'] ||
327 $box_a['unformatted-dm'] == $folder_prefix ) {
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;
339 if ( count($subboxes) > 0 ) {
340 echo addForm('folders.php')
341 . addHidden('smaction', 'subscribe')
342 . '<tt><select name="folder_names[]" multiple="multiple" size="8">';
344 foreach($subboxes as $subbox_enc => $subbox_disp) {
345 echo ' <option value="' . $subbox_enc . '">'.$subbox_disp."</option>\n";
348 echo '</select></tt><br /><br />'
349 . '<input type="submit" value="'. _("Subscribe") . "\" />\n"
350 . "</form></td></tr></table><br />\n";
352 echo _("No folders were found to subscribe to.") . '</td></tr></table>';
355 /* don't perform the list action -- this is much faster */
356 echo addForm('folders.php')
357 . addHidden('smaction', 'subscribe')
358 . _("Subscribe to:") . '<br />'
359 . '<tt><input type="text" name="folder_names[]" size="35" />'
360 . '<input type="submit" value="'. _("Subscribe") . "\" />\n"
361 . "</form></td></tr></table><br />\n";
365 do_hook('folders_bottom');
366 sqimap_logout($imapConnection);