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