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');
30 html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) .
32 html_tag( 'td', '', 'center' ) . '<b>' . _("Folders") . '</b>' .
33 html_tag( 'table', '', 'center', '', 'width="100%" cellpadding="5" cellspacing="0" border="0"' ) .
35 html_tag( 'td', '', 'center', $color[4] );
37 if ((isset($success) && $success) ||
38 (isset($sent_create) && $sent_create == 'true') ||
39 (isset($trash_create) && $trash_create == 'true')) {
40 if ($success == "subscribe") {
41 $td_str = "<b>" . _("Subscribed successfully!") . "</b><br>";
42 } else if ($success == "unsubscribe") {
43 $td_str = "<b>" . _("Unsubscribed successfully!") . "</b><br>";
44 } else if ($success == "delete") {
45 $td_str = "<b>" . _("Deleted folder successfully!") . "</b><br>";
46 } else if ($success == "create") {
47 $td_str = "<b>" . _("Created folder successfully!") . "</b><br>";
48 } else if ($success == "rename") {
49 $td_str = "<b>" . _("Renamed successfully!") . "</b><br>";
50 } else if ($success == "subscribe-doesnotexist") {
52 _("Subscription Unsuccessful - Folder does not exist.") .
56 echo html_tag( 'table',
58 html_tag( 'td', $td_str .
59 "<a href=\"../src/left_main.php\" target=left>" . _("refresh folder list") . "</a>" ,
62 'center', '', 'width="100%" cellpadding="4" cellspacing="0" border="0"' ) . "<br>\n";
66 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
67 $boxes = sqimap_mailbox_list($imapConnection);
69 /** CREATING FOLDERS **/
70 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
72 html_tag( 'td', '<b>' . _("Create Folder") . '</b>', 'center', $color[9] )
75 html_tag( 'td', '', 'center', $color[0] ) .
77 "<FORM NAME=cf ACTION=\"folders_create.php\" METHOD=\"POST\">\n".
78 "<input type=TEXT SIZE=25 NAME=folder_name><BR>\n".
79 _("as a subfolder of").
81 "<TT><SELECT NAME=subfolder>\n";
82 if ($default_sub_of_inbox == false) {
83 echo '<OPTION SELECTED VALUE="">[ '._("None")." ]\n";
85 echo '<OPTION VALUE="">[ '._("None")." ]\n";
88 for ($i = 0; $i < count($boxes); $i++
) {
89 if (!in_array('noinferiors', $boxes[$i]['flags'])) {
90 if ((strtolower($boxes[$i]['unformatted']) == 'inbox') &&
91 $default_sub_of_inbox) {
93 $box = $boxes[$i]['unformatted'];
94 $box2 = str_replace(' ', ' ',
95 imap_utf7_decode_local($boxes[$i]['unformatted-disp']));
96 echo "<OPTION SELECTED VALUE=\"$box\">$box2</option>\n";
98 $box = $boxes[$i]['unformatted'];
99 $box2 = str_replace(' ', ' ',
100 imap_utf7_decode_local($boxes[$i]['unformatted-disp']));
101 if (strtolower($imap_server_type) != 'courier' ||
102 strtolower($box) != "inbox.trash")
103 echo "<OPTION VALUE=\"$box\">$box2</option>\n";
107 echo "</SELECT></TT>\n";
108 if ($show_contain_subfolders_option) {
109 echo "<br><input type=CHECKBOX NAME=\"contain_subs\"> ";
110 echo _("Let this folder contain subfolders");
113 echo "<input type=SUBMIT VALUE=\""._("Create")."\">\n";
114 echo "</FORM></td></tr>\n";
117 html_tag( 'td', ' ', 'left', $color[4] )
120 /** count special folders **/
121 $count_special_folders = 0;
123 if (strtolower($imap_server_type) == "courier" ||
$move_to_trash) {
129 if ($save_as_draft) {
132 for ($p = 0; $p < count($boxes) && $count_special_folders < $num_max; $p++
) {
133 if (strtolower($boxes[$p]['unformatted']) == 'inbox')
134 $count_special_folders++
;
135 else if (strtolower($imap_server_type) == 'courier' &&
136 strtolower($boxes[$p]['unformatted']) == 'inbox.trash')
137 $count_special_folders++
;
138 else if ($boxes[$p]['unformatted'] == $trash_folder && $trash_folder)
139 $count_special_folders++
;
140 else if ($boxes[$p]['unformatted'] == $sent_folder && $sent_folder)
141 $count_special_folders++
;
142 else if ($boxes[$p]['unformatted'] == $draft_folder && $draft_folder)
143 $count_special_folders++
;
147 /** RENAMING FOLDERS **/
149 html_tag( 'td', '<b>' . _("Rename a Folder") . '</b>', 'center', $color[9] )
152 html_tag( 'td', '', 'center', $color[0] );
154 if ($count_special_folders < count($boxes)) {
155 echo "<FORM ACTION=\"folders_rename_getname.php\" METHOD=\"POST\">\n"
156 . "<TT><SELECT NAME=old>\n"
157 . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
158 for ($i = 0; $i < count($boxes); $i++
) {
161 if ((strtolower($boxes[$i]['unformatted']) != 'inbox') &&
162 ($boxes[$i]['unformatted'] != $trash_folder) &&
163 ($boxes[$i]['unformatted'] != $sent_folder) &&
164 ($boxes[$i]['unformatted'] != $draft_folder)) {
165 $box = $boxes[$i]['unformatted-dm'];
167 $box2 = str_replace(' ', ' ',
168 imap_utf7_decode_local($boxes[$i]['unformatted-disp']));
169 if (strtolower($imap_server_type) != 'courier' ||
strtolower($box) != 'inbox.trash') {
170 echo "<OPTION VALUE=\"$box\">$box2</option>\n";
174 echo "</SELECT></TT>\n".
175 "<input type=SUBMIT VALUE=\"".
178 "</FORM></td></tr>\n";
180 echo _("No folders found") . "<br><br></td></tr>";
185 html_tag( 'td', ' ', 'left', $color[4] )
188 /** DELETING FOLDERS **/
190 html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[9] )
193 html_tag( 'td', '', 'center', $color[0] );
195 if ($count_special_folders < count($boxes)) {
196 echo "<FORM ACTION=\"folders_delete.php\" METHOD=\"POST\">\n"
197 . "<TT><SELECT NAME=mailbox>\n"
198 . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
199 for ($i = 0; $i < count($boxes); $i++
) {
201 if ((strtolower($boxes[$i]['unformatted']) != 'inbox') &&
202 ($boxes[$i]['unformatted'] != $trash_folder) &&
203 ($boxes[$i]['unformatted'] != $sent_folder) &&
204 ($boxes[$i]['unformatted'] != $draft_folder) &&
205 (!in_array('noselect', $boxes[$i]['flags'])) &&
206 ((strtolower($imap_server_type) != 'courier') ||
207 (strtolower($boxes[$i]['unformatted']) != 'inbox.trash'))) {
208 $box = $boxes[$i]['unformatted-dm'];
209 $box2 = str_replace(' ', ' ',
210 imap_utf7_decode_local($boxes[$i]['unformatted-disp']));
211 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
214 echo "</SELECT></TT>\n";
215 echo "<input type=SUBMIT VALUE=\"";
218 echo "</form></td></tr>\n";
220 echo _("No folders found") . "<br><br></td></tr>";
224 html_tag( 'td', ' ', 'left', $color[4] )
228 /** UNSUBSCRIBE FOLDERS **/
229 echo html_tag( 'table', '', 'center', '', 'width="70%" cols="2" cellpadding="4" cellspacing="0" border="0"' ) .
231 html_tag( 'td', '<b>' . _("Unsubscribe") . '/' . _("Subscribe") . '</b>', 'center', $color[9], 'colspan="2"' )
234 html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
236 if ($count_special_folders < count($boxes)) {
237 echo "<FORM ACTION=\"folders_subscribe.php?method=unsub\" METHOD=\"POST\">\n";
238 echo "<TT><SELECT NAME=\"mailbox[]\" multiple size=8>\n";
239 for ($i = 0; $i < count($boxes); $i++
) {
241 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
242 ($boxes[$i]["unformatted"] != $trash_folder) &&
243 ($boxes[$i]["unformatted"] != $sent_folder) &&
244 ($boxes[$i]["unformatted"] != $draft_folder)) {
245 $box = $boxes[$i]["unformatted-dm"];
246 $box2 = str_replace(' ', ' ',
247 imap_utf7_decode_local($boxes[$i]["unformatted-disp"]));
248 echo " <OPTION VALUE=\"$box\">$box2\n";
251 echo "</SELECT></TT><br><br>\n";
252 echo "<input type=SUBMIT VALUE=\"";
253 echo _("Unsubscribe");
255 echo "</FORM></td>\n";
257 echo _("No folders were found to unsubscribe from!") . "</td>";
261 /** SUBSCRIBE TO FOLDERS **/
262 echo html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
263 if(!$no_list_for_subscribe) {
264 $imap_stream = sqimap_login ($username, $key, $imapServerAddress,
266 $boxes_all = sqimap_mailbox_list_all ($imap_stream);
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"]);
286 sqimap_logout($imap_stream);
289 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n";
290 echo "<tt><select name=\"mailbox[]\" multiple size=8>";
292 for ($q = 0; $q < count($box); $q++
) {
293 echo " <OPTION VALUE=\"$box[$q]\">".$box2[$q]."\n";
295 echo "</select></tt><br><br>";
296 echo "<input type=SUBMIT VALUE=\"". _("Subscribe") . "\">\n";
297 echo "</FORM></td></tr></table><BR>\n";
299 echo _("No folders were found to subscribe to!") . "</td></tr></table>";
302 /* don't perform the list action -- this is much faster */
303 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n";
304 echo _("Subscribe to:") . "<br>";
305 echo "<tt><input type=\"text\" name=\"mailbox[]\" size=35>";
306 echo "<INPUT TYPE=SUBMIT VALUE=\"". _("Subscribe") . "\">\n";
307 echo "</FORM></TD></TR></TABLE><BR>\n";
310 do_hook("folders_bottom");
321 sqimap_logout($imapConnection);