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 require_once('../src/validate.php');
17 require_once('../functions/imap_utf7_decode_local.php');
18 require_once('../functions/imap.php');
19 require_once('../functions/array.php');
20 require_once('../functions/plugin.php');
21 require_once('../functions/html.php');
23 displayPageHeader($color, 'None');
26 html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) .
28 html_tag( 'td', '', 'center' ) . '<b>' . _("Folders") . '</b>' .
29 html_tag( 'table', '', 'center', '', 'width="100%" cellpadding="5" cellspacing="0" border="0"' ) .
31 html_tag( 'td', '', 'center', $color[4] );
33 if ((isset($success) && $success) ||
34 (isset($sent_create) && $sent_create == 'true') ||
35 (isset($trash_create) && $trash_create == 'true')) {
36 if ($success == "subscribe") {
37 $td_str = "<b>" . _("Subscribed successfully!") . "</b><br>";
38 } else if ($success == "unsubscribe") {
39 $td_str = "<b>" . _("Unsubscribed successfully!") . "</b><br>";
40 } else if ($success == "delete") {
41 $td_str = "<b>" . _("Deleted folder successfully!") . "</b><br>";
42 } else if ($success == "create") {
43 $td_str = "<b>" . _("Created folder successfully!") . "</b><br>";
44 } else if ($success == "rename") {
45 $td_str = "<b>" . _("Renamed successfully!") . "</b><br>";
46 } else if ($success == "subscribe-doesnotexist") {
48 _("Subscription Unsuccessful - Folder does not exist.") .
52 echo html_tag( 'table',
54 html_tag( 'td', $td_str .
55 "<a href=\"../src/left_main.php\" target=left>" . _("refresh folder list") . "</a>" ,
58 'center', '', 'width="100%" cellpadding="4" cellspacing="0" border="0"' ) . "<br>\n";
62 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
63 $boxes = sqimap_mailbox_list($imapConnection);
65 /** CREATING FOLDERS **/
66 echo html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="4" cellspacing="0" border="0"' ) .
68 html_tag( 'td', '<b>' . _("Create Folder") . '</b>', 'center', $color[9] )
71 html_tag( 'td', '', 'center', $color[0] ) .
73 "<FORM NAME=cf ACTION=\"folders_create.php\" METHOD=\"POST\">\n".
74 "<input type=TEXT SIZE=25 NAME=folder_name><BR>\n".
75 _("as a subfolder of").
77 "<TT><SELECT NAME=subfolder>\n";
78 if ($default_sub_of_inbox == false) {
79 echo '<OPTION SELECTED VALUE="">[ '._("None")." ]\n";
81 echo '<OPTION VALUE="">[ '._("None")." ]\n";
84 for ($i = 0; $i < count($boxes); $i++
) {
85 if (!in_array('noinferiors', $boxes[$i]['flags'])) {
86 if ((strtolower($boxes[$i]['unformatted']) == 'inbox') &&
87 $default_sub_of_inbox) {
89 $box = $boxes[$i]['unformatted'];
90 $box2 = str_replace(' ', ' ',
91 imap_utf7_decode_local($boxes[$i]['unformatted-disp']));
92 echo "<OPTION SELECTED VALUE=\"$box\">$box2</option>\n";
94 $box = $boxes[$i]['unformatted'];
95 $box2 = str_replace(' ', ' ',
96 imap_utf7_decode_local($boxes[$i]['unformatted-disp']));
97 if (strtolower($imap_server_type) != 'courier' ||
98 strtolower($box) != "inbox.trash")
99 echo "<OPTION VALUE=\"$box\">$box2</option>\n";
103 echo "</SELECT></TT>\n";
104 if ($show_contain_subfolders_option) {
105 echo "<br><input type=CHECKBOX NAME=\"contain_subs\"> ";
106 echo _("Let this folder contain subfolders");
109 echo "<input type=SUBMIT VALUE=\""._("Create")."\">\n";
110 echo "</FORM></td></tr>\n";
113 html_tag( 'td', ' ', 'left', $color[4] )
116 /** count special folders **/
117 $count_special_folders = 0;
119 if (strtolower($imap_server_type) == "courier" ||
$move_to_trash) {
125 if ($save_as_draft) {
128 for ($p = 0; $p < count($boxes) && $count_special_folders < $num_max; $p++
) {
129 if (strtolower($boxes[$p]['unformatted']) == 'inbox')
130 $count_special_folders++
;
131 else if (strtolower($imap_server_type) == 'courier' &&
132 strtolower($boxes[$p]['unformatted']) == 'inbox.trash')
133 $count_special_folders++
;
134 else if ($boxes[$p]['unformatted'] == $trash_folder && $trash_folder)
135 $count_special_folders++
;
136 else if ($boxes[$p]['unformatted'] == $sent_folder && $sent_folder)
137 $count_special_folders++
;
138 else if ($boxes[$p]['unformatted'] == $draft_folder && $draft_folder)
139 $count_special_folders++
;
143 /** RENAMING FOLDERS **/
145 html_tag( 'td', '<b>' . _("Rename a Folder") . '</b>', 'center', $color[9] )
148 html_tag( 'td', '', 'center', $color[0] );
150 if ($count_special_folders < count($boxes)) {
151 echo "<FORM ACTION=\"folders_rename_getname.php\" METHOD=\"POST\">\n"
152 . "<TT><SELECT NAME=old>\n"
153 . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
154 for ($i = 0; $i < count($boxes); $i++
) {
157 if ((strtolower($boxes[$i]['unformatted']) != 'inbox') &&
158 ($boxes[$i]['unformatted'] != $trash_folder) &&
159 ($boxes[$i]['unformatted'] != $sent_folder) &&
160 ($boxes[$i]['unformatted'] != $draft_folder)) {
161 $box = $boxes[$i]['unformatted-dm'];
163 $box2 = str_replace(' ', ' ',
164 imap_utf7_decode_local($boxes[$i]['unformatted-disp']));
165 if (strtolower($imap_server_type) != 'courier' ||
strtolower($box) != 'inbox.trash') {
166 echo "<OPTION VALUE=\"$box\">$box2</option>\n";
170 echo "</SELECT></TT>\n".
171 "<input type=SUBMIT VALUE=\"".
174 "</FORM></td></tr>\n";
176 echo _("No folders found") . "<br><br></td></tr>";
181 html_tag( 'td', ' ', 'left', $color[4] )
184 /** DELETING FOLDERS **/
186 html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[9] )
189 html_tag( 'td', '', 'center', $color[0] );
191 if ($count_special_folders < count($boxes)) {
192 echo "<FORM ACTION=\"folders_delete.php\" METHOD=\"POST\">\n"
193 . "<TT><SELECT NAME=mailbox>\n"
194 . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
195 for ($i = 0; $i < count($boxes); $i++
) {
197 if ((strtolower($boxes[$i]['unformatted']) != 'inbox') &&
198 ($boxes[$i]['unformatted'] != $trash_folder) &&
199 ($boxes[$i]['unformatted'] != $sent_folder) &&
200 ($boxes[$i]['unformatted'] != $draft_folder) &&
201 (!in_array('noselect', $boxes[$i]['flags'])) &&
202 ((strtolower($imap_server_type) != 'courier') ||
203 (strtolower($boxes[$i]['unformatted']) != 'inbox.trash'))) {
204 $box = $boxes[$i]['unformatted-dm'];
205 $box2 = str_replace(' ', ' ',
206 imap_utf7_decode_local($boxes[$i]['unformatted-disp']));
207 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
210 echo "</SELECT></TT>\n";
211 echo "<input type=SUBMIT VALUE=\"";
214 echo "</form></td></tr>\n";
216 echo _("No folders found") . "<br><br></td></tr>";
220 html_tag( 'td', ' ', 'left', $color[4] )
224 /** UNSUBSCRIBE FOLDERS **/
225 echo html_tag( 'table', '', 'center', '', 'width="70%" cols="2" cellpadding="4" cellspacing="0" border="0"' ) .
227 html_tag( 'td', '<b>' . _("Unsubscribe") . '/' . _("Subscribe") . '</b>', 'center', $color[9], 'colspan="2"' )
230 html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
232 if ($count_special_folders < count($boxes)) {
233 echo "<FORM ACTION=\"folders_subscribe.php?method=unsub\" METHOD=\"POST\">\n";
234 echo "<TT><SELECT NAME=\"mailbox[]\" multiple size=8>\n";
235 for ($i = 0; $i < count($boxes); $i++
) {
237 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
238 ($boxes[$i]["unformatted"] != $trash_folder) &&
239 ($boxes[$i]["unformatted"] != $sent_folder) &&
240 ($boxes[$i]["unformatted"] != $draft_folder)) {
241 $box = $boxes[$i]["unformatted-dm"];
242 $box2 = str_replace(' ', ' ',
243 imap_utf7_decode_local($boxes[$i]["unformatted-disp"]));
244 echo " <OPTION VALUE=\"$box\">$box2\n";
247 echo "</SELECT></TT><br><br>\n";
248 echo "<input type=SUBMIT VALUE=\"";
249 echo _("Unsubscribe");
251 echo "</FORM></td>\n";
253 echo _("No folders were found to unsubscribe from!") . "</td>";
257 /** SUBSCRIBE TO FOLDERS **/
258 echo html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
259 if(!$no_list_for_subscribe) {
260 $imap_stream = sqimap_login ($username, $key, $imapServerAddress,
262 $boxes_all = sqimap_mailbox_list_all ($imap_stream);
266 for ($i = 0, $q = 0; $i < count($boxes_all); $i++
) {
268 for ($p = 0; $p < count ($boxes); $p++
) {
269 if ($boxes_all[$i]["unformatted"] == $boxes[$p]["unformatted"]) {
272 } else if ($boxes_all[$i]["unformatted-dm"] == $folder_prefix) {
276 if ($use_folder == true) {
277 $box[$q] = $boxes_all[$i]["unformatted-dm"];
278 $box2[$q] = imap_utf7_decode_local($boxes_all[$i]["unformatted-disp"]);
282 sqimap_logout($imap_stream);
285 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n";
286 echo "<tt><select name=\"mailbox[]\" multiple size=8>";
288 for ($q = 0; $q < count($box); $q++
) {
289 echo " <OPTION VALUE=\"$box[$q]\">".$box2[$q]."\n";
291 echo "</select></tt><br><br>";
292 echo "<input type=SUBMIT VALUE=\"". _("Subscribe") . "\">\n";
293 echo "</FORM></td></tr></table><BR>\n";
295 echo _("No folders were found to subscribe to!") . "</td></tr></table>";
298 /* don't perform the list action -- this is much faster */
299 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n";
300 echo _("Subscribe to:") . "<br>";
301 echo "<tt><input type=\"text\" name=\"mailbox[]\" size=35>";
302 echo "<INPUT TYPE=SUBMIT VALUE=\"". _("Subscribe") . "\">\n";
303 echo "</FORM></TD></TR></TABLE><BR>\n";
306 do_hook("folders_bottom");
317 sqimap_logout($imapConnection);