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