* To reduce on errors, I moved the includes for config.php and strings.php
[squirrelmail.git] / src / folders.php
CommitLineData
59177427 1<?php
ef870322 2 /**
3 ** folders.php
4 **
5 ** Copyright (c) 1999-2000 The SquirrelMail development team
6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
7 **
8 ** Handles all interaction between the user and the other folder
9 ** scripts which do most of the work. Also handles the Special
10 ** Folders.
245a6892 11 **
12 ** $Id$
ef870322 13 **/
14
f740c049 15 include('../src/validate.php');
f740c049 16 include("../functions/page_header.php");
17 include("../functions/imap.php");
18 include("../functions/array.php");
19 include("../functions/plugin.php");
d3cdb279 20 include("../src/load_prefs.php");
21
1181f3bf 22 displayPageHeader($color, _("None"));
aa42fbfb 23
1195c340 24 echo "<br>";
25 echo "<TABLE WIDTH=95% COLS=1 ALIGN=CENTER>\n";
e9f8ea4e 26 echo " <TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><b>\n";
036a8a9d 27 echo _("Folders");
e9f8ea4e 28 echo " </b></TD></TR>\n";
aa42fbfb 29 echo "</TABLE>\n";
30
245a6892 31 if ((isset($success) && $success) ||
32 (isset($sent_create) && $sent_create == "true") ||
33 (isset($trash_create) && $trash_create == "true")) {
1195c340 34 echo "<table width=100% align=center cellpadding=3 cellspacing=0 border=0>\n";
e9f8ea4e 35 echo " <tr><td><center>\n";
1195c340 36 if ($success == "subscribe") {
37 echo "<b>" . _("Subscribed successfully!") . "</b><br>";
38 } else if ($success == "unsubscribe") {
39 echo "<b>" . _("Unsubscribed successfully!") . "</b><br>";
40 } else if ($success == "delete") {
41 echo "<b>" . _("Deleted folder successfully!") . "</b><br>";
42 } else if ($success == "create") {
43 echo "<b>" . _("Created folder successfully!") . "</b><br>";
44 } else if ($success == "rename") {
45 echo "<b>" . _("Renamed successfully!") . "</b><br>";
0e743004 46 } else if (($sent_create == "true") || ($trash_create == "true")) {
1f936c98 47 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
0e743004 48 if ($sent_create == "true") {
49 sqimap_mailbox_create ($imapConnection, $sent_folder, "");
50 }
51 if ($trash_create == "true") {
52 sqimap_mailbox_create ($imapConnection, $trash_folder, "");
53 }
1f936c98 54 sqimap_logout($imapConnection);
0e743004 55 echo _("Folders created successfully!");
1195c340 56 }
0e743004 57
e9f8ea4e 58 echo " <a href=\"../src/left_main.php\" target=left>" . _("refresh folder list") . "</a>";
1195c340 59 echo " </center></td></tr>\n";
60 echo "</table><br>\n";
61 }
e1469126 62 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
813eba2f 63 $boxes = sqimap_mailbox_list($imapConnection);
60573cd9 64
0e743004 65 //display form option for creating Sent and Trash folder
66 if ($imap_server_type == "cyrus" && ($sent_folder != "none" || $trash_folder != "none")) {
5bdd7223 67 if ((!sqimap_mailbox_exists ($imapConnection, $sent_folder)) ||
68 (!sqimap_mailbox_exists ($imapConnection, $trash_folder))) {
0e743004 69 echo "<TABLE WIDTH=70% COLS=1 ALIGN=CENTER cellpadding=2 cellspacing=0 border=0>\n";
70 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><B>";
71 echo _("Special Folder Options");
72 echo "</B></TD></TR>";
73 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>";
74 echo _("In order for SquirrelMail to provide the full set of options you need to create the special folders listed below. Just click the check box and hit the create button.");
75 echo "<FORM ACTION=\"folders.php\" METHOD=\"POST\">\n";
76 if (!sqimap_mailbox_exists ($imapConnection, $sent_folder) && $sent_folder != "none") {
77 echo _("Create Sent") . "<INPUT TYPE=checkbox NAME=sent_create value=true><br>\n";
78 }
79 if (!sqimap_mailbox_exists ($imapConnection, $trash_folder) && $trash_folder != "none"){
80 echo _("Create Trash") . "<INPUT TYPE=checkbox NAME=trash_create value=true><br>\n";
81 }
32f4685b 82 echo "<INPUT TYPE=submit VALUE="._("Create").">";
0e743004 83 echo "</FORM></TD></TR></TABLE><br>";
90790bd4 84 }
90790bd4 85 }
86
60573cd9 87 /** DELETING FOLDERS **/
1195c340 88 echo "<TABLE WIDTH=70% COLS=1 ALIGN=CENTER cellpadding=2 cellspacing=0 border=0>\n";
32f4685b 89 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><B>";
036a8a9d 90 echo _("Delete Folder");
32f4685b 91 echo "</B></TD></TR>";
1195c340 92 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>";
1e0628fb 93
225ce239 94 $count_special_folders = 0;
2c1dc652 95 $num_max = 1;
96 if (strtolower($imap_server_type) == "courier" || $move_to_trash)
97 $num_max++;
98 if ($move_to_sent)
99 $num_max++;
4bbba0d8 100
2c1dc652 101 for ($p = 0; $p < count($boxes) && $count_special_folders < $num_max; $p++) {
c36ed9cf 102 if (strtolower($boxes[$p]["unformatted"]) == "inbox")
1e0628fb 103 $count_special_folders++;
2c1dc652 104 else if (strtolower($imap_server_type) == "courier" &&
5bdd7223 105 strtolower($boxes[$p]["unformatted"]) == "inbox.trash")
1e0628fb 106 $count_special_folders++;
5bdd7223 107 else if ($boxes[$p]["unformatted"] == $trash_folder && $trash_folder)
1e0628fb 108 $count_special_folders++;
b93e186d 109 else if ($boxes[$p]["unformatted"] == $sent_folder && $sent_folder)
110 $count_special_folders++;
1e0628fb 111 }
225ce239 112
113 if ($count_special_folders < count($boxes)) {
9f2215a1 114 echo "<FORM ACTION=\"folders_delete.php\" METHOD=\"POST\">\n";
225ce239 115 echo "<TT><SELECT NAME=mailbox>\n";
116 for ($i = 0; $i < count($boxes); $i++) {
117 $use_folder = true;
5bdd7223 118 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
119 ($boxes[$i]["unformatted"] != $trash_folder) &&
120 ($boxes[$i]["unformatted"] != $sent_folder) &&
121 (strtolower($imap_server_type) != "courier" ||
122 strtolower($boxes[$i]["unformatted"]) != "inbox.trash"))
123 {
124 $box = $boxes[$i]["unformatted-dm"];
0cd84d75 125 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]["unformatted-disp"]);
5bdd7223 126 echo " <OPTION VALUE=\"$box\">$box2\n";
127 }
60573cd9 128 }
225ce239 129 echo "</SELECT></TT>\n";
130 echo "<INPUT TYPE=SUBMIT VALUE=\"";
131 echo _("Delete");
132 echo "\">\n";
1195c340 133 echo "</FORM></TD></TR>\n";
225ce239 134 } else {
0e743004 135 echo _("No folders found") . "<br><br></td><tr>";
60573cd9 136 }
7ce342dc 137
1195c340 138 echo "<tr><td bgcolor=\"$color[4]\">&nbsp;</td></tr>\n";
60573cd9 139
140 /** CREATING FOLDERS **/
32f4685b 141 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><B>";
036a8a9d 142 echo _("Create Folder");
32f4685b 143 echo "</B></TD></TR>";
1195c340 144 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>";
d7d3c4d4 145 echo "<FORM NAME=cf ACTION=\"folders_create.php\" METHOD=\"POST\">\n";
907165ca 146 echo "<INPUT TYPE=TEXT SIZE=25 NAME=folder_name><BR>\n";
036a8a9d 147 echo _("as a subfolder of");
aae41ae9 148 echo "<BR>";
149 echo "<TT><SELECT NAME=subfolder>\n";
2c1dc652 150 if (strtolower($imap_server_type) != "courier"){
151 if ($default_sub_of_inbox == false)
4c75ba81 152 echo '<OPTION SELECTED VALUE="">[ '._("None")." ]\n";
2c1dc652 153 else
4c75ba81 154 echo '<OPTION VALUE="">[ '._("None")." ]\n";
2c1dc652 155 }
d92b6f31 156
7ce342dc 157 for ($i = 0; $i < count($boxes); $i++) {
e54e0b89 158 if (!in_array('noinferiors', $boxes[$i]['flags'])) {
1e0628fb 159 if ((strtolower($boxes[$i]["unformatted"]) == "inbox") && ($default_sub_of_inbox == true)) {
1f97f59a 160 $box = $boxes[$i]["unformatted"];
0cd84d75 161 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]["unformatted-disp"]);
1f97f59a 162 echo "<OPTION SELECTED VALUE=\"$box\">$box2\n";
163 } else {
164 $box = $boxes[$i]["unformatted"];
0cd84d75 165 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]["unformatted-disp"]);
2c1dc652 166 if (strtolower($imap_server_type) != "courier" ||
167 strtolower($box) != "inbox.trash")
168 echo "<OPTION VALUE=\"$box\">$box2\n";
1f97f59a 169 }
170 }
60573cd9 171 }
7ce342dc 172 echo "</SELECT></TT><BR>\n";
813eba2f 173 if ($show_contain_subfolders_option) {
aae41ae9 174 echo "<INPUT TYPE=CHECKBOX NAME=\"contain_subs\"> &nbsp;";
036a8a9d 175 echo _("Let this folder contain subfolders");
aae41ae9 176 echo "<BR>";
813eba2f 177 }
88c81396 178 echo "<INPUT TYPE=SUBMIT VALUE=\""._("Create")."\">\n";
1195c340 179 echo "</FORM></TD></TR>\n";
180
181 echo "<tr><td bgcolor=\"$color[4]\">&nbsp;</td></tr>\n";
60573cd9 182
183 /** RENAMING FOLDERS **/
32f4685b 184 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><B>";
036a8a9d 185 echo _("Rename a Folder");
32f4685b 186 echo "</B></TD></TR>";
1195c340 187 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>";
225ce239 188 if ($count_special_folders < count($boxes)) {
9f2215a1 189 echo "<FORM ACTION=\"folders_rename_getname.php\" METHOD=\"POST\">\n";
225ce239 190 echo "<TT><SELECT NAME=old>\n";
191 for ($i = 0; $i < count($boxes); $i++) {
192 $use_folder = true;
1e0628fb 193
5bdd7223 194 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
195 ($boxes[$i]["unformatted"] != $trash_folder) &&
196 ($boxes[$i]["unformatted"] != $sent_folder))
197 {
198 $box = $boxes[$i]["unformatted-dm"];
0cd84d75 199 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]["unformatted-disp"]);
5bdd7223 200 if (strtolower($imap_server_type) != "courier" || strtolower($box) != "inbox.trash")
201 echo "<OPTION VALUE=\"$box\">$box2\n";
202 }
60573cd9 203 }
225ce239 204 echo "</SELECT></TT>\n";
205 echo "<INPUT TYPE=SUBMIT VALUE=\"";
206 echo _("Rename");
207 echo "\">\n";
37578167 208 echo "</FORM></TD></TR>\n";
209 } else {
0e743004 210 echo _("No folders found") . "<br><br></td></tr>";
37578167 211 }
212 $boxes_sub = $boxes;
1195c340 213
e9f8ea4e 214 echo "<tr><td bgcolor=\"$color[4]\">&nbsp;</td></tr></table>\n";
37578167 215
216 /** UNSUBSCRIBE FOLDERS **/
e9f8ea4e 217 echo "<TABLE WIDTH=70% COLS=1 ALIGN=CENTER cellpadding=2 cellspacing=0 border=0>\n";
32f4685b 218 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER colspan=3><B>";
88c81396 219 echo _("Unsubscribe") . "/" . _("Subscribe");
32f4685b 220 echo "</B></TD></TR>";
e9f8ea4e 221 echo "<TR><TD BGCOLOR=\"$color[0]\" width=49% ALIGN=CENTER>";
37578167 222 if ($count_special_folders < count($boxes)) {
9f2215a1 223 echo "<FORM ACTION=\"folders_subscribe.php?method=unsub\" METHOD=\"POST\">\n";
e9f8ea4e 224 echo "<TT><SELECT NAME=mailbox[] multiple size=8>\n";
37578167 225 for ($i = 0; $i < count($boxes); $i++) {
226 $use_folder = true;
5bdd7223 227 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
228 ($boxes[$i]["unformatted"] != $trash_folder) &&
229 ($boxes[$i]["unformatted"] != $sent_folder))
230 {
231 $box = $boxes[$i]["unformatted-dm"];
0cd84d75 232 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]["unformatted-disp"]);
5bdd7223 233 echo " <OPTION VALUE=\"$box\">$box2\n";
234 }
37578167 235 }
e9f8ea4e 236 echo "</SELECT></TT><br>\n";
37578167 237 echo "<INPUT TYPE=SUBMIT VALUE=\"";
238 echo _("Unsubscribe");
239 echo "\">\n";
e9f8ea4e 240 echo "</FORM></TD>\n";
37578167 241 } else {
e9f8ea4e 242 echo _("No folders were found to unsubscribe from!") . "</td>";
37578167 243 }
244 $boxes_sub = $boxes;
e9f8ea4e 245
246 echo "<td bgcolor=\"$color[9]\" width=2%>&nbsp;</td>";
37578167 247
248 /** SUBSCRIBE TO FOLDERS **/
e9f8ea4e 249 echo "<TD BGCOLOR=\"$color[0]\" widtn=49% ALIGN=CENTER>";
250 $imap_stream = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 1);
251 $boxes_all = sqimap_mailbox_list_all ($imap_stream);
252
5bdd7223 253 $box = "";
254 $box2 = "";
255 for ($i = 0, $q = 0; $i < count($boxes_all); $i++) {
256 $use_folder = true;
257 for ($p = 0; $p < count ($boxes); $p++) {
258 if ($boxes_all[$i]["unformatted"] == $boxes[$p]["unformatted"]) {
259 $use_folder = false;
260 continue;
261 } else if ($boxes_all[$i]["unformatted-dm"] == $folder_prefix) {
262 $use_folder = false;
263 }
32b3d87e 264 }
5bdd7223 265 if ($use_folder == true) {
266 $box[$q] = $boxes_all[$i]["unformatted-dm"];
2752bb16 267 $box2[$q] = $boxes_all[$i]["unformatted-disp"];
5bdd7223 268 $q++;
269 }
270 }
271 sqimap_logout($imap_stream);
e9f8ea4e 272
273 if ($box && $box2) {
274 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n";
275 echo "<tt><select name=mailbox[] multiple size=8>";
276
277 for ($q = 0; $q < count($box); $q++) {
278 echo " <OPTION VALUE=\"$box[$q]\">".$box2[$q]."\n";
279 }
280 echo "</select></tt><br>";
281 echo "<INPUT TYPE=SUBMIT VALUE=\"". _("Subscribe") . "\">\n";
225ce239 282 echo "</FORM></TD></TR></TABLE><BR>\n";
283 } else {
e9f8ea4e 284 echo _("No folders were found to subscribe to!") . "</td></tr></table>";
60573cd9 285 }
60573cd9 286
d7d3c4d4 287 do_hook("folders_bottom");
1195c340 288 sqimap_logout($imapConnection);
aa42fbfb 289?>
2aa12d5e 290</BODY></HTML>