Added minimum GNU License
[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
26 include("../src/load_prefs.php");
27
28 displayPageHeader($color, "None");
29
30 echo "<TABLE WIDTH=100% COLS=1 ALIGN=CENTER>\n";
31 echo " <TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>\n";
32 echo _("Folders");
33 echo " </TD></TR>\n";
34 echo "</TABLE>\n";
35
36 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
37 $boxes = sqimap_mailbox_list($imapConnection);
38
39 /** Cyrus Folder Options**/
40 //Creates the Sent and Trash folder
41 if (($sent_create == "true") || ($trash_create == "true")) {
42 if ($sent_create == "true") {
43 sqimap_mailbox_create ($imapConnection, $sent_folder, "");
44 }
45 if ($trash_create == "true") {
46 sqimap_mailbox_create ($imapConnection, $trash_folder, "");
47 }
48 echo "<BR><BR><CENTER><b>";
49 echo _("Mailboxes Created Successfully!");
50 echo "<BR><A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>";
51 echo _("Click here");
52 echo "</A> ";
53 echo _("to continue.");
54 echo "</CENTER>";
55 echo "</BODY></HTML>";
56
57 exit;
58 }
59
60 //display form option for creating Sent and Trash folder
61 if ($imap_server_type == "cyrus") {
62 if ((!sqimap_mailbox_exists ($imapConnection, $sent_folder)) || (!sqimap_mailbox_exists ($imapConnection, $trash_folder))) {
63 echo "<TABLE WIDTH=70% COLS=1 ALIGN=CENTER>\n";
64 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><B>";
65 echo _("Special Folder Options");
66 echo "</B></TD></TR>";
67 echo "<TR><TD BGCOLOR=\"$color[4]\" ALIGN=CENTER>";
68 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.");
69 echo "<FORM ACTION=\"folders.php\" METHOD=\"POST\">\n";
70 if (!sqimap_mailbox_exists ($imapConnection, $sent_folder)) {
71 echo _("Create Sent") . "<INPUT TYPE=checkbox NAME=sent_create value=true><br>\n";
72 }
73 if (!sqimap_mailbox_exists ($imapConnection, $trash_folder)){
74 echo _("Create Trash") . "<INPUT TYPE=checkbox NAME=trash_create value=true><br>\n";
75 echo "<INPUT TYPE=submit VALUE=Create>";
76 echo "</FORM></TD></TR>\n";
77 }
78 }
79 }
80
81 /** DELETING FOLDERS **/
82 echo "<TABLE WIDTH=70% COLS=1 ALIGN=CENTER>\n";
83 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><B>";
84 echo _("Delete Folder");
85 echo "</B></TD></TR>";
86 echo "<TR><TD BGCOLOR=\"$color[4]\" ALIGN=CENTER>";
87
88 $count_special_folders = 0;
89 $num_max = 1;
90 if ($move_to_trash)
91 $num_max++;
92 if ($move_to_sent)
93 $num_max++;
94
95 for ($p = 0; $p < count($boxes) && $count_special_folders < $num_max; $p++) {
96 if (strtolower($boxes[$i]["unformatted"]) == "inbox")
97 $count_special_folders++;
98 else if ($boxes[$i]["unformatted"] == $trash_folder)
99 $count_special_folders++;
100 else if ($boxes[$i]["unformatted"] == $sent_folder)
101 $count_special_folders++;
102 }
103
104 if ($count_special_folders < count($boxes)) {
105 echo "<FORM ACTION=\"folders_delete.php\" METHOD=\"POST\">\n";
106 echo "<TT><SELECT NAME=mailbox>\n";
107 for ($i = 0; $i < count($boxes); $i++) {
108 $use_folder = true;
109 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
110 ($boxes[$i]["unformatted"] != $trash_folder) &&
111 ($boxes[$i]["unformatted"] != $sent_folder))
112 {
113 $box = $boxes[$i]["unformatted-dm"];
114 $box2 = replace_spaces($boxes[$i]["formatted"]);
115 echo " <OPTION VALUE=\"$box\">$box2\n";
116 }
117 }
118 echo "</SELECT></TT>\n";
119 echo "<INPUT TYPE=SUBMIT VALUE=\"";
120 echo _("Delete");
121 echo "\">\n";
122 echo "</FORM><BR></TD></TR>\n";
123 } else {
124 echo _("No mailboxes found") . "<br><br></td><tr>";
125 }
126
127
128 /** CREATING FOLDERS **/
129 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><B>";
130 echo _("Create Folder");
131 echo "</B></TD></TR>";
132 echo "<TR><TD BGCOLOR=\"$color[4]\" ALIGN=CENTER>";
133 echo "<FORM ACTION=\"folders_create.php\" METHOD=\"POST\">\n";
134 echo "<INPUT TYPE=TEXT SIZE=25 NAME=folder_name><BR>\n";
135 echo _("as a subfolder of");
136 echo "<BR>";
137 echo "<TT><SELECT NAME=subfolder>\n";
138 if ($default_sub_of_inbox == false)
139 echo "<OPTION SELECTED>[ None ]\n";
140 else
141 echo "<OPTION>[ None ]\n";
142
143 for ($i = 0; $i < count($boxes); $i++) {
144 if (count($boxes[$i]["flags"]) > 0) {
145 for ($j = 0; $j < count($boxes[$i]["flags"]); $j++) {
146 if ($boxes[$i]["flags"][$j] != "noinferiors") {
147 if ((strtolower($boxes[$i]["unformatted"]) == "inbox") && ($default_sub_of_inbox == true)) {
148 $box = $boxes[$i]["unformatted"];
149 $box2 = replace_spaces($boxes[$i]["formatted"]);
150 echo "<OPTION SELECTED VALUE=\"$box\">$box2\n";
151 } else {
152 $box = $boxes[$i]["unformatted"];
153 $box2 = replace_spaces($boxes[$i]["formatted"]);
154 echo "<OPTION VALUE=\"$box\">$box2\n";
155 }
156 }
157 }
158 } else {
159 if ((strtolower($boxes[$i]["unformatted"]) == "inbox") && ($default_sub_of_inbox == true)) {
160 $box = $boxes[$i]["unformatted"];
161 $box2 = replace_spaces($boxes[$i]["formatted"]);
162 echo "<OPTION SELECTED VALUE=\"$box\">$box2\n";
163 } else {
164 $box = $boxes[$i]["unformatted"];
165 $box2 = replace_spaces($boxes[$i]["formatted"]);
166 echo "<OPTION VALUE=\"$box\">$box2\n";
167 }
168 }
169 }
170 echo "</SELECT></TT><BR>\n";
171 if ($show_contain_subfolders_option) {
172 echo "<INPUT TYPE=CHECKBOX NAME=\"contain_subs\"> &nbsp;";
173 echo _("Let this folder contain subfolders");
174 echo "<BR>";
175 }
176 echo "<INPUT TYPE=SUBMIT VALUE=Create>\n";
177 echo "</FORM><BR></TD></TR><BR>\n";
178
179 /** RENAMING FOLDERS **/
180 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><B>";
181 echo _("Rename a Folder");
182 echo "</B></TD></TR>";
183 echo "<TR><TD BGCOLOR=\"$color[4]\" ALIGN=CENTER>";
184 if ($count_special_folders < count($boxes)) {
185 echo "<FORM ACTION=\"folders_rename_getname.php\" METHOD=\"POST\">\n";
186 echo "<TT><SELECT NAME=old>\n";
187 for ($i = 0; $i < count($boxes); $i++) {
188 $use_folder = true;
189
190 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
191 ($boxes[$i]["unformatted"] != $trash_folder) &&
192 ($boxes[$i]["unformatted"] != $sent_folder))
193 {
194 $box = $boxes[$i]["unformatted-dm"];
195 $box2 = replace_spaces($boxes[$i]["formatted"]);
196 echo " <OPTION VALUE=\"$box\">$box2\n";
197 }
198 }
199 echo "</SELECT></TT>\n";
200 echo "<INPUT TYPE=SUBMIT VALUE=\"";
201 echo _("Rename");
202 echo "\">\n";
203 echo "</FORM></TD></TR>\n";
204 } else {
205 echo _("No mailboxes found") . "<br><br></td></tr>";
206 }
207 $boxes_sub = $boxes;
208
209 /** UNSUBSCRIBE FOLDERS **/
210 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><B>";
211 echo _("Unsubscribe/Subscribe");
212 echo "</B></TD></TR>";
213 echo "<TR><TD BGCOLOR=\"$color[4]\" ALIGN=CENTER>";
214 if ($count_special_folders < count($boxes)) {
215 echo "<FORM ACTION=\"folders_subscribe.php?method=unsub\" METHOD=\"POST\">\n";
216 echo "<TT><SELECT NAME=mailbox>\n";
217 for ($i = 0; $i < count($boxes); $i++) {
218 $use_folder = true;
219 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
220 ($boxes[$i]["unformatted"] != $trash_folder) &&
221 ($boxes[$i]["unformatted"] != $sent_folder))
222 {
223 $box = $boxes[$i]["unformatted-dm"];
224 $box2 = replace_spaces($boxes[$i]["formatted"]);
225 echo " <OPTION VALUE=\"$box\">$box2\n";
226 }
227 }
228 echo "</SELECT></TT>\n";
229 echo "<INPUT TYPE=SUBMIT VALUE=\"";
230 echo _("Unsubscribe");
231 echo "\">\n";
232 echo "</FORM></TD></TR>\n";
233 } else {
234 echo _("No mailboxes found") . "<br><br></td></tr>";
235 }
236 $boxes_sub = $boxes;
237
238 /** SUBSCRIBE TO FOLDERS **/
239
240 echo "<TR><TD BGCOLOR=\"$color[4]\" ALIGN=CENTER>";
241 if ($count_special_folders <= count($boxes)) {
242 $imap_stream = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 1);
243 $boxes_all = sqimap_mailbox_list_all ($imap_stream);
244
245 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n";
246 echo "<tt><select name=mailbox>";
247 for ($i = 0; $i < count($boxes_all); $i++) {
248 $use_folder = true;
249 for ($p = 0; $p < count ($boxes); $p++) {
250 if ($boxes_all[$i]["unformatted"] == $boxes[$p]["unformatted"]) {
251 $use_folder = false;
252 continue;
253 } else if ($boxes_all[$i]["unformatted-dm"] == $folder_prefix) {
254 $use_folder = false;
255 }
256 }
257 if ($use_folder == true) {
258 $box = $boxes_all[$i]["unformatted-dm"];
259 $box2 = replace_spaces($boxes_all[$i]["formatted"]);
260 echo " <OPTION VALUE=\"$box\">$box2\n";
261 }
262 }
263 echo "</select></tt>";
264 echo "<INPUT TYPE=SUBMIT VALUE=\"";
265 echo _("Subscribe");
266 echo "\">\n";
267 echo "</FORM></TD></TR></TABLE><BR>\n";
268 } else {
269 echo _("No mailboxes found") . "<br><br></td></tr></table>";
270 }
271
272 ?>
273 </BODY></HTML>