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