59177427 |
1 | <?php |
895905c0 |
2 | |
35586184 |
3 | /** |
4 | * folders.php |
5 | * |
15e6162e |
6 | * Copyright (c) 1999-2002 The SquirrelMail Project Team |
35586184 |
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 | |
35586184 |
16 | require_once('../src/validate.php'); |
994163eb |
17 | require_once('../functions/imap_utf7_decode_local.php'); |
35586184 |
18 | require_once('../functions/imap.php'); |
19 | require_once('../functions/array.php'); |
20 | require_once('../functions/plugin.php'); |
50ed645b |
21 | require_once('../functions/html.php'); |
d3cdb279 |
22 | |
e634431a |
23 | displayPageHeader($color, 'None'); |
aa42fbfb |
24 | |
2441907d |
25 | echo '<br>' . |
26 | html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="2" cellspacing="0" border="0"' ) . |
27 | html_tag( 'tr' ) . |
28 | html_tag( 'td', '', 'center' ) . '<b>' . _("Folders") . '</b>' . |
29 | html_tag( 'table', '', 'center', '', 'width="100%" cellpadding="5" cellspacing="0" border="0"' ) . |
30 | html_tag( 'tr' ) . |
31 | html_tag( 'td', '', 'center', $color[4] ); |
aa42fbfb |
32 | |
1c52ba77 |
33 | if ((isset($success) && $success) || |
34 | (isset($sent_create) && $sent_create == 'true') || |
35 | (isset($trash_create) && $trash_create == 'true')) { |
e634431a |
36 | if ($success == "subscribe") { |
50ed645b |
37 | $td_str = "<b>" . _("Subscribed successfully!") . "</b><br>"; |
e634431a |
38 | } else if ($success == "unsubscribe") { |
50ed645b |
39 | $td_str = "<b>" . _("Unsubscribed successfully!") . "</b><br>"; |
e634431a |
40 | } else if ($success == "delete") { |
50ed645b |
41 | $td_str = "<b>" . _("Deleted folder successfully!") . "</b><br>"; |
e634431a |
42 | } else if ($success == "create") { |
50ed645b |
43 | $td_str = "<b>" . _("Created folder successfully!") . "</b><br>"; |
e634431a |
44 | } else if ($success == "rename") { |
50ed645b |
45 | $td_str = "<b>" . _("Renamed successfully!") . "</b><br>"; |
e634431a |
46 | } |
47 | |
50ed645b |
48 | echo html_tag( 'table', |
49 | html_tag( 'tr', |
50 | html_tag( 'td', $td_str . |
51 | "<a href=\"../src/left_main.php\" target=left>" . _("refresh folder list") . "</a>" , |
52 | 'center' ) |
53 | ) , |
54 | 'center', '', 'width="100%" cellpadding="4" cellspacing="0" border="0"' ) . "<br>\n"; |
e634431a |
55 | } else { |
56 | echo "<br>"; |
57 | } |
58 | $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0); |
59 | $boxes = sqimap_mailbox_list($imapConnection); |
60 | |
61 | /** CREATING FOLDERS **/ |
50ed645b |
62 | echo html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="4" cellspacing="0" border="0"' ) . |
63 | html_tag( 'tr', |
64 | html_tag( 'td', '<b>' . _("Create Folder") . '</b>', 'center', $color[9] ) |
65 | ) . |
66 | html_tag( 'tr' ) . |
67 | html_tag( 'td', '', 'center', $color[0] ) . |
68 | |
1c52ba77 |
69 | "<FORM NAME=cf ACTION=\"folders_create.php\" METHOD=\"POST\">\n". |
6b4bd11f |
70 | "<input type=TEXT SIZE=25 NAME=folder_name><BR>\n". |
1c52ba77 |
71 | _("as a subfolder of"). |
72 | "<BR>". |
73 | "<TT><SELECT NAME=subfolder>\n"; |
e634431a |
74 | if ($default_sub_of_inbox == false) { |
75 | echo '<OPTION SELECTED VALUE="">[ '._("None")." ]\n"; |
76 | } else { |
77 | echo '<OPTION VALUE="">[ '._("None")." ]\n"; |
78 | } |
79 | |
80 | for ($i = 0; $i < count($boxes); $i++) { |
81 | if (!in_array('noinferiors', $boxes[$i]['flags'])) { |
1c52ba77 |
82 | if ((strtolower($boxes[$i]['unformatted']) == 'inbox') && |
83 | $default_sub_of_inbox) { |
994163eb |
84 | |
1c52ba77 |
85 | $box = $boxes[$i]['unformatted']; |
46bc57c1 |
86 | $box2 = str_replace(' ', ' ', |
87 | imap_utf7_decode_local($boxes[$i]['unformatted-disp'])); |
1c52ba77 |
88 | echo "<OPTION SELECTED VALUE=\"$box\">$box2</option>\n"; |
e634431a |
89 | } else { |
1c52ba77 |
90 | $box = $boxes[$i]['unformatted']; |
46bc57c1 |
91 | $box2 = str_replace(' ', ' ', |
92 | imap_utf7_decode_local($boxes[$i]['unformatted-disp'])); |
1c52ba77 |
93 | if (strtolower($imap_server_type) != 'courier' || |
e634431a |
94 | strtolower($box) != "inbox.trash") |
1c52ba77 |
95 | echo "<OPTION VALUE=\"$box\">$box2</option>\n"; |
e634431a |
96 | } |
97 | } |
98 | } |
99 | echo "</SELECT></TT>\n"; |
100 | if ($show_contain_subfolders_option) { |
6b4bd11f |
101 | echo "<br><input type=CHECKBOX NAME=\"contain_subs\"> "; |
e634431a |
102 | echo _("Let this folder contain subfolders"); |
103 | echo "<BR>"; |
1c52ba77 |
104 | } |
6b4bd11f |
105 | echo "<input type=SUBMIT VALUE=\""._("Create")."\">\n"; |
106 | echo "</FORM></td></tr>\n"; |
e634431a |
107 | |
50ed645b |
108 | echo html_tag( 'tr', |
109 | html_tag( 'td', ' ', 'left', $color[4] ) |
110 | ) ."\n"; |
0037f048 |
111 | |
112 | /** count special folders **/ |
113 | $count_special_folders = 0; |
114 | $num_max = 1; |
115 | if (strtolower($imap_server_type) == "courier" || $move_to_trash) { |
116 | $num_max++; |
117 | } |
118 | if ($move_to_sent) { |
119 | $num_max++; |
120 | } |
121 | if ($save_as_draft) { |
122 | $num_max++; |
123 | } |
124 | for ($p = 0; $p < count($boxes) && $count_special_folders < $num_max; $p++) { |
125 | if (strtolower($boxes[$p]['unformatted']) == 'inbox') |
126 | $count_special_folders++; |
127 | else if (strtolower($imap_server_type) == 'courier' && |
128 | strtolower($boxes[$p]['unformatted']) == 'inbox.trash') |
129 | $count_special_folders++; |
130 | else if ($boxes[$p]['unformatted'] == $trash_folder && $trash_folder) |
131 | $count_special_folders++; |
132 | else if ($boxes[$p]['unformatted'] == $sent_folder && $sent_folder) |
133 | $count_special_folders++; |
134 | else if ($boxes[$p]['unformatted'] == $draft_folder && $draft_folder) |
135 | $count_special_folders++; |
136 | } |
137 | |
138 | |
e634431a |
139 | /** RENAMING FOLDERS **/ |
50ed645b |
140 | echo html_tag( 'tr', |
141 | html_tag( 'td', '<b>' . _("Rename a Folder") . '</b>', 'center', $color[9] ) |
142 | ) . |
143 | html_tag( 'tr' ) . |
144 | html_tag( 'td', '', 'center', $color[0] ); |
145 | |
0037f048 |
146 | if ($count_special_folders < count($boxes)) { |
147 | echo "<FORM ACTION=\"folders_rename_getname.php\" METHOD=\"POST\">\n" |
148 | . "<TT><SELECT NAME=old>\n" |
149 | . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n"; |
e634431a |
150 | for ($i = 0; $i < count($boxes); $i++) { |
151 | $use_folder = true; |
152 | |
1c52ba77 |
153 | if ((strtolower($boxes[$i]['unformatted']) != 'inbox') && |
154 | ($boxes[$i]['unformatted'] != $trash_folder) && |
155 | ($boxes[$i]['unformatted'] != $sent_folder) && |
156 | ($boxes[$i]['unformatted'] != $draft_folder)) { |
157 | $box = $boxes[$i]['unformatted-dm']; |
158 | |
46bc57c1 |
159 | $box2 = str_replace(' ', ' ', |
160 | imap_utf7_decode_local($boxes[$i]['unformatted-disp'])); |
1c52ba77 |
161 | if (strtolower($imap_server_type) != 'courier' || strtolower($box) != 'inbox.trash') { |
162 | echo "<OPTION VALUE=\"$box\">$box2</option>\n"; |
163 | } |
e634431a |
164 | } |
165 | } |
1c52ba77 |
166 | echo "</SELECT></TT>\n". |
6b4bd11f |
167 | "<input type=SUBMIT VALUE=\"". |
1c52ba77 |
168 | _("Rename"). |
169 | "\">\n". |
50ed645b |
170 | "</FORM></td></tr>\n"; |
e634431a |
171 | } else { |
172 | echo _("No folders found") . "<br><br></td></tr>"; |
173 | } |
174 | $boxes_sub = $boxes; |
175 | |
50ed645b |
176 | echo html_tag( 'tr', |
177 | html_tag( 'td', ' ', 'left', $color[4] ) |
178 | ) ."\n"; |
e634431a |
179 | |
180 | /** DELETING FOLDERS **/ |
50ed645b |
181 | echo html_tag( 'tr', |
182 | html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[9] ) |
183 | ) . |
184 | html_tag( 'tr' ) . |
185 | html_tag( 'td', '', 'center', $color[0] ); |
e634431a |
186 | |
e634431a |
187 | if ($count_special_folders < count($boxes)) { |
0037f048 |
188 | echo "<FORM ACTION=\"folders_delete.php\" METHOD=\"POST\">\n" |
189 | . "<TT><SELECT NAME=mailbox>\n" |
190 | . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n"; |
e634431a |
191 | for ($i = 0; $i < count($boxes); $i++) { |
192 | $use_folder = true; |
1c52ba77 |
193 | if ((strtolower($boxes[$i]['unformatted']) != 'inbox') && |
194 | ($boxes[$i]['unformatted'] != $trash_folder) && |
195 | ($boxes[$i]['unformatted'] != $sent_folder) && |
196 | ($boxes[$i]['unformatted'] != $draft_folder) && |
11f6f685 |
197 | (!in_array('noselect', $boxes[$i]['flags'])) && |
1c52ba77 |
198 | ((strtolower($imap_server_type) != 'courier') || |
199 | (strtolower($boxes[$i]['unformatted']) != 'inbox.trash'))) { |
200 | $box = $boxes[$i]['unformatted-dm']; |
46bc57c1 |
201 | $box2 = str_replace(' ', ' ', |
202 | imap_utf7_decode_local($boxes[$i]['unformatted-disp'])); |
1c52ba77 |
203 | echo " <OPTION VALUE=\"$box\">$box2</option>\n"; |
e634431a |
204 | } |
205 | } |
206 | echo "</SELECT></TT>\n"; |
6b4bd11f |
207 | echo "<input type=SUBMIT VALUE=\""; |
e634431a |
208 | echo _("Delete"); |
209 | echo "\">\n"; |
6b4bd11f |
210 | echo "</form></td></tr>\n"; |
e634431a |
211 | } else { |
6b4bd11f |
212 | echo _("No folders found") . "<br><br></td></tr>"; |
e634431a |
213 | } |
50ed645b |
214 | |
215 | echo html_tag( 'tr', |
216 | html_tag( 'td', ' ', 'left', $color[4] ) |
217 | ) ."</table>\n"; |
218 | |
e634431a |
219 | |
220 | /** UNSUBSCRIBE FOLDERS **/ |
50ed645b |
221 | echo html_tag( 'table', '', 'center', '', 'width="70%" cols="2" cellpadding="4" cellspacing="0" border="0"' ) . |
222 | html_tag( 'tr', |
223 | html_tag( 'td', '<b>' . _("Unsubscribe") . '/' . _("Subscribe") . '</b>', 'center', $color[9], 'colspan="2"' ) |
224 | ) . |
225 | html_tag( 'tr' ) . |
226 | html_tag( 'td', '', 'center', $color[0], 'width="50%"' ); |
227 | |
e634431a |
228 | if ($count_special_folders < count($boxes)) { |
229 | echo "<FORM ACTION=\"folders_subscribe.php?method=unsub\" METHOD=\"POST\">\n"; |
230 | echo "<TT><SELECT NAME=\"mailbox[]\" multiple size=8>\n"; |
231 | for ($i = 0; $i < count($boxes); $i++) { |
232 | $use_folder = true; |
233 | if ((strtolower($boxes[$i]["unformatted"]) != "inbox") && |
234 | ($boxes[$i]["unformatted"] != $trash_folder) && |
235 | ($boxes[$i]["unformatted"] != $sent_folder) && |
236 | ($boxes[$i]["unformatted"] != $draft_folder)) { |
237 | $box = $boxes[$i]["unformatted-dm"]; |
46bc57c1 |
238 | $box2 = str_replace(' ', ' ', |
239 | imap_utf7_decode_local($boxes[$i]["unformatted-disp"])); |
e634431a |
240 | echo " <OPTION VALUE=\"$box\">$box2\n"; |
241 | } |
242 | } |
243 | echo "</SELECT></TT><br><br>\n"; |
6b4bd11f |
244 | echo "<input type=SUBMIT VALUE=\""; |
e634431a |
245 | echo _("Unsubscribe"); |
246 | echo "\">\n"; |
50ed645b |
247 | echo "</FORM></td>\n"; |
e634431a |
248 | } else { |
249 | echo _("No folders were found to unsubscribe from!") . "</td>"; |
250 | } |
251 | $boxes_sub = $boxes; |
252 | |
253 | /** SUBSCRIBE TO FOLDERS **/ |
50ed645b |
254 | echo html_tag( 'td', '', 'center', $color[0], 'width="50%"' ); |
e634431a |
255 | $imap_stream = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 1); |
256 | $boxes_all = sqimap_mailbox_list_all ($imap_stream); |
257 | |
258 | $box = ""; |
259 | $box2 = ""; |
260 | for ($i = 0, $q = 0; $i < count($boxes_all); $i++) { |
261 | $use_folder = true; |
262 | for ($p = 0; $p < count ($boxes); $p++) { |
263 | if ($boxes_all[$i]["unformatted"] == $boxes[$p]["unformatted"]) { |
264 | $use_folder = false; |
265 | continue; |
266 | } else if ($boxes_all[$i]["unformatted-dm"] == $folder_prefix) { |
267 | $use_folder = false; |
268 | } |
269 | } |
7e235a1a |
270 | if ($use_folder == true) { |
e634431a |
271 | $box[$q] = $boxes_all[$i]["unformatted-dm"]; |
994163eb |
272 | $box2[$q] = imap_utf7_decode_local($boxes_all[$i]["unformatted-disp"]); |
e634431a |
273 | $q++; |
274 | } |
275 | } |
276 | sqimap_logout($imap_stream); |
277 | |
278 | if ($box && $box2) { |
279 | echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n"; |
280 | echo "<tt><select name=\"mailbox[]\" multiple size=8>"; |
281 | |
282 | for ($q = 0; $q < count($box); $q++) { |
283 | echo " <OPTION VALUE=\"$box[$q]\">".$box2[$q]."\n"; |
284 | } |
285 | echo "</select></tt><br><br>"; |
6b4bd11f |
286 | echo "<input type=SUBMIT VALUE=\"". _("Subscribe") . "\">\n"; |
50ed645b |
287 | echo "</FORM></td></tr></table><BR>\n"; |
e634431a |
288 | } else { |
289 | echo _("No folders were found to subscribe to!") . "</td></tr></table>"; |
290 | } |
e7db48af |
291 | |
bd9bbfef |
292 | do_hook("folders_bottom"); |
293 | ?> |
e7db48af |
294 | |
60573cd9 |
295 | |
e7db48af |
296 | </td></tr> |
297 | </table> |
298 | |
299 | </td></tr> |
300 | </table> |
301 | |
302 | <?php |
1195c340 |
303 | sqimap_logout($imapConnection); |
aa42fbfb |
304 | ?> |
e7db48af |
305 | |
0037f048 |
306 | </body></html> |