6 * Copyright (c) 1999-2004 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/plugin.php');
27 require_once(SM_PATH
. 'functions/html.php');
28 require_once(SM_PATH
. 'functions/forms.php');
30 displayPageHeader($color, 'None');
32 /* get globals we may need */
34 sqgetGlobalVar('username', $username, SQ_SESSION
);
35 sqgetGlobalVar('key', $key, SQ_COOKIE
);
36 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
37 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION
);
39 sqgetGlobalVar('success', $success, SQ_GET
);
41 /* end of get globals */
44 html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) .
46 html_tag( 'td', '', 'center' ) . '<b>' . _("Folders") . '</b>' .
47 html_tag( 'table', '', 'center', '', 'width="100%" cellpadding="5" cellspacing="0" border="0"' ) .
49 html_tag( 'td', '', 'center', $color[4] );
51 if ( isset($success) && $success ) {
58 $td_str .= _("Subscribed successfully!");
61 $td_str .= _("Unsubscribed successfully!");
64 $td_str .= _("Deleted folder successfully!");
67 $td_str .= _("Created folder successfully!");
70 $td_str .= _("Renamed successfully!");
72 case 'subscribe-doesnotexist':
73 $td_str .= _("Subscription Unsuccessful - Folder does not exist.");
77 $td_str .= '</b><br>';
80 echo html_tag( 'table',
82 html_tag( 'td', $td_str .
83 '<a href="../src/left_main.php" target=left>' .
84 _("refresh folder list") . '</a>' ,
87 'center', '', 'width="100%" cellpadding="4" cellspacing="0" border="0"' );
92 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
93 $boxes = sqimap_mailbox_list($imapConnection,true);
95 /** CREATING FOLDERS **/
96 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
98 html_tag( 'td', '<b>' . _("Create Folder") . '</b>', 'center', $color[9] )
101 html_tag( 'td', '', 'center', $color[0] ) .
102 addForm('folders_create.php', 'POST', 'cf').
103 addInput('folder_name', '', 25).
104 "<BR>\n". _("as a subfolder of"). '<BR>'.
105 "<TT><SELECT NAME=subfolder>\n";
107 $show_selected = array();
108 $skip_folders = array();
109 $server_type = strtolower($imap_server_type);
110 if ( $server_type == 'courier' ) {
111 array_push($skip_folders, 'inbox.trash');
112 if ( $default_folder_prefix == 'INBOX.' ) {
113 array_push($skip_folders, 'inbox');
117 if ( $default_sub_of_inbox == false ) {
118 echo '<OPTION SELECTED VALUE="">[ '._("None")." ]\n";
120 echo '<OPTION VALUE="">[ '._("None")." ]\n";
121 $show_selected = array('inbox');
124 // Call sqimap_mailbox_option_list, using existing connection to IMAP server,
125 // the arrays of folders to include or skip (assembled above),
126 // use 'noinferiors' as a mailbox filter to leave out folders that can not contain other folders.
127 // use the long format to show subfolders in an intelligible way if parent is missing (special folder)
128 echo sqimap_mailbox_option_list($imapConnection, $show_selected, $skip_folders, $boxes, 'noinferiors', true);
130 echo "</SELECT></TT>\n";
131 if ($show_contain_subfolders_option) {
133 addCheckBox('contain_subs', FALSE, '1') .' '
134 . _("Let this folder contain subfolders")
137 echo "<input type=SUBMIT VALUE=\""._("Create")."\">\n";
138 echo "</FORM></td></tr>\n";
141 html_tag( 'td', ' ', 'left', $color[4] )
144 /** count special folders **/
146 // FIX ME, why not check if the folders are defined IMHO move_to_sent, move_to_trash has nothing todo with it
147 $count_special_folders = 0;
149 if (strtolower($imap_server_type) == "courier" ||
$move_to_trash) {
155 if ($save_as_draft) {
159 // What if move_to_sent = false and $sent_folder is set? Should it still be skipped?
161 for ($p = 0, $cnt = count($boxes); $p < $cnt && $count_special_folders < $num_max; $p++
) {
162 switch ($boxes[$p]['unformatted'])
164 case (strtoupper($boxes[$p]['unformatted']) == 'INBOX'):
165 ++
$count_special_folders;
166 $skip_folders[] = $boxes[$p]['unformatted'];
168 // FIX ME inbox.trash should be set in conf.pl
170 if (strtolower($imap_server_type) == 'courier') {
171 ++
$count_special_folders;
175 ++
$count_special_folders;
176 $skip_folders[] = $trash_folder;
179 ++
$count_special_folders;
180 $skip_folders[] = $sent_folder;
183 ++
$count_special_folders;
184 $skip_folders[] = $draft_folder;
191 /** RENAMING FOLDERS **/
193 html_tag( 'td', '<b>' . _("Rename a Folder") . '</b>', 'center', $color[9] )
196 html_tag( 'td', '', 'center', $color[0] );
198 if ($count_special_folders < count($boxes)) {
199 echo addForm('folders_rename_getname.php')
200 . "<TT><SELECT NAME=old>\n"
201 . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
203 // use existing IMAP connection, we have no special values to show,
204 // but we do include values to skip. Use the pre-created $boxes to save an IMAP query.
205 // send NULL for the flag - ALL folders are eligible for rename!
206 // use long format to make sure folder names make sense when parents may be missing.
207 echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes, NULL, true);
209 echo "</SELECT></TT>\n".
210 "<input type=SUBMIT VALUE=\"".
213 "</FORM></td></tr>\n";
215 echo _("No folders found") . '<br><br></td></tr>';
220 html_tag( 'td', ' ', 'left', $color[4] )
223 /** DELETING FOLDERS **/
225 html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[9] )
228 html_tag( 'td', '', 'center', $color[0] );
230 if ($count_special_folders < count($boxes)) {
231 echo addForm('folders_delete.php')
232 . "<TT><SELECT NAME=mailbox>\n"
233 . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
235 // send NULL for the flag - ALL folders are eligible for delete (except what we've got in skiplist)
236 // use long format to make sure folder names make sense when parents may be missing.
237 echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes, NULL, true);
239 echo "</SELECT></TT>\n"
240 . '<input type=SUBMIT VALUE="'
243 . "</form></td></tr>\n";
245 echo _("No folders found") . "<br><br></td></tr>";
249 html_tag( 'td', ' ', 'left', $color[4] )
253 /** UNSUBSCRIBE FOLDERS **/
254 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
256 html_tag( 'td', '<b>' . _("Unsubscribe") . '/' . _("Subscribe") . '</b>', 'center', $color[9], 'colspan="2"' )
259 html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
261 if ($count_special_folders < count($boxes)) {
262 echo addForm('folders_subscribe.php?method=unsub')
263 . "<TT><SELECT NAME=\"mailbox[]\" multiple size=8>\n";
264 for ($i = 0; $i < count($boxes); $i++
) {
266 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
267 ($boxes[$i]["unformatted"] != $trash_folder) &&
268 ($boxes[$i]["unformatted"] != $sent_folder) &&
269 ($boxes[$i]["unformatted"] != $draft_folder)) {
270 $box = htmlspecialchars($boxes[$i]["unformatted-dm"]);
271 $box2 = str_replace(' ', ' ',
272 htmlspecialchars(imap_utf7_decode_local($boxes[$i]["unformatted-disp"])));
273 echo " <OPTION VALUE=\"$box\">$box2\n";
276 echo "</SELECT></TT><br><br>\n"
277 . '<input type=SUBMIT VALUE="'
282 echo _("No folders were found to unsubscribe from!") . '</td>';
286 /** SUBSCRIBE TO FOLDERS **/
287 echo html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
288 if(!$no_list_for_subscribe) {
289 $boxes_all = sqimap_mailbox_list_all ($imapConnection);
293 for ($i = 0, $q = 0; $i < count($boxes_all); $i++
) {
295 for ($p = 0; $p < count ($boxes); $p++
) {
296 if ($boxes_all[$i]['unformatted'] == $boxes[$p]['unformatted']) {
299 } else if ($boxes_all[$i]['unformatted-dm'] == $folder_prefix) {
303 if ($use_folder == true) {
304 $box[$q] = htmlspecialchars($boxes_all[$i]['unformatted-dm']);
305 $box2[$q] = htmlspecialchars(imap_utf7_decode_local($boxes_all[$i]['unformatted-disp']));
310 echo addForm('folders_subscribe.php?method=sub')
311 . '<tt><select name="mailbox[]" multiple size=8>';
313 for ($q = 0; $q < count($box); $q++
) {
314 echo " <OPTION VALUE=\"$box[$q]\">".$box2[$q]."\n";
316 echo '</select></tt><br><br>'
317 . '<input type=SUBMIT VALUE="'. _("Subscribe") . "\">\n"
318 . "</FORM></td></tr></table><BR>\n";
320 echo _("No folders were found to subscribe to!") . '</td></tr></table>';
323 /* don't perform the list action -- this is much faster */
324 echo addForm('folders_subscribe.php?method=sub')
325 . _("Subscribe to:") . '<br>'
326 . '<tt><input type="text" name="mailbox[]" size=35>'
327 . '<INPUT TYPE=SUBMIT VALUE="'. _("Subscribe") . "\">\n"
328 . "</FORM></TD></TR></TABLE><BR>\n";
331 do_hook('folders_bottom');
341 sqimap_logout($imapConnection);