submitted a patch from Andreas Dahl to make folder deleting work with
[squirrelmail.git] / src / folders.php
1 <?php
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.
11 **/
12
13 session_start();
14
15 if (!isset($config_php))
16 include("../config/config.php");
17 if (!isset($strings_php))
18 include("../functions/strings.php");
19 if (!isset($page_header_php))
20 include("../functions/page_header.php");
21 if (!isset($imap_php))
22 include("../functions/imap.php");
23 if (!isset($array_php))
24 include("../functions/array.php");
25 if (!isset($plugin_php))
26 include("../functions/plugin.php");
27
28 include("../src/load_prefs.php");
29
30 displayPageHeader($color, "None");
31
32 echo "<br>";
33 echo "<TABLE WIDTH=95% COLS=1 ALIGN=CENTER>\n";
34 echo " <TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><b>\n";
35 echo _("Folders");
36 echo " </b></TD></TR>\n";
37 echo "</TABLE>\n";
38
39 if ($success) {
40 echo "<table width=100% align=center cellpadding=3 cellspacing=0 border=0>\n";
41 echo " <tr><td><center>\n";
42 if ($success == "subscribe") {
43 echo "<b>" . _("Subscribed successfully!") . "</b><br>";
44 } else if ($success == "unsubscribe") {
45 echo "<b>" . _("Unsubscribed successfully!") . "</b><br>";
46 } else if ($success == "delete") {
47 echo "<b>" . _("Deleted folder successfully!") . "</b><br>";
48 } else if ($success == "create") {
49 echo "<b>" . _("Created folder successfully!") . "</b><br>";
50 } else if ($success == "rename") {
51 echo "<b>" . _("Renamed successfully!") . "</b><br>";
52 }
53 echo " <a href=\"../src/left_main.php\" target=left>" . _("refresh folder list") . "</a>";
54 echo " </center></td></tr>\n";
55 echo "</table><br>\n";
56 }
57 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
58 $boxes = sqimap_mailbox_list($imapConnection);
59
60 /** Cyrus Folder Options**/
61 //Creates the Sent and Trash folder
62 if (($sent_create == "true") || ($trash_create == "true")) {
63 if ($sent_create == "true") {
64 sqimap_mailbox_create ($imapConnection, $sent_folder, "");
65 }
66 if ($trash_create == "true") {
67 sqimap_mailbox_create ($imapConnection, $trash_folder, "");
68 }
69 echo "<BR><BR><CENTER><b>";
70 echo _("Mailboxes Created Successfully!");
71 echo "<BR><A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>";
72 echo _("Click here");
73 echo "</A> ";
74 echo _("to continue.");
75 echo "</CENTER>";
76 echo "</BODY></HTML>";
77
78 sqimap_logout($imapConnection);
79 exit;
80 }
81
82 //display form option for creating Sent and Trash folder
83 if ($imap_server_type == "cyrus") {
84 if ((!sqimap_mailbox_exists ($imapConnection, $sent_folder)) || (!sqimap_mailbox_exists ($imapConnection, $trash_folder))) {
85 echo "<TABLE WIDTH=70% COLS=1 ALIGN=CENTER>\n";
86 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><B>";
87 echo _("Special Folder Options");
88 echo "</B></TD></TR>";
89 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>";
90 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.");
91 echo "<FORM ACTION=\"folders.php\" METHOD=\"POST\">\n";
92 if (!sqimap_mailbox_exists ($imapConnection, $sent_folder)) {
93 echo _("Create Sent") . "<INPUT TYPE=checkbox NAME=sent_create value=true><br>\n";
94 }
95 if (!sqimap_mailbox_exists ($imapConnection, $trash_folder)){
96 echo _("Create Trash") . "<INPUT TYPE=checkbox NAME=trash_create value=true><br>\n";
97 echo "<INPUT TYPE=submit VALUE=Create>";
98 }
99 }
100 echo "</FORM></TD></TR></TABLE>n";
101 }
102
103 /** DELETING FOLDERS **/
104 echo "<TABLE WIDTH=70% COLS=1 ALIGN=CENTER cellpadding=2 cellspacing=0 border=0>\n";
105 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER>";
106 echo _("Delete Folder");
107 echo "</TD></TR>";
108 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>";
109
110 $count_special_folders = 0;
111 $num_max = 1;
112 if (strtolower($imap_server_type) == "courier" || $move_to_trash)
113 $num_max++;
114 if ($move_to_sent)
115 $num_max++;
116
117 for ($p = 0; $p < count($boxes) && $count_special_folders < $num_max; $p++) {
118 if (strtolower($boxes[$p]["unformatted"]) == "inbox")
119 $count_special_folders++;
120 else if (strtolower($imap_server_type) == "courier" &&
121 strtolower($boxes[$p]["unformatted"]) == "inbox.trash")
122 $count_special_folders++;
123 else if ($boxes[$p]["unformatted"] == $trash_folder && $trash_folder)
124 $count_special_folders++;
125 }
126
127 if ($count_special_folders < count($boxes)) {
128 echo "<FORM ACTION=\"folders_delete.php\" METHOD=\"POST\">\n";
129 echo "<TT><SELECT NAME=mailbox>\n";
130 for ($i = 0; $i < count($boxes); $i++) {
131 $use_folder = true;
132 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
133 ($boxes[$i]["unformatted"] != $trash_folder) &&
134 ($boxes[$i]["unformatted"] != $sent_folder) &&
135 (strtolower($imap_server_type) != "courier" ||
136 strtolower($boxes[$i]["unformatted"]) != "inbox.trash"))
137 {
138 $box = $boxes[$i]["unformatted-dm"];
139 $box2 = replace_spaces($boxes[$i]["formatted"]);
140 echo " <OPTION VALUE=\"$box\">$box2\n";
141 }
142 }
143 echo "</SELECT></TT>\n";
144 echo "<INPUT TYPE=SUBMIT VALUE=\"";
145 echo _("Delete");
146 echo "\">\n";
147 echo "</FORM></TD></TR>\n";
148 } else {
149 echo _("No mailboxes found") . "<br><br></td><tr>";
150 }
151
152 echo "<tr><td bgcolor=\"$color[4]\">&nbsp;</td></tr>\n";
153
154 /** CREATING FOLDERS **/
155 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER>";
156 echo _("Create Folder");
157 echo "</TD></TR>";
158 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>";
159 echo "<FORM NAME=cf ACTION=\"folders_create.php\" METHOD=\"POST\">\n";
160 echo "<INPUT TYPE=TEXT SIZE=25 NAME=folder_name><BR>\n";
161 echo _("as a subfolder of");
162 echo "<BR>";
163 echo "<TT><SELECT NAME=subfolder>\n";
164 if (strtolower($imap_server_type) != "courier"){
165 if ($default_sub_of_inbox == false)
166 echo "<OPTION SELECTED>[ None ]\n";
167 else
168 echo "<OPTION>[ None ]\n";
169 }
170
171 for ($i = 0; $i < count($boxes); $i++) {
172 if (count($boxes[$i]["flags"]) > 0) {
173 $noinf = false;
174 for ($j = 0; $j < count($boxes[$i]["flags"]); $j++) {
175 if ($boxes[$i]["flags"][$j] == "noinferiors") {
176 $noinf = true;
177 continue;
178 }
179 }
180 if ($noinf == false) {
181 if ((strtolower($boxes[$i]["unformatted"]) == "inbox") && ($default_sub_of_inbox == true)) {
182 $box = $boxes[$i]["unformatted"];
183 $box2 = replace_spaces($boxes[$i]["formatted"]);
184 echo "<OPTION SELECTED VALUE=\"$box\">$box2\n";
185 } else {
186 $box = $boxes[$i]["unformatted"];
187 $box2 = replace_spaces($boxes[$i]["formatted"]);
188 if (strtolower($imap_server_type) != "courier" ||
189 strtolower($box) != "inbox.trash")
190 echo "<OPTION VALUE=\"$box\">$box2\n";
191 }
192 }
193 } else {
194 if ((strtolower($boxes[$i]["unformatted"]) == "inbox") && ($default_sub_of_inbox == true)) {
195 $box = $boxes[$i]["unformatted"];
196 $box2 = replace_spaces($boxes[$i]["formatted"]);
197 echo "<OPTION SELECTED VALUE=\"$box\">$box2\n";
198 } else {
199 $box = $boxes[$i]["unformatted"];
200 $box2 = replace_spaces($boxes[$i]["formatted"]);
201 if (strtolower($imap_server_type) != "courier" ||
202 strtolower($box) != "inbox.trash")
203 echo "<OPTION VALUE=\"$box\">$box2\n";
204 }
205 }
206 }
207 echo "</SELECT></TT><BR>\n";
208 if ($show_contain_subfolders_option) {
209 echo "<INPUT TYPE=CHECKBOX NAME=\"contain_subs\"> &nbsp;";
210 echo _("Let this folder contain subfolders");
211 echo "<BR>";
212 }
213 echo "<INPUT TYPE=SUBMIT VALUE=\""._("Create")."\">\n";
214 echo "</FORM></TD></TR>\n";
215
216 echo "<tr><td bgcolor=\"$color[4]\">&nbsp;</td></tr>\n";
217
218 /** RENAMING FOLDERS **/
219 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER>";
220 echo _("Rename a Folder");
221 echo "</TD></TR>";
222 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>";
223 if ($count_special_folders < count($boxes)) {
224 echo "<FORM ACTION=\"folders_rename_getname.php\" METHOD=\"POST\">\n";
225 echo "<TT><SELECT NAME=old>\n";
226 for ($i = 0; $i < count($boxes); $i++) {
227 $use_folder = true;
228
229 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
230 ($boxes[$i]["unformatted"] != $trash_folder) &&
231 ($boxes[$i]["unformatted"] != $sent_folder))
232 {
233 $box = $boxes[$i]["unformatted-dm"];
234 $box2 = replace_spaces($boxes[$i]["formatted"]);
235 echo " <OPTION VALUE=\"$box\">$box2\n";
236 }
237 }
238 echo "</SELECT></TT>\n";
239 echo "<INPUT TYPE=SUBMIT VALUE=\"";
240 echo _("Rename");
241 echo "\">\n";
242 echo "</FORM></TD></TR>\n";
243 } else {
244 echo _("No mailboxes found") . "<br><br></td></tr>";
245 }
246 $boxes_sub = $boxes;
247
248 echo "<tr><td bgcolor=\"$color[4]\">&nbsp;</td></tr></table>\n";
249
250 /** UNSUBSCRIBE FOLDERS **/
251 echo "<TABLE WIDTH=70% COLS=1 ALIGN=CENTER cellpadding=2 cellspacing=0 border=0>\n";
252 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER colspan=3>";
253 echo _("Unsubscribe") . "/" . _("Subscribe");
254 echo "</TD></TR>";
255 echo "<TR><TD BGCOLOR=\"$color[0]\" width=49% ALIGN=CENTER>";
256 if ($count_special_folders < count($boxes)) {
257 echo "<FORM ACTION=\"folders_subscribe.php?method=unsub\" METHOD=\"POST\">\n";
258 echo "<TT><SELECT NAME=mailbox[] multiple size=8>\n";
259 for ($i = 0; $i < count($boxes); $i++) {
260 $use_folder = true;
261 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
262 ($boxes[$i]["unformatted"] != $trash_folder) &&
263 ($boxes[$i]["unformatted"] != $sent_folder))
264 {
265 $box = $boxes[$i]["unformatted-dm"];
266 $box2 = replace_spaces($boxes[$i]["formatted"]);
267 echo " <OPTION VALUE=\"$box\">$box2\n";
268 }
269 }
270 echo "</SELECT></TT><br>\n";
271 echo "<INPUT TYPE=SUBMIT VALUE=\"";
272 echo _("Unsubscribe");
273 echo "\">\n";
274 echo "</FORM></TD>\n";
275 } else {
276 echo _("No folders were found to unsubscribe from!") . "</td>";
277 }
278 $boxes_sub = $boxes;
279
280 echo "<td bgcolor=\"$color[9]\" width=2%>&nbsp;</td>";
281
282 /** SUBSCRIBE TO FOLDERS **/
283 echo "<TD BGCOLOR=\"$color[0]\" widtn=49% ALIGN=CENTER>";
284 $imap_stream = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 1);
285 $boxes_all = sqimap_mailbox_list_all ($imap_stream);
286
287 $box = "";
288 $box2 = "";
289 for ($i = 0, $q = 0; $i < count($boxes_all); $i++) {
290 $use_folder = true;
291 for ($p = 0; $p < count ($boxes); $p++) {
292 if ($boxes_all[$i]["unformatted"] == $boxes[$p]["unformatted"]) {
293 $use_folder = false;
294 continue;
295 } else if ($boxes_all[$i]["unformatted-dm"] == $folder_prefix) {
296 $use_folder = false;
297 }
298 }
299 if ($use_folder == true) {
300 $box[$q] = $boxes_all[$i]["unformatted-dm"];
301 $box2[$q] = $boxes_all[$i]["formatted"];
302 $q++;
303 }
304 }
305 sqimap_logout($imap_stream);
306
307 if ($box && $box2) {
308 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n";
309 echo "<tt><select name=mailbox[] multiple size=8>";
310
311 for ($q = 0; $q < count($box); $q++) {
312 echo " <OPTION VALUE=\"$box[$q]\">".$box2[$q]."\n";
313 }
314 echo "</select></tt><br>";
315 echo "<INPUT TYPE=SUBMIT VALUE=\"". _("Subscribe") . "\">\n";
316 echo "</FORM></TD></TR></TABLE><BR>\n";
317 } else {
318 echo _("No folders were found to subscribe to!") . "</td></tr></table>";
319 }
320
321 do_hook("folders_bottom");
322 sqimap_logout($imapConnection);
323 ?>
324 </BODY></HTML>