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
17 /** Path for SquirrelMail required files. */
18 define('SM_PATH','../');
20 /* SquirrelMail required files. */
21 require_once(SM_PATH
. 'include/validate.php');
22 require_once(SM_PATH
. 'functions/imap.php');
23 require_once(SM_PATH
. 'functions/plugin.php');
24 require_once(SM_PATH
. 'functions/html.php');
26 displayPageHeader($color, 'None');
28 /* get globals we may need */
30 sqgetGlobalVar('username', $username, SQ_SESSION
);
31 sqgetGlobalVar('key', $key, SQ_COOKIE
);
32 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
33 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION
);
35 sqgetGlobalVar('success', $success, SQ_GET
);
37 /* end of get globals */
40 html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) .
42 html_tag( 'td', '', 'center' ) . '<b>' . _("Folders") . '</b>' .
43 html_tag( 'table', '', 'center', '', 'width="100%" cellpadding="5" cellspacing="0" border="0"' ) .
45 html_tag( 'td', '', 'center', $color[4] );
47 if ( isset($success) && $success ) {
54 $td_str .= _("Subscribed successfully!");
57 $td_str .= _("Unsubscribed successfully!");
60 $td_str .= _("Deleted folder successfully!");
63 $td_str .= _("Created folder successfully!");
66 $td_str .= _("Renamed successfully!");
68 case 'subscribe-doesnotexist':
69 $td_str .= _("Subscription Unsuccessful - Folder does not exist.");
73 $td_str .= '</b><br>';
76 echo html_tag( 'table',
78 html_tag( 'td', $td_str .
79 '<a href="../src/left_main.php" target=left>' .
80 _("refresh folder list") . '</a>' ,
83 'center', '', 'width="100%" cellpadding="4" cellspacing="0" border="0"' );
88 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
89 $boxes = sqimap_mailbox_list($imapConnection);
91 /** CREATING FOLDERS **/
92 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
94 html_tag( 'td', '<b>' . _("Create Folder") . '</b>', 'center', $color[9] )
97 html_tag( 'td', '', 'center', $color[0] ) .
99 "<FORM NAME=cf ACTION=\"folders_create.php\" METHOD=\"POST\">\n".
100 "<input type=TEXT SIZE=25 NAME=folder_name><BR>\n".
101 _("as a subfolder of").
103 "<TT><SELECT NAME=subfolder>\n";
105 $show_selected = array();
106 $skip_folders = array();
107 $server_type = strtolower($imap_server_type);
108 if ( $server_type == 'courier' ) {
109 array_push($skip_folders, 'inbox.trash');
110 if ( $default_folder_prefix == 'INBOX.' ) {
111 array_push($skip_folders, 'inbox');
115 if ( $default_sub_of_inbox == false ) {
116 echo '<OPTION SELECTED VALUE="">[ '._("None")." ]\n";
118 echo '<OPTION VALUE="">[ '._("None")." ]\n";
119 $show_selected = array('inbox');
122 // Call sqimap_mailbox_option_list, using existing connection to IMAP server,
123 // the arrays of folders to include or skip (assembled above),
124 // use 'noinferiors' as a mailbox filter to leave out folders that can not contain other folders.
125 // use the long format to show subfolders in an intelligible way if parent is missing (special folder)
126 echo sqimap_mailbox_option_list($imapConnection, $show_selected, $skip_folders, $boxes, 'noinferiors', true);
128 echo "</SELECT></TT>\n";
129 if ($show_contain_subfolders_option) {
130 echo '<br><input type=CHECKBOX NAME="contain_subs"> '
131 . _("Let this folder contain subfolders")
134 echo "<input type=SUBMIT VALUE=\""._("Create")."\">\n";
135 echo "</FORM></td></tr>\n";
138 html_tag( 'td', ' ', 'left', $color[4] )
141 /** count special folders **/
143 // FIX ME, why not check if the folders are defined IMHO move_to_sent, move_to_trash has nothing todo with it
144 $count_special_folders = 0;
146 if (strtolower($imap_server_type) == "courier" ||
$move_to_trash) {
152 if ($save_as_draft) {
156 // What if move_to_sent = false and $sent_folder is set? Should it still be skipped?
158 for ($p = 0, $cnt = count($boxes); $p < $cnt && $count_special_folders < $num_max; $p++
) {
159 switch ($boxes[$p]['unformatted'])
161 case (strtoupper($boxes[$p]['unformatted']) == 'INBOX'):
162 ++
$count_special_folders;
163 $skip_folders[] = $boxes[$p]['unformatted'];
165 // FIX ME inbox.trash should be set in conf.pl
167 if (strtolower($imap_server_type) == 'courier') {
168 ++
$count_special_folders;
172 ++
$count_special_folders;
173 $skip_folders[] = $trash_folder;
176 ++
$count_special_folders;
177 $skip_folders[] = $sent_folder;
180 ++
$count_special_folders;
181 $skip_folders[] = $draft_folder;
188 /** RENAMING FOLDERS **/
190 html_tag( 'td', '<b>' . _("Rename a Folder") . '</b>', 'center', $color[9] )
193 html_tag( 'td', '', 'center', $color[0] );
195 if ($count_special_folders < count($boxes)) {
196 echo "<FORM ACTION=\"folders_rename_getname.php\" METHOD=\"POST\">\n"
197 . "<TT><SELECT NAME=old>\n"
198 . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
200 // use existing IMAP connection, we have no special values to show,
201 // but we do include values to skip. Use the pre-created $boxes to save an IMAP query.
202 // send NULL for the flag - ALL folders are eligible for rename!
203 // use long format to make sure folder names make sense when parents may be missing.
204 echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes, NULL, true);
206 echo "</SELECT></TT>\n".
207 "<input type=SUBMIT VALUE=\"".
210 "</FORM></td></tr>\n";
212 echo _("No folders found") . '<br><br></td></tr>';
217 html_tag( 'td', ' ', 'left', $color[4] )
220 /** DELETING FOLDERS **/
222 html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[9] )
225 html_tag( 'td', '', 'center', $color[0] );
227 if ($count_special_folders < count($boxes)) {
228 echo "<FORM ACTION=\"folders_delete.php\" METHOD=\"POST\">\n"
229 . "<TT><SELECT NAME=mailbox>\n"
230 . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
232 // send NULL for the flag - ALL folders are eligible for delete (except what we've got in skiplist)
233 // use long format to make sure folder names make sense when parents may be missing.
234 echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes, NULL, true);
236 echo "</SELECT></TT>\n"
237 . '<input type=SUBMIT VALUE="'
240 . "</form></td></tr>\n";
242 echo _("No folders found") . "<br><br></td></tr>";
246 html_tag( 'td', ' ', 'left', $color[4] )
250 /** UNSUBSCRIBE FOLDERS **/
251 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
253 html_tag( 'td', '<b>' . _("Unsubscribe") . '/' . _("Subscribe") . '</b>', 'center', $color[9], 'colspan="2"' )
256 html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
258 if ($count_special_folders < count($boxes)) {
259 echo "<FORM ACTION=\"folders_subscribe.php?method=unsub\" METHOD=\"POST\">\n"
260 . "<TT><SELECT NAME=\"mailbox[]\" multiple size=8>\n";
261 for ($i = 0; $i < count($boxes); $i++
) {
263 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
264 ($boxes[$i]["unformatted"] != $trash_folder) &&
265 ($boxes[$i]["unformatted"] != $sent_folder) &&
266 ($boxes[$i]["unformatted"] != $draft_folder)) {
267 $box = htmlspecialchars($boxes[$i]["unformatted-dm"]);
268 $box2 = str_replace(' ', ' ',
269 htmlspecialchars(imap_utf7_decode_local($boxes[$i]["unformatted-disp"])));
270 echo " <OPTION VALUE=\"$box\">$box2\n";
273 echo "</SELECT></TT><br><br>\n"
274 . '<input type=SUBMIT VALUE="'
279 echo _("No folders were found to unsubscribe from!") . '</td>';
283 /** SUBSCRIBE TO FOLDERS **/
284 echo html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
285 if(!$no_list_for_subscribe) {
286 $boxes_all = sqimap_mailbox_list_all ($imapConnection);
290 for ($i = 0, $q = 0; $i < count($boxes_all); $i++
) {
292 for ($p = 0; $p < count ($boxes); $p++
) {
293 if ($boxes_all[$i]['unformatted'] == $boxes[$p]['unformatted']) {
296 } else if ($boxes_all[$i]['unformatted-dm'] == $folder_prefix) {
300 if ($use_folder == true) {
301 $box[$q] = htmlspecialchars($boxes_all[$i]['unformatted-dm']);
302 $box2[$q] = htmlspecialchars(imap_utf7_decode_local($boxes_all[$i]['unformatted-disp']));
307 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n"
308 . '<tt><select name="mailbox[]" multiple size=8>';
310 for ($q = 0; $q < count($box); $q++
) {
311 echo " <OPTION VALUE=\"$box[$q]\">".$box2[$q]."\n";
313 echo '</select></tt><br><br>'
314 . '<input type=SUBMIT VALUE="'. _("Subscribe") . "\">\n"
315 . "</FORM></td></tr></table><BR>\n";
317 echo _("No folders were found to subscribe to!") . '</td></tr></table>';
320 /* don't perform the list action -- this is much faster */
321 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n"
322 . _("Subscribe to:") . '<br>'
323 . '<tt><input type="text" name="mailbox[]" size=35>'
324 . '<INPUT TYPE=SUBMIT VALUE="'. _("Subscribe") . "\">\n"
325 . "</FORM></TD></TR></TABLE><BR>\n";
328 do_hook('folders_bottom');
338 sqimap_logout($imapConnection);