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.");
103 // TODO: add hook for plugin action processing.
108 // if there are any messages, output them.
109 if ( !empty($td_str) ) {
110 echo html_tag( 'table',
112 html_tag( 'td', '<b>' . $td_str . "</b><br />\n" .
113 '<a href="../src/left_main.php" target="left">' .
114 _("refresh folder list") . '</a>' ,
117 'center', '', 'width="100%" cellpadding="4" cellspacing="0" border="0"' );
123 $boxes = sqimap_mailbox_list($imapConnection,true);
125 /** CREATING FOLDERS **/
126 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
128 html_tag( 'td', '<b>' . _("Create Folder") . '</b>', 'center', $color[9] )
131 html_tag( 'td', '', 'center', $color[0] ) .
132 addForm('folders.php', 'post', 'cf').
133 addHidden('smaction','create').
134 addInput('folder_name', '', 25).
135 "<br />\n". _("as a subfolder of"). '<br />'.
136 "<tt><select name=\"subfolder\">\n";
138 $show_selected = array();
139 $skip_folders = array();
140 $server_type = strtolower($imap_server_type);
142 // Special handling for courier
143 if ( $server_type == 'courier' ) {
145 * If we use courier, we should hide system trash folder
146 * FIXME: (tokul) Who says that courier does not allow storing folders in
147 * INBOX.Trash or inbox.trash? Can't reproduce it 3.0.8. This entry is
148 * useless, because in_array() check is case sensitive and INBOX is in
151 array_push($skip_folders, 'inbox.trash');
153 if ( $default_folder_prefix == 'INBOX.' ) {
154 // We don't need INBOX, since it is top folder
155 array_push($skip_folders, 'INBOX');
159 if ( $default_sub_of_inbox == false ) {
160 echo '<option selected="selected" value="">[ '._("None")." ]</option>\n";
162 echo '<option value="">[ '._("None")." ]</option>\n";
163 $show_selected = array('inbox');
166 // Call sqimap_mailbox_option_list, using existing connection to IMAP server,
167 // the arrays of folders to include or skip (assembled above),
168 // use 'noinferiors' as a mailbox filter to leave out folders that can not contain other folders.
169 // use the long format to show subfolders in an intelligible way if parent is missing (special folder)
170 echo sqimap_mailbox_option_list($imapConnection, $show_selected, $skip_folders, $boxes, 'noinferiors', true);
172 echo "</select></tt>\n";
173 if ($show_contain_subfolders_option) {
175 addCheckBox('contain_subs', FALSE, '1') .' '
176 . _("Let this folder contain subfolders")
179 echo "<input type=\"submit\" value=\""._("Create")."\" />\n";
180 echo "</form></td></tr>\n";
183 html_tag( 'td', ' ', 'left', $color[4] )
186 /** count special folders **/
187 foreach ($boxes as $index => $aBoxData) {
188 if (isSpecialMailbox($aBoxData['unformatted']) &&
189 ! in_array($aBoxData['unformatted'],$skip_folders)) {
190 $skip_folders[] = $aBoxData['unformatted'];
195 * Retrieve list of folders when special folders are excluded. Special folders
196 * should be unavailable in rename/delete/unsubscribe. Theoretically user can
197 * modify form and perform these operations with special folders, but if user
198 * manages to delete/rename/unsubscribe special folder by hacking form...
200 * If script or program depends on special folder, they should not assume that
201 * folder is available.
203 * $filtered_folders contains empty string or html formated option list.
205 $filtered_folders = sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes, NULL, true);
207 /** RENAMING FOLDERS **/
209 html_tag( 'td', '<b>' . _("Rename a Folder") . '</b>', 'center', $color[9] )
212 html_tag( 'td', '', 'center', $color[0] );
214 /* show only if we have folders to rename */
215 if (! empty($filtered_folders)) {
216 echo addForm('folders.php')
217 . addHidden('smaction', 'rename')
218 . "<tt><select name=\"old_name\">\n"
219 . ' <option value="">[ ' . _("Select a folder") . " ]</option>\n";
221 // use existing IMAP connection, we have no special values to show,
222 // but we do include values to skip. Use the pre-created $boxes to save an IMAP query.
223 // send NULL for the flag - ALL folders are eligible for rename!
224 // use long format to make sure folder names make sense when parents may be missing.
225 echo $filtered_folders;
227 echo "</select></tt>\n".
228 '<input type="submit" value="'.
231 "</form></td></tr>\n";
233 echo _("No folders found") . '<br /><br /></td></tr>';
237 html_tag( 'td', ' ', 'left', $color[4] )
240 /** DELETING FOLDERS **/
242 html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[9] )
245 html_tag( 'td', '', 'center', $color[0] );
247 /* show only if we have folders to delete */
248 if (!empty($filtered_folders)) {
249 echo addForm('folders.php')
250 . addHidden('smaction', 'delete')
251 . "<tt><select name=\"folder_name\">\n"
252 . ' <option value="">[ ' . _("Select a folder") . " ]</option>\n";
254 // send NULL for the flag - ALL folders are eligible for delete (except what we've got in skiplist)
255 // use long format to make sure folder names make sense when parents may be missing.
256 echo $filtered_folders;
258 echo "</select></tt>\n"
259 . '<input type="submit" value="'
262 . "</form></td></tr>\n";
264 echo _("No folders found") . "<br /><br /></td></tr>";
268 html_tag( 'td', ' ', 'left', $color[4] )
272 if ($show_only_subscribed_folders) {
273 // FIXME: fix subscription options when top folder is not subscribed and sub folder is subscribed
274 // TODO: use checkboxes instead of select options.
276 /** UNSUBSCRIBE FOLDERS **/
277 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
279 html_tag( 'td', '<b>' . _("Unsubscribe") . '/' . _("Subscribe") . '</b>', 'center', $color[9], 'colspan="2"' )
282 html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
284 if (!empty($filtered_folders)) {
285 echo addForm('folders.php')
286 . addHidden('smaction', 'unsubscribe')
287 . "<tt><select name=\"folder_names[]\" multiple=\"multiple\" size=\"8\">\n"
289 . "</select></tt><br /><br />\n"
290 . '<input type="submit" value="'
295 echo _("No folders were found to unsubscribe from.") . '</td>';
298 /** SUBSCRIBE TO FOLDERS **/
299 echo html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
300 if(!$no_list_for_subscribe) {
301 $boxes_all = sqimap_mailbox_list_all ($imapConnection);
304 // here we filter out all boxes we're already subscribed to,
305 // so we keep only the unsubscribed ones.
306 foreach ($boxes_all as $box_a) {
309 foreach ( $boxes as $box ) {
310 if ($box_a['unformatted'] == $box['unformatted'] ||
311 $box_a['unformatted-dm'] == $folder_prefix ) {
316 if ($use_folder == true) {
317 $box_enc = htmlspecialchars($box_a['unformatted-dm']);
318 $box_disp = htmlspecialchars(imap_utf7_decode_local($box_a['unformatted-disp']));
319 $subboxes[$box_enc] = $box_disp;
323 if ( count($subboxes) > 0 ) {
324 echo addForm('folders.php')
325 . addHidden('smaction', 'subscribe')
326 . '<tt><select name="folder_names[]" multiple="multiple" size="8">';
328 foreach($subboxes as $subbox_enc => $subbox_disp) {
329 echo ' <option value="' . $subbox_enc . '">'.$subbox_disp."</option>\n";
332 echo '</select></tt><br /><br />'
333 . '<input type="submit" value="'. _("Subscribe") . "\" />\n"
334 . "</form></td></tr></table><br />\n";
336 echo _("No folders were found to subscribe to.") . '</td></tr></table>';
339 /* don't perform the list action -- this is much faster */
340 echo addForm('folders.php')
341 . addHidden('smaction', 'subscribe')
342 . _("Subscribe to:") . '<br />'
343 . '<tt><input type="text" name="folder_names[]" size="35" />'
344 . '<input type="submit" value="'. _("Subscribe") . "\" />\n"
345 . "</form></td></tr></table><br />\n";
349 do_hook('folders_bottom');
350 sqimap_logout($imapConnection);