squirrelmail-Bugs-488332
[squirrelmail.git] / src / folders.php
CommitLineData
59177427 1<?php
895905c0 2
35586184 3/**
4 * folders.php
5 *
6 * Copyright (c) 1999-2001 The Squirrelmail Development Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Handles all interaction between the user and the other folder
10 * scripts which do most of the work. Also handles the Special
11 * Folders.
12 *
13 * $Id$
14 */
15
16/*****************************************************************/
17/*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/
18/*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/
19/*** + Base level indent should begin at left margin, as ***/
20/*** the require_once below looks. ***/
21/*** + All identation should consist of four space blocks ***/
22/*** + Tab characters are evil. ***/
23/*** + all comments should use "slash-star ... star-slash" ***/
24/*** style -- no pound characters, no slash-slash style ***/
25/*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/
26/*** ALWAYS USE { AND } CHARACTERS!!! ***/
27/*** + Please use ' instead of ", when possible. Note " ***/
28/*** should always be used in _( ) function calls. ***/
29/*** Thank you for your help making the SM code more readable. ***/
30/*****************************************************************/
31
32require_once('../src/validate.php');
33require_once('../functions/imap.php');
34require_once('../functions/array.php');
35require_once('../functions/plugin.php');
d3cdb279 36
2d367c68 37 displayPageHeader($color, 'None');
aa42fbfb 38
e7db48af 39?>
40
e7db48af 41<br>
42<table bgcolor="<?php echo $color[0] ?>" width="95%" align="center" cellpadding="2" cellspacing="0" border="0">
43<tr><td align="center">
44
45 <b><?php echo _("Folders"); ?></b>
46
47 <table width="100%" border="0" cellpadding="5" cellspacing="0">
48 <tr><td bgcolor="<?php echo $color[4] ?>" align="center">
49
50<?php
aa42fbfb 51
245a6892 52 if ((isset($success) && $success) ||
53 (isset($sent_create) && $sent_create == "true") ||
54 (isset($trash_create) && $trash_create == "true")) {
e7db48af 55 echo "<table width=100% align=center cellpadding=2 cellspacing=0 border=0>\n";
56 echo " <tr><td align=center>\n";
1195c340 57 if ($success == "subscribe") {
58 echo "<b>" . _("Subscribed successfully!") . "</b><br>";
59 } else if ($success == "unsubscribe") {
60 echo "<b>" . _("Unsubscribed successfully!") . "</b><br>";
61 } else if ($success == "delete") {
62 echo "<b>" . _("Deleted folder successfully!") . "</b><br>";
63 } else if ($success == "create") {
64 echo "<b>" . _("Created folder successfully!") . "</b><br>";
65 } else if ($success == "rename") {
66 echo "<b>" . _("Renamed successfully!") . "</b><br>";
67 }
0e743004 68
e9f8ea4e 69 echo " <a href=\"../src/left_main.php\" target=left>" . _("refresh folder list") . "</a>";
e7db48af 70 echo " </td></tr>\n";
1195c340 71 echo "</table><br>\n";
72 }
e1469126 73 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
813eba2f 74 $boxes = sqimap_mailbox_list($imapConnection);
60573cd9 75
76 /** DELETING FOLDERS **/
1195c340 77 echo "<TABLE WIDTH=70% COLS=1 ALIGN=CENTER cellpadding=2 cellspacing=0 border=0>\n";
32f4685b 78 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><B>";
036a8a9d 79 echo _("Delete Folder");
32f4685b 80 echo "</B></TD></TR>";
1195c340 81 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>";
1e0628fb 82
225ce239 83 $count_special_folders = 0;
2c1dc652 84 $num_max = 1;
85 if (strtolower($imap_server_type) == "courier" || $move_to_trash)
86 $num_max++;
87 if ($move_to_sent)
88 $num_max++;
1d38b94b 89 if ($save_as_draft)
90 $num_max++;
4bbba0d8 91
2c1dc652 92 for ($p = 0; $p < count($boxes) && $count_special_folders < $num_max; $p++) {
c36ed9cf 93 if (strtolower($boxes[$p]["unformatted"]) == "inbox")
1e0628fb 94 $count_special_folders++;
2c1dc652 95 else if (strtolower($imap_server_type) == "courier" &&
5bdd7223 96 strtolower($boxes[$p]["unformatted"]) == "inbox.trash")
1e0628fb 97 $count_special_folders++;
5bdd7223 98 else if ($boxes[$p]["unformatted"] == $trash_folder && $trash_folder)
1e0628fb 99 $count_special_folders++;
b93e186d 100 else if ($boxes[$p]["unformatted"] == $sent_folder && $sent_folder)
101 $count_special_folders++;
1d38b94b 102 else if ($boxes[$p]["unformatted"] == $draft_folder && $draft_folder)
e38807da 103 $count_special_folders++;
1e0628fb 104 }
225ce239 105
106 if ($count_special_folders < count($boxes)) {
9f2215a1 107 echo "<FORM ACTION=\"folders_delete.php\" METHOD=\"POST\">\n";
225ce239 108 echo "<TT><SELECT NAME=mailbox>\n";
109 for ($i = 0; $i < count($boxes); $i++) {
110 $use_folder = true;
5bdd7223 111 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
112 ($boxes[$i]["unformatted"] != $trash_folder) &&
113 ($boxes[$i]["unformatted"] != $sent_folder) &&
1d38b94b 114 ($boxes[$i]["unformatted"] != $draft_folder) &&
5bdd7223 115 (strtolower($imap_server_type) != "courier" ||
116 strtolower($boxes[$i]["unformatted"]) != "inbox.trash"))
117 {
118 $box = $boxes[$i]["unformatted-dm"];
0cd84d75 119 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]["unformatted-disp"]);
5bdd7223 120 echo " <OPTION VALUE=\"$box\">$box2\n";
121 }
60573cd9 122 }
225ce239 123 echo "</SELECT></TT>\n";
124 echo "<INPUT TYPE=SUBMIT VALUE=\"";
125 echo _("Delete");
126 echo "\">\n";
1195c340 127 echo "</FORM></TD></TR>\n";
225ce239 128 } else {
0e743004 129 echo _("No folders found") . "<br><br></td><tr>";
60573cd9 130 }
7ce342dc 131
1195c340 132 echo "<tr><td bgcolor=\"$color[4]\">&nbsp;</td></tr>\n";
60573cd9 133
134 /** CREATING FOLDERS **/
32f4685b 135 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><B>";
036a8a9d 136 echo _("Create Folder");
32f4685b 137 echo "</B></TD></TR>";
1195c340 138 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>";
d7d3c4d4 139 echo "<FORM NAME=cf ACTION=\"folders_create.php\" METHOD=\"POST\">\n";
907165ca 140 echo "<INPUT TYPE=TEXT SIZE=25 NAME=folder_name><BR>\n";
036a8a9d 141 echo _("as a subfolder of");
aae41ae9 142 echo "<BR>";
143 echo "<TT><SELECT NAME=subfolder>\n";
2c1dc652 144 if (strtolower($imap_server_type) != "courier"){
145 if ($default_sub_of_inbox == false)
4c75ba81 146 echo '<OPTION SELECTED VALUE="">[ '._("None")." ]\n";
2c1dc652 147 else
4c75ba81 148 echo '<OPTION VALUE="">[ '._("None")." ]\n";
2c1dc652 149 }
d92b6f31 150
7ce342dc 151 for ($i = 0; $i < count($boxes); $i++) {
e54e0b89 152 if (!in_array('noinferiors', $boxes[$i]['flags'])) {
1e0628fb 153 if ((strtolower($boxes[$i]["unformatted"]) == "inbox") && ($default_sub_of_inbox == true)) {
1f97f59a 154 $box = $boxes[$i]["unformatted"];
0cd84d75 155 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]["unformatted-disp"]);
1f97f59a 156 echo "<OPTION SELECTED VALUE=\"$box\">$box2\n";
157 } else {
158 $box = $boxes[$i]["unformatted"];
0cd84d75 159 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]["unformatted-disp"]);
2c1dc652 160 if (strtolower($imap_server_type) != "courier" ||
161 strtolower($box) != "inbox.trash")
162 echo "<OPTION VALUE=\"$box\">$box2\n";
1f97f59a 163 }
164 }
60573cd9 165 }
e7db48af 166 echo "</SELECT></TT>\n";
813eba2f 167 if ($show_contain_subfolders_option) {
e7db48af 168 echo "<br><INPUT TYPE=CHECKBOX NAME=\"contain_subs\"> &nbsp;";
036a8a9d 169 echo _("Let this folder contain subfolders");
aae41ae9 170 echo "<BR>";
813eba2f 171 }
88c81396 172 echo "<INPUT TYPE=SUBMIT VALUE=\""._("Create")."\">\n";
1195c340 173 echo "</FORM></TD></TR>\n";
174
175 echo "<tr><td bgcolor=\"$color[4]\">&nbsp;</td></tr>\n";
60573cd9 176
177 /** RENAMING FOLDERS **/
32f4685b 178 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><B>";
036a8a9d 179 echo _("Rename a Folder");
32f4685b 180 echo "</B></TD></TR>";
1195c340 181 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>";
225ce239 182 if ($count_special_folders < count($boxes)) {
9f2215a1 183 echo "<FORM ACTION=\"folders_rename_getname.php\" METHOD=\"POST\">\n";
225ce239 184 echo "<TT><SELECT NAME=old>\n";
185 for ($i = 0; $i < count($boxes); $i++) {
186 $use_folder = true;
1e0628fb 187
5bdd7223 188 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
189 ($boxes[$i]["unformatted"] != $trash_folder) &&
1d38b94b 190 ($boxes[$i]["unformatted"] != $sent_folder) &&
191 ($boxes[$i]["unformatted"] != $draft_folder))
5bdd7223 192 {
193 $box = $boxes[$i]["unformatted-dm"];
0cd84d75 194 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]["unformatted-disp"]);
5bdd7223 195 if (strtolower($imap_server_type) != "courier" || strtolower($box) != "inbox.trash")
196 echo "<OPTION VALUE=\"$box\">$box2\n";
197 }
60573cd9 198 }
225ce239 199 echo "</SELECT></TT>\n";
200 echo "<INPUT TYPE=SUBMIT VALUE=\"";
201 echo _("Rename");
202 echo "\">\n";
37578167 203 echo "</FORM></TD></TR>\n";
204 } else {
0e743004 205 echo _("No folders found") . "<br><br></td></tr>";
37578167 206 }
207 $boxes_sub = $boxes;
1195c340 208
e9f8ea4e 209 echo "<tr><td bgcolor=\"$color[4]\">&nbsp;</td></tr></table>\n";
37578167 210
211 /** UNSUBSCRIBE FOLDERS **/
e7db48af 212 echo "<TABLE WIDTH=70% COLS=2 ALIGN=CENTER cellpadding=2 cellspacing=1 border=0>\n";
213 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER colspan=2><B>";
88c81396 214 echo _("Unsubscribe") . "/" . _("Subscribe");
e7db48af 215 echo "</B></TD></TR>\n";
216 echo "<TR><TD BGCOLOR=\"$color[0]\" width=50% ALIGN=CENTER>\n";
37578167 217 if ($count_special_folders < count($boxes)) {
9f2215a1 218 echo "<FORM ACTION=\"folders_subscribe.php?method=unsub\" METHOD=\"POST\">\n";
e9f8ea4e 219 echo "<TT><SELECT NAME=mailbox[] multiple size=8>\n";
37578167 220 for ($i = 0; $i < count($boxes); $i++) {
221 $use_folder = true;
5bdd7223 222 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
223 ($boxes[$i]["unformatted"] != $trash_folder) &&
1d38b94b 224 ($boxes[$i]["unformatted"] != $sent_folder) &&
225 ($boxes[$i]["unformatted"] != $draft_folder))
5bdd7223 226 {
227 $box = $boxes[$i]["unformatted-dm"];
0cd84d75 228 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]["unformatted-disp"]);
5bdd7223 229 echo " <OPTION VALUE=\"$box\">$box2\n";
230 }
37578167 231 }
e9f8ea4e 232 echo "</SELECT></TT><br>\n";
37578167 233 echo "<INPUT TYPE=SUBMIT VALUE=\"";
234 echo _("Unsubscribe");
235 echo "\">\n";
e9f8ea4e 236 echo "</FORM></TD>\n";
37578167 237 } else {
e9f8ea4e 238 echo _("No folders were found to unsubscribe from!") . "</td>";
37578167 239 }
240 $boxes_sub = $boxes;
e9f8ea4e 241
37578167 242 /** SUBSCRIBE TO FOLDERS **/
76f9855e 243 echo "<TD BGCOLOR=\"$color[0]\" width=50% ALIGN=CENTER>";
e9f8ea4e 244 $imap_stream = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 1);
245 $boxes_all = sqimap_mailbox_list_all ($imap_stream);
246
5bdd7223 247 $box = "";
248 $box2 = "";
249 for ($i = 0, $q = 0; $i < count($boxes_all); $i++) {
250 $use_folder = true;
251 for ($p = 0; $p < count ($boxes); $p++) {
252 if ($boxes_all[$i]["unformatted"] == $boxes[$p]["unformatted"]) {
253 $use_folder = false;
254 continue;
255 } else if ($boxes_all[$i]["unformatted-dm"] == $folder_prefix) {
256 $use_folder = false;
257 }
32b3d87e 258 }
5bdd7223 259 if ($use_folder == true) {
260 $box[$q] = $boxes_all[$i]["unformatted-dm"];
2752bb16 261 $box2[$q] = $boxes_all[$i]["unformatted-disp"];
5bdd7223 262 $q++;
263 }
264 }
265 sqimap_logout($imap_stream);
e9f8ea4e 266
267 if ($box && $box2) {
268 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n";
269 echo "<tt><select name=mailbox[] multiple size=8>";
270
271 for ($q = 0; $q < count($box); $q++) {
272 echo " <OPTION VALUE=\"$box[$q]\">".$box2[$q]."\n";
273 }
274 echo "</select></tt><br>";
275 echo "<INPUT TYPE=SUBMIT VALUE=\"". _("Subscribe") . "\">\n";
225ce239 276 echo "</FORM></TD></TR></TABLE><BR>\n";
277 } else {
e9f8ea4e 278 echo _("No folders were found to subscribe to!") . "</td></tr></table>";
60573cd9 279 }
e7db48af 280?>
281
282
283 <?php do_hook("folders_bottom"); ?>
284
60573cd9 285
e7db48af 286 </td></tr>
287 </table>
288
289</td></tr>
290</table>
291
292<?php
1195c340 293 sqimap_logout($imapConnection);
aa42fbfb 294?>
e7db48af 295
35586184 296</body></html>