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="2" 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>";
48 echo html_tag( 'table',
50 html_tag( 'td', $td_str .
51 "<a href=\"../src/left_main.php\" target=left>" . _("refresh folder list") . "</a>" ,
54 'center', '', 'width="100%" cellpadding="4" cellspacing="0" border="0"' ) . "<br>\n";
58 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
59 $boxes = sqimap_mailbox_list($imapConnection);
61 /** CREATING FOLDERS **/
62 echo html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="4" cellspacing="0" border="0"' ) .
64 html_tag( 'td', '<b>' . _("Create Folder") . '</b>', 'center', $color[9] )
67 html_tag( 'td', '', 'center', $color[0] ) .
69 "<FORM NAME=cf ACTION=\"folders_create.php\" METHOD=\"POST\">\n".
70 "<input type=TEXT SIZE=25 NAME=folder_name><BR>\n".
71 _("as a subfolder of").
73 "<TT><SELECT NAME=subfolder>\n";
74 if ($default_sub_of_inbox == false) {
75 echo '<OPTION SELECTED VALUE="">[ '._("None")." ]\n";
77 echo '<OPTION VALUE="">[ '._("None")." ]\n";
80 for ($i = 0; $i < count($boxes); $i++
) {
81 if (!in_array('noinferiors', $boxes[$i]['flags'])) {
82 if ((strtolower($boxes[$i]['unformatted']) == 'inbox') &&
83 $default_sub_of_inbox) {
85 $box = $boxes[$i]['unformatted'];
86 $box2 = str_replace(' ', ' ',
87 imap_utf7_decode_local($boxes[$i]['unformatted-disp']));
88 echo "<OPTION SELECTED VALUE=\"$box\">$box2</option>\n";
90 $box = $boxes[$i]['unformatted'];
91 $box2 = str_replace(' ', ' ',
92 imap_utf7_decode_local($boxes[$i]['unformatted-disp']));
93 if (strtolower($imap_server_type) != 'courier' ||
94 strtolower($box) != "inbox.trash")
95 echo "<OPTION VALUE=\"$box\">$box2</option>\n";
99 echo "</SELECT></TT>\n";
100 if ($show_contain_subfolders_option) {
101 echo "<br><input type=CHECKBOX NAME=\"contain_subs\"> ";
102 echo _("Let this folder contain subfolders");
105 echo "<input type=SUBMIT VALUE=\""._("Create")."\">\n";
106 echo "</FORM></td></tr>\n";
109 html_tag( 'td', ' ', 'left', $color[4] )
112 /** count special folders **/
113 $count_special_folders = 0;
115 if (strtolower($imap_server_type) == "courier" ||
$move_to_trash) {
121 if ($save_as_draft) {
124 for ($p = 0; $p < count($boxes) && $count_special_folders < $num_max; $p++
) {
125 if (strtolower($boxes[$p]['unformatted']) == 'inbox')
126 $count_special_folders++
;
127 else if (strtolower($imap_server_type) == 'courier' &&
128 strtolower($boxes[$p]['unformatted']) == 'inbox.trash')
129 $count_special_folders++
;
130 else if ($boxes[$p]['unformatted'] == $trash_folder && $trash_folder)
131 $count_special_folders++
;
132 else if ($boxes[$p]['unformatted'] == $sent_folder && $sent_folder)
133 $count_special_folders++
;
134 else if ($boxes[$p]['unformatted'] == $draft_folder && $draft_folder)
135 $count_special_folders++
;
139 /** RENAMING FOLDERS **/
141 html_tag( 'td', '<b>' . _("Rename a Folder") . '</b>', 'center', $color[9] )
144 html_tag( 'td', '', 'center', $color[0] );
146 if ($count_special_folders < count($boxes)) {
147 echo "<FORM ACTION=\"folders_rename_getname.php\" METHOD=\"POST\">\n"
148 . "<TT><SELECT NAME=old>\n"
149 . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
150 for ($i = 0; $i < count($boxes); $i++
) {
153 if ((strtolower($boxes[$i]['unformatted']) != 'inbox') &&
154 ($boxes[$i]['unformatted'] != $trash_folder) &&
155 ($boxes[$i]['unformatted'] != $sent_folder) &&
156 ($boxes[$i]['unformatted'] != $draft_folder)) {
157 $box = $boxes[$i]['unformatted-dm'];
159 $box2 = str_replace(' ', ' ',
160 imap_utf7_decode_local($boxes[$i]['unformatted-disp']));
161 if (strtolower($imap_server_type) != 'courier' ||
strtolower($box) != 'inbox.trash') {
162 echo "<OPTION VALUE=\"$box\">$box2</option>\n";
166 echo "</SELECT></TT>\n".
167 "<input type=SUBMIT VALUE=\"".
170 "</FORM></td></tr>\n";
172 echo _("No folders found") . "<br><br></td></tr>";
177 html_tag( 'td', ' ', 'left', $color[4] )
180 /** DELETING FOLDERS **/
182 html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[9] )
185 html_tag( 'td', '', 'center', $color[0] );
187 if ($count_special_folders < count($boxes)) {
188 echo "<FORM ACTION=\"folders_delete.php\" METHOD=\"POST\">\n"
189 . "<TT><SELECT NAME=mailbox>\n"
190 . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
191 for ($i = 0; $i < count($boxes); $i++
) {
193 if ((strtolower($boxes[$i]['unformatted']) != 'inbox') &&
194 ($boxes[$i]['unformatted'] != $trash_folder) &&
195 ($boxes[$i]['unformatted'] != $sent_folder) &&
196 ($boxes[$i]['unformatted'] != $draft_folder) &&
197 (!in_array('noselect', $boxes[$i]['flags'])) &&
198 ((strtolower($imap_server_type) != 'courier') ||
199 (strtolower($boxes[$i]['unformatted']) != 'inbox.trash'))) {
200 $box = $boxes[$i]['unformatted-dm'];
201 $box2 = str_replace(' ', ' ',
202 imap_utf7_decode_local($boxes[$i]['unformatted-disp']));
203 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
206 echo "</SELECT></TT>\n";
207 echo "<input type=SUBMIT VALUE=\"";
210 echo "</form></td></tr>\n";
212 echo _("No folders found") . "<br><br></td></tr>";
216 html_tag( 'td', ' ', 'left', $color[4] )
220 /** UNSUBSCRIBE FOLDERS **/
221 echo html_tag( 'table', '', 'center', '', 'width="70%" cols="2" cellpadding="4" cellspacing="0" border="0"' ) .
223 html_tag( 'td', '<b>' . _("Unsubscribe") . '/' . _("Subscribe") . '</b>', 'center', $color[9], 'colspan="2"' )
226 html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
228 if ($count_special_folders < count($boxes)) {
229 echo "<FORM ACTION=\"folders_subscribe.php?method=unsub\" METHOD=\"POST\">\n";
230 echo "<TT><SELECT NAME=\"mailbox[]\" multiple size=8>\n";
231 for ($i = 0; $i < count($boxes); $i++
) {
233 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
234 ($boxes[$i]["unformatted"] != $trash_folder) &&
235 ($boxes[$i]["unformatted"] != $sent_folder) &&
236 ($boxes[$i]["unformatted"] != $draft_folder)) {
237 $box = $boxes[$i]["unformatted-dm"];
238 $box2 = str_replace(' ', ' ',
239 imap_utf7_decode_local($boxes[$i]["unformatted-disp"]));
240 echo " <OPTION VALUE=\"$box\">$box2\n";
243 echo "</SELECT></TT><br><br>\n";
244 echo "<input type=SUBMIT VALUE=\"";
245 echo _("Unsubscribe");
247 echo "</FORM></td>\n";
249 echo _("No folders were found to unsubscribe from!") . "</td>";
253 /** SUBSCRIBE TO FOLDERS **/
254 echo html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
255 $imap_stream = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 1);
256 $boxes_all = sqimap_mailbox_list_all ($imap_stream);
260 for ($i = 0, $q = 0; $i < count($boxes_all); $i++
) {
262 for ($p = 0; $p < count ($boxes); $p++
) {
263 if ($boxes_all[$i]["unformatted"] == $boxes[$p]["unformatted"]) {
266 } else if ($boxes_all[$i]["unformatted-dm"] == $folder_prefix) {
270 if ($use_folder == true) {
271 $box[$q] = $boxes_all[$i]["unformatted-dm"];
272 $box2[$q] = imap_utf7_decode_local($boxes_all[$i]["unformatted-disp"]);
276 sqimap_logout($imap_stream);
279 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n";
280 echo "<tt><select name=\"mailbox[]\" multiple size=8>";
282 for ($q = 0; $q < count($box); $q++
) {
283 echo " <OPTION VALUE=\"$box[$q]\">".$box2[$q]."\n";
285 echo "</select></tt><br><br>";
286 echo "<input type=SUBMIT VALUE=\"". _("Subscribe") . "\">\n";
287 echo "</FORM></td></tr></table><BR>\n";
289 echo _("No folders were found to subscribe to!") . "</td></tr></table>";
292 do_hook("folders_bottom");
303 sqimap_logout($imapConnection);