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
16 /* Path for SquirrelMail required files. */
17 define('SM_PATH','../');
19 /* SquirrelMail required files. */
20 require_once(SM_PATH
. 'include/validate.php');
21 require_once(SM_PATH
. 'functions/imap.php');
22 require_once(SM_PATH
. 'functions/plugin.php');
23 require_once(SM_PATH
. 'functions/html.php');
25 displayPageHeader($color, 'None');
27 /* get globals we may need */
29 sqgetGlobalVar('username', $username, SQ_SESSION
);
30 sqgetGlobalVar('key', $key, SQ_COOKIE
);
31 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
32 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION
);
34 sqgetGlobalVar('success', $success, SQ_GET
);
36 /* end of get globals */
39 html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) .
41 html_tag( 'td', '', 'center' ) . '<b>' . _("Folders") . '</b>' .
42 html_tag( 'table', '', 'center', '', 'width="100%" cellpadding="5" cellspacing="0" border="0"' ) .
44 html_tag( 'td', '', 'center', $color[4] );
46 if ( isset($success) && $success ) {
53 $td_str .= _("Subscribed successfully!");
56 $td_str .= _("Unsubscribed successfully!");
59 $td_str .= _("Deleted folder successfully!");
62 $td_str .= _("Created folder successfully!");
65 $td_str .= _("Renamed successfully!");
67 case 'subscribe-doesnotexist':
68 $td_str .= _("Subscription Unsuccessful - Folder does not exist.");
72 $td_str .= '</b><br>';
75 echo html_tag( 'table',
77 html_tag( 'td', $td_str .
78 '<a href="../src/left_main.php" target=left>' .
79 _("refresh folder list") . '</a>' ,
82 'center', '', 'width="100%" cellpadding="4" cellspacing="0" border="0"' );
87 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
88 $boxes = sqimap_mailbox_list($imapConnection);
90 /** CREATING FOLDERS **/
91 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
93 html_tag( 'td', '<b>' . _("Create Folder") . '</b>', 'center', $color[9] )
96 html_tag( 'td', '', 'center', $color[0] ) .
98 "<FORM NAME=cf ACTION=\"folders_create.php\" METHOD=\"POST\">\n".
99 "<input type=TEXT SIZE=25 NAME=folder_name><BR>\n".
100 _("as a subfolder of").
102 "<TT><SELECT NAME=subfolder>\n";
104 $show_selected = array();
105 $skip_folders = array();
106 $server_type = strtolower($imap_server_type);
107 if ( $server_type == 'courier' ) {
108 array_push($skip_folders, 'inbox.trash');
109 if ( $default_folder_prefix == 'INBOX.' ) {
110 array_push($skip_folders, 'inbox');
114 if ( $default_sub_of_inbox == false ) {
115 echo '<OPTION SELECTED VALUE="">[ '._("None")." ]\n";
117 echo '<OPTION VALUE="">[ '._("None")." ]\n";
118 $show_selected = array('inbox');
121 // Call sqimap_mailbox_option_list, using existing connection to IMAP server,
122 // the arrays of folders to include or skip (assembled above),
123 // and indicate that folders listed should be parents (we're creating folders,
124 // so we want to list the folders that can contain other folders), also force long form
125 echo sqimap_mailbox_option_list($imapConnection, $show_selected, $skip_folders, $boxes, true, true);
127 echo "</SELECT></TT>\n";
128 if ($show_contain_subfolders_option) {
129 echo '<br><input type=CHECKBOX NAME="contain_subs"> '
130 . _("Let this folder contain subfolders")
133 echo "<input type=SUBMIT VALUE=\""._("Create")."\">\n";
134 echo "</FORM></td></tr>\n";
137 html_tag( 'td', ' ', 'left', $color[4] )
140 /** count special folders **/
141 $count_special_folders = 0;
143 if (strtolower($imap_server_type) == "courier" ||
$move_to_trash) {
149 if ($save_as_draft) {
152 for ($p = 0, $cnt = count($boxes); $p < $cnt && $count_special_folders < $num_max; $p++
) {
153 if (strtolower($boxes[$p]['unformatted']) == 'inbox')
154 $count_special_folders++
;
155 else if (strtolower($imap_server_type) == 'courier' &&
156 strtolower($boxes[$p]['unformatted']) == 'inbox.trash') {
157 $count_special_folders++
;
159 else if ($boxes[$p]['unformatted'] == $trash_folder && $trash_folder) {
160 $count_special_folders++
;
161 array_push($skip_folders, strtolower($trash_folder));
163 else if ($boxes[$p]['unformatted'] == $sent_folder && $sent_folder) {
164 $count_special_folders++
;
165 array_push($skip_folders, strtolower($sent_folder));
167 else if ($boxes[$p]['unformatted'] == $draft_folder && $draft_folder) {
168 $count_special_folders++
;
169 array_push($skip_folders, strtolower($draft_folder));
174 /** RENAMING FOLDERS **/
176 html_tag( 'td', '<b>' . _("Rename a Folder") . '</b>', 'center', $color[9] )
179 html_tag( 'td', '', 'center', $color[0] );
181 if ($count_special_folders < count($boxes)) {
182 echo "<FORM ACTION=\"folders_rename_getname.php\" METHOD=\"POST\">\n"
183 . "<TT><SELECT NAME=old>\n"
184 . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
186 echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes, false, true);
188 echo "</SELECT></TT>\n".
189 "<input type=SUBMIT VALUE=\"".
192 "</FORM></td></tr>\n";
194 echo _("No folders found") . '<br><br></td></tr>';
199 html_tag( 'td', ' ', 'left', $color[4] )
202 /** DELETING FOLDERS **/
204 html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[9] )
207 html_tag( 'td', '', 'center', $color[0] );
209 if ($count_special_folders < count($boxes)) {
210 echo "<FORM ACTION=\"folders_delete.php\" METHOD=\"POST\">\n"
211 . "<TT><SELECT NAME=mailbox>\n"
212 . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
214 echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes, false, 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>";
226 html_tag( 'td', ' ', 'left', $color[4] )
230 /** UNSUBSCRIBE FOLDERS **/
231 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
233 html_tag( 'td', '<b>' . _("Unsubscribe") . '/' . _("Subscribe") . '</b>', 'center', $color[9], 'colspan="2"' )
236 html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
238 if ($count_special_folders < count($boxes)) {
239 echo "<FORM ACTION=\"folders_subscribe.php?method=unsub\" METHOD=\"POST\">\n"
240 . "<TT><SELECT NAME=\"mailbox[]\" multiple size=8>\n";
241 for ($i = 0; $i < count($boxes); $i++
) {
243 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
244 ($boxes[$i]["unformatted"] != $trash_folder) &&
245 ($boxes[$i]["unformatted"] != $sent_folder) &&
246 ($boxes[$i]["unformatted"] != $draft_folder)) {
247 $box = $boxes[$i]["unformatted-dm"];
248 $box2 = str_replace(' ', ' ',
249 imap_utf7_decode_local($boxes[$i]["unformatted-disp"]));
250 echo " <OPTION VALUE=\"$box\">$box2\n";
253 echo "</SELECT></TT><br><br>\n"
254 . '<input type=SUBMIT VALUE="'
259 echo _("No folders were found to unsubscribe from!") . '</td>';
263 /** SUBSCRIBE TO FOLDERS **/
264 echo html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
265 if(!$no_list_for_subscribe) {
266 $boxes_all = sqimap_mailbox_list_all ($imapConnection);
270 for ($i = 0, $q = 0; $i < count($boxes_all); $i++
) {
272 for ($p = 0; $p < count ($boxes); $p++
) {
273 if ($boxes_all[$i]['unformatted'] == $boxes[$p]['unformatted']) {
276 } else if ($boxes_all[$i]['unformatted-dm'] == $folder_prefix) {
280 if ($use_folder == true) {
281 $box[$q] = $boxes_all[$i]['unformatted-dm'];
282 $box2[$q] = imap_utf7_decode_local($boxes_all[$i]['unformatted-disp']);
287 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n"
288 . '<tt><select name="mailbox[]" multiple size=8>';
290 for ($q = 0; $q < count($box); $q++
) {
291 echo " <OPTION VALUE=\"$box[$q]\">".$box2[$q]."\n";
293 echo '</select></tt><br><br>'
294 . '<input type=SUBMIT VALUE="'. _("Subscribe") . "\">\n"
295 . "</FORM></td></tr></table><BR>\n";
297 echo _("No folders were found to subscribe to!") . '</td></tr></table>';
300 /* don't perform the list action -- this is much faster */
301 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n"
302 . _("Subscribe to:") . '<br>'
303 . '<tt><input type="text" name="mailbox[]" size=35>'
304 . '<INPUT TYPE=SUBMIT VALUE="'. _("Subscribe") . "\">\n"
305 . "</FORM></TD></TR></TABLE><BR>\n";
308 do_hook('folders_bottom');
318 sqimap_logout($imapConnection);