866f9d42aebf733566e8538ed10e91f851baf8f8
6 * Copyright (c) 1999-2003 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>';
75 if (isset($use_frames) && $use_frames) {
76 echo html_tag( 'table',
78 html_tag( 'td', $td_str .
79 '<a href="' . SM_PATH
. 'src/left_main.php" target=left>' .
80 _("refresh folder list") . '</a>' ,
83 'center', '', 'width="100%" cellpadding="4" cellspacing="0" border="0"' );
85 echo html_tag( 'table',
87 html_tag( 'td', $td_str .
88 '<a href="' . SM_PATH
. 'src/folders.php">' .
89 _("refresh folder list") . '</a>' ,
92 'center', '', 'width="100%" cellpadding="4" cellspacing="0" border="0"' );
98 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
99 $boxes = sqimap_mailbox_list($imapConnection);
101 /** CREATING FOLDERS **/
102 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
104 html_tag( 'td', '<b>' . _("Create Folder") . '</b>', 'center', $color[9] )
107 html_tag( 'td', '', 'center', $color[0] ) .
109 "<FORM NAME=cf ACTION=\"folders_create.php\" METHOD=\"POST\">\n".
110 "<input type=TEXT SIZE=25 NAME=folder_name><BR>\n".
111 _("as a subfolder of").
113 "<TT><SELECT NAME=subfolder>\n";
115 $show_selected = array();
116 $skip_folders = array();
117 $server_type = strtolower($imap_server_type);
118 if ( $server_type == 'courier' ) {
119 array_push($skip_folders, 'inbox.trash');
120 if ( $default_folder_prefix == 'INBOX.' ) {
121 array_push($skip_folders, 'inbox');
125 if ( $default_sub_of_inbox == false ) {
126 echo '<OPTION SELECTED VALUE="">[ '._("None")." ]\n";
128 echo '<OPTION VALUE="">[ '._("None")." ]\n";
129 $show_selected = array('inbox');
132 // Call sqimap_mailbox_option_list, using existing connection to IMAP server,
133 // the arrays of folders to include or skip (assembled above),
134 // use 'noinferiors' as a mailbox filter to leave out folders that can not contain other folders.
135 // use the long format to show subfolders in an intelligible way if parent is missing (special folder)
136 echo sqimap_mailbox_option_list($imapConnection, $show_selected, $skip_folders, $boxes, 'noinferiors', true);
138 echo "</SELECT></TT>\n";
139 if ($show_contain_subfolders_option) {
140 echo '<br><input type=CHECKBOX NAME="contain_subs"> '
141 . _("Let this folder contain subfolders")
144 echo "<input type=SUBMIT VALUE=\""._("Create")."\">\n";
145 echo "</FORM></td></tr>\n";
148 html_tag( 'td', ' ', 'left', $color[4] )
151 /** count special folders **/
153 // FIX ME, why not check if the folders are defined IMHO move_to_sent, move_to_trash has nothing todo with it
154 $count_special_folders = 0;
156 if (strtolower($imap_server_type) == "courier" ||
$move_to_trash) {
162 if ($save_as_draft) {
166 // What if move_to_sent = false and $sent_folder is set? Should it still be skipped?
168 for ($p = 0, $cnt = count($boxes); $p < $cnt && $count_special_folders < $num_max; $p++
) {
169 switch ($boxes[$p]['unformatted'])
171 case (strtoupper($boxes[$p]['unformatted']) == 'INBOX'):
172 ++
$count_special_folders;
173 $skip_folders[] = $boxes[$p]['unformatted'];
175 // FIX ME inbox.trash should be set in conf.pl
177 if (strtolower($imap_server_type) == 'courier') {
178 ++
$count_special_folders;
182 ++
$count_special_folders;
183 $skip_folders[] = $trash_folder;
186 ++
$count_special_folders;
187 $skip_folders[] = $sent_folder;
190 ++
$count_special_folders;
191 $skip_folders[] = $draft_folder;
198 /** RENAMING FOLDERS **/
200 html_tag( 'td', '<b>' . _("Rename a Folder") . '</b>', 'center', $color[9] )
203 html_tag( 'td', '', 'center', $color[0] );
205 if ($count_special_folders < count($boxes)) {
206 echo "<FORM ACTION=\"folders_rename_getname.php\" METHOD=\"POST\">\n"
207 . "<TT><SELECT NAME=old>\n"
208 . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
210 // use existing IMAP connection, we have no special values to show,
211 // but we do include values to skip. Use the pre-created $boxes to save an IMAP query.
212 // send NULL for the flag - ALL folders are eligible for rename!
213 // use long format to make sure folder names make sense when parents may be missing.
214 echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes, NULL, true);
216 echo "</SELECT></TT>\n".
217 "<input type=SUBMIT VALUE=\"".
220 "</FORM></td></tr>\n";
222 echo _("No folders found") . '<br><br></td></tr>';
227 html_tag( 'td', ' ', 'left', $color[4] )
230 /** DELETING FOLDERS **/
232 html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[9] )
235 html_tag( 'td', '', 'center', $color[0] );
237 if ($count_special_folders < count($boxes)) {
238 echo "<FORM ACTION=\"folders_delete.php\" METHOD=\"POST\">\n"
239 . "<TT><SELECT NAME=mailbox>\n"
240 . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
242 // send NULL for the flag - ALL folders are eligible for delete (except what we've got in skiplist)
243 // use long format to make sure folder names make sense when parents may be missing.
244 echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes, NULL, true);
246 echo "</SELECT></TT>\n"
247 . '<input type=SUBMIT VALUE="'
250 . "</form></td></tr>\n";
252 echo _("No folders found") . "<br><br></td></tr>";
256 html_tag( 'td', ' ', 'left', $color[4] )
260 /** UNSUBSCRIBE FOLDERS **/
261 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
263 html_tag( 'td', '<b>' . _("Unsubscribe") . '/' . _("Subscribe") . '</b>', 'center', $color[9], 'colspan="2"' )
266 html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
268 if ($count_special_folders < count($boxes)) {
269 echo "<FORM ACTION=\"folders_subscribe.php?method=unsub\" METHOD=\"POST\">\n"
270 . "<TT><SELECT NAME=\"mailbox[]\" multiple size=8>\n";
271 for ($i = 0; $i < count($boxes); $i++
) {
273 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
274 ($boxes[$i]["unformatted"] != $trash_folder) &&
275 ($boxes[$i]["unformatted"] != $sent_folder) &&
276 ($boxes[$i]["unformatted"] != $draft_folder)) {
277 $box = htmlspecialchars($boxes[$i]["unformatted-dm"]);
278 $box2 = str_replace(' ', ' ',
279 htmlspecialchars(imap_utf7_decode_local($boxes[$i]["unformatted-disp"])));
280 echo " <OPTION VALUE=\"$box\">$box2\n";
283 echo "</SELECT></TT><br><br>\n"
284 . '<input type=SUBMIT VALUE="'
289 echo _("No folders were found to unsubscribe from!") . '</td>';
293 /** SUBSCRIBE TO FOLDERS **/
294 echo html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
295 if(!$no_list_for_subscribe) {
296 $boxes_all = sqimap_mailbox_list_all ($imapConnection);
300 for ($i = 0, $q = 0; $i < count($boxes_all); $i++
) {
302 for ($p = 0; $p < count ($boxes); $p++
) {
303 if ($boxes_all[$i]['unformatted'] == $boxes[$p]['unformatted']) {
306 } else if ($boxes_all[$i]['unformatted-dm'] == $folder_prefix) {
310 if ($use_folder == true) {
311 $box[$q] = htmlspecialchars($boxes_all[$i]['unformatted-dm']);
312 $box2[$q] = htmlspecialchars(imap_utf7_decode_local($boxes_all[$i]['unformatted-disp']));
317 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n"
318 . '<tt><select name="mailbox[]" multiple size=8>';
320 for ($q = 0; $q < count($box); $q++
) {
321 echo " <OPTION VALUE=\"$box[$q]\">".$box2[$q]."\n";
323 echo '</select></tt><br><br>'
324 . '<input type=SUBMIT VALUE="'. _("Subscribe") . "\">\n"
325 . "</FORM></td></tr></table><BR>\n";
327 echo _("No folders were found to subscribe to!") . '</td></tr></table>';
330 /* don't perform the list action -- this is much faster */
331 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n"
332 . _("Subscribe to:") . '<br>'
333 . '<tt><input type="text" name="mailbox[]" size=35>'
334 . '<INPUT TYPE=SUBMIT VALUE="'. _("Subscribe") . "\">\n"
335 . "</FORM></TD></TR></TABLE><BR>\n";
338 do_hook('folders_bottom');
348 sqimap_logout($imapConnection);