6 * Copyright (c) 1999-2002 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_utf7_decode_local.php');
22 require_once(SM_PATH
. 'functions/imap.php');
23 require_once(SM_PATH
. 'functions/array.php');
24 require_once(SM_PATH
. 'functions/plugin.php');
25 require_once(SM_PATH
. 'functions/html.php');
27 displayPageHeader($color, 'None');
29 /* get globals we may need */
31 $username = $_SESSION['username'];
32 $key = $_COOKIE['key'];
33 $delimiter = $_SESSION['delimiter'];
34 $onetimepad = $_SESSION['onetimepad'];
35 if (isset($_GET['success'])) {
36 $success = $_GET['success'];
39 /* end of get globals */
42 html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) .
44 html_tag( 'td', '', 'center' ) . '<b>' . _("Folders") . '</b>' .
45 html_tag( 'table', '', 'center', '', 'width="100%" cellpadding="5" cellspacing="0" border="0"' ) .
47 html_tag( 'td', '', 'center', $color[4] );
49 if ((isset($success) && $success) ||
50 (isset($sent_create) && $sent_create == 'true') ||
51 (isset($trash_create) && $trash_create == 'true')) {
52 if ($success == "subscribe") {
53 $td_str = "<b>" . _("Subscribed successfully!") . "</b><br>";
54 } else if ($success == "unsubscribe") {
55 $td_str = "<b>" . _("Unsubscribed successfully!") . "</b><br>";
56 } else if ($success == "delete") {
57 $td_str = "<b>" . _("Deleted folder successfully!") . "</b><br>";
58 } else if ($success == "create") {
59 $td_str = "<b>" . _("Created folder successfully!") . "</b><br>";
60 } else if ($success == "rename") {
61 $td_str = "<b>" . _("Renamed successfully!") . "</b><br>";
62 } else if ($success == "subscribe-doesnotexist") {
64 _("Subscription Unsuccessful - Folder does not exist.") .
68 echo html_tag( 'table',
70 html_tag( 'td', $td_str .
71 "<a href=\"../src/left_main.php\" target=left>" . _("refresh folder list") . "</a>" ,
74 'center', '', 'width="100%" cellpadding="4" cellspacing="0" border="0"' ) . "<br>\n";
78 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
79 $boxes = sqimap_mailbox_list($imapConnection);
81 /** CREATING FOLDERS **/
82 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
84 html_tag( 'td', '<b>' . _("Create Folder") . '</b>', 'center', $color[9] )
87 html_tag( 'td', '', 'center', $color[0] ) .
89 "<FORM NAME=cf ACTION=\"folders_create.php\" METHOD=\"POST\">\n".
90 "<input type=TEXT SIZE=25 NAME=folder_name><BR>\n".
91 _("as a subfolder of").
93 "<TT><SELECT NAME=subfolder>\n";
94 if ($default_sub_of_inbox == false) {
95 echo '<OPTION SELECTED VALUE="">[ '._("None")." ]\n";
97 echo '<OPTION VALUE="">[ '._("None")." ]\n";
100 for ($i = 0, $cnt=count($boxes); $i < $cnt; $i++
) {
101 if (!in_array('noinferiors', $boxes[$i]['flags'])) {
102 if ((strtolower($boxes[$i]['unformatted']) == 'inbox') &&
103 $default_sub_of_inbox) {
105 $box = $boxes[$i]['unformatted'];
106 $box2 = str_replace(' ', ' ',
107 imap_utf7_decode_local($boxes[$i]['unformatted-disp']));
108 echo "<OPTION SELECTED VALUE=\"$box\">$box2</option>\n";
110 $box = $boxes[$i]['unformatted'];
111 $box2 = str_replace(' ', ' ',
112 imap_utf7_decode_local($boxes[$i]['unformatted-disp']));
113 if (strtolower($imap_server_type) != 'courier' ||
114 strtolower($box) != "inbox.trash")
115 echo "<OPTION VALUE=\"$box\">$box2</option>\n";
119 echo "</SELECT></TT>\n";
120 if ($show_contain_subfolders_option) {
121 echo "<br><input type=CHECKBOX NAME=\"contain_subs\"> ";
122 echo _("Let this folder contain subfolders");
125 echo "<input type=SUBMIT VALUE=\""._("Create")."\">\n";
126 echo "</FORM></td></tr>\n";
129 html_tag( 'td', ' ', 'left', $color[4] )
132 /** count special folders **/
133 $count_special_folders = 0;
135 if (strtolower($imap_server_type) == "courier" ||
$move_to_trash) {
141 if ($save_as_draft) {
144 for ($p = 0, $cnt = count($boxes); $p < $cnt && $count_special_folders < $num_max; $p++
) {
145 if (strtolower($boxes[$p]['unformatted']) == 'inbox')
146 $count_special_folders++
;
147 else if (strtolower($imap_server_type) == 'courier' &&
148 strtolower($boxes[$p]['unformatted']) == 'inbox.trash')
149 $count_special_folders++
;
150 else if ($boxes[$p]['unformatted'] == $trash_folder && $trash_folder)
151 $count_special_folders++
;
152 else if ($boxes[$p]['unformatted'] == $sent_folder && $sent_folder)
153 $count_special_folders++
;
154 else if ($boxes[$p]['unformatted'] == $draft_folder && $draft_folder)
155 $count_special_folders++
;
159 /** RENAMING FOLDERS **/
161 html_tag( 'td', '<b>' . _("Rename a Folder") . '</b>', 'center', $color[9] )
164 html_tag( 'td', '', 'center', $color[0] );
166 if ($count_special_folders < count($boxes)) {
167 echo "<FORM ACTION=\"folders_rename_getname.php\" METHOD=\"POST\">\n"
168 . "<TT><SELECT NAME=old>\n"
169 . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
170 for ($i = 0; $i < count($boxes); $i++
) {
173 if ((strtolower($boxes[$i]['unformatted']) != 'inbox') &&
174 ($boxes[$i]['unformatted'] != $trash_folder) &&
175 ($boxes[$i]['unformatted'] != $sent_folder) &&
176 ($boxes[$i]['unformatted'] != $draft_folder)) {
177 $box = $boxes[$i]['unformatted-dm'];
179 $box2 = str_replace(' ', ' ',
180 imap_utf7_decode_local($boxes[$i]['unformatted-disp']));
181 if (strtolower($imap_server_type) != 'courier' ||
strtolower($box) != 'inbox.trash') {
182 echo "<OPTION VALUE=\"$box\">$box2</option>\n";
186 echo "</SELECT></TT>\n".
187 "<input type=SUBMIT VALUE=\"".
190 "</FORM></td></tr>\n";
192 echo _("No folders found") . "<br><br></td></tr>";
197 html_tag( 'td', ' ', 'left', $color[4] )
200 /** DELETING FOLDERS **/
202 html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[9] )
205 html_tag( 'td', '', 'center', $color[0] );
207 if ($count_special_folders < count($boxes)) {
208 echo "<FORM ACTION=\"folders_delete.php\" METHOD=\"POST\">\n"
209 . "<TT><SELECT NAME=mailbox>\n"
210 . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
211 for ($i = 0; $i < count($boxes); $i++
) {
213 if ((strtolower($boxes[$i]['unformatted']) != 'inbox') &&
214 ($boxes[$i]['unformatted'] != $trash_folder) &&
215 ($boxes[$i]['unformatted'] != $sent_folder) &&
216 ($boxes[$i]['unformatted'] != $draft_folder) &&
217 (!in_array('noselect', $boxes[$i]['flags'])) &&
218 ((strtolower($imap_server_type) != 'courier') ||
219 (strtolower($boxes[$i]['unformatted']) != 'inbox.trash'))) {
220 $box = $boxes[$i]['unformatted-dm'];
221 $box2 = str_replace(' ', ' ',
222 imap_utf7_decode_local($boxes[$i]['unformatted-disp']));
223 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
226 echo "</SELECT></TT>\n";
227 echo "<input type=SUBMIT VALUE=\"";
230 echo "</form></td></tr>\n";
232 echo _("No folders found") . "<br><br></td></tr>";
236 html_tag( 'td', ' ', 'left', $color[4] )
240 /** UNSUBSCRIBE FOLDERS **/
241 echo html_tag( 'table', '', 'center', '', 'width="70%" cols="2" cellpadding="4" cellspacing="0" border="0"' ) .
243 html_tag( 'td', '<b>' . _("Unsubscribe") . '/' . _("Subscribe") . '</b>', 'center', $color[9], 'colspan="2"' )
246 html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
248 if ($count_special_folders < count($boxes)) {
249 echo "<FORM ACTION=\"folders_subscribe.php?method=unsub\" METHOD=\"POST\">\n";
250 echo "<TT><SELECT NAME=\"mailbox[]\" multiple size=8>\n";
251 for ($i = 0; $i < count($boxes); $i++
) {
253 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
254 ($boxes[$i]["unformatted"] != $trash_folder) &&
255 ($boxes[$i]["unformatted"] != $sent_folder) &&
256 ($boxes[$i]["unformatted"] != $draft_folder)) {
257 $box = $boxes[$i]["unformatted-dm"];
258 $box2 = str_replace(' ', ' ',
259 imap_utf7_decode_local($boxes[$i]["unformatted-disp"]));
260 echo " <OPTION VALUE=\"$box\">$box2\n";
263 echo "</SELECT></TT><br><br>\n";
264 echo "<input type=SUBMIT VALUE=\"";
265 echo _("Unsubscribe");
267 echo "</FORM></td>\n";
269 echo _("No folders were found to unsubscribe from!") . "</td>";
273 /** SUBSCRIBE TO FOLDERS **/
274 echo html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
275 if(!$no_list_for_subscribe) {
276 $boxes_all = sqimap_mailbox_list_all ($imapConnection);
280 for ($i = 0, $q = 0; $i < count($boxes_all); $i++
) {
282 for ($p = 0; $p < count ($boxes); $p++
) {
283 if ($boxes_all[$i]["unformatted"] == $boxes[$p]["unformatted"]) {
286 } else if ($boxes_all[$i]["unformatted-dm"] == $folder_prefix) {
290 if ($use_folder == true) {
291 $box[$q] = $boxes_all[$i]["unformatted-dm"];
292 $box2[$q] = imap_utf7_decode_local($boxes_all[$i]["unformatted-disp"]);
297 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n";
298 echo "<tt><select name=\"mailbox[]\" multiple size=8>";
300 for ($q = 0; $q < count($box); $q++
) {
301 echo " <OPTION VALUE=\"$box[$q]\">".$box2[$q]."\n";
303 echo "</select></tt><br><br>";
304 echo "<input type=SUBMIT VALUE=\"". _("Subscribe") . "\">\n";
305 echo "</FORM></td></tr></table><BR>\n";
307 echo _("No folders were found to subscribe to!") . "</td></tr></table>";
310 /* don't perform the list action -- this is much faster */
311 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n";
312 echo _("Subscribe to:") . "<br>";
313 echo "<tt><input type=\"text\" name=\"mailbox[]\" size=35>";
314 echo "<INPUT TYPE=SUBMIT VALUE=\"". _("Subscribe") . "\">\n";
315 echo "</FORM></TD></TR></TABLE><BR>\n";
318 do_hook("folders_bottom");
329 sqimap_logout($imapConnection);