59177427 |
1 | <?php |
895905c0 |
2 | |
35586184 |
3 | /** |
4 | * folders.php |
5 | * |
6c84ba1e |
6 | * Copyright (c) 1999-2005 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 | * |
30967a1e |
13 | * @version $Id$ |
8f6f9ba5 |
14 | * @package squirrelmail |
35586184 |
15 | */ |
16 | |
30967a1e |
17 | /** |
18 | * Path for SquirrelMail required files. |
19 | * @ignore |
20 | */ |
86725763 |
21 | define('SM_PATH','../'); |
22 | |
23 | /* SquirrelMail required files. */ |
08185f2a |
24 | require_once(SM_PATH . 'include/validate.php'); |
86725763 |
25 | require_once(SM_PATH . 'functions/imap.php'); |
32aa0074 |
26 | require_once(SM_PATH . 'functions/folder_manip.php'); |
86725763 |
27 | require_once(SM_PATH . 'functions/plugin.php'); |
28 | require_once(SM_PATH . 'functions/html.php'); |
62366261 |
29 | require_once(SM_PATH . 'functions/forms.php'); |
d3cdb279 |
30 | |
e634431a |
31 | displayPageHeader($color, 'None'); |
aa42fbfb |
32 | |
a32985a5 |
33 | /* get globals we may need */ |
34 | |
f38b7cf0 |
35 | sqgetGlobalVar('username', $username, SQ_SESSION); |
36 | sqgetGlobalVar('key', $key, SQ_COOKIE); |
37 | sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION); |
38 | sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION); |
39 | |
32aa0074 |
40 | sqgetGlobalVar('smaction', $action, SQ_POST); |
a32985a5 |
41 | |
42 | /* end of get globals */ |
43 | |
ff0969a0 |
44 | echo '<br />' . |
6206f6c4 |
45 | html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) . |
2441907d |
46 | html_tag( 'tr' ) . |
47 | html_tag( 'td', '', 'center' ) . '<b>' . _("Folders") . '</b>' . |
48 | html_tag( 'table', '', 'center', '', 'width="100%" cellpadding="5" cellspacing="0" border="0"' ) . |
49 | html_tag( 'tr' ) . |
50 | html_tag( 'td', '', 'center', $color[4] ); |
aa42fbfb |
51 | |
32aa0074 |
52 | $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0); |
b7f83b61 |
53 | |
32aa0074 |
54 | /* switch to the right function based on what the user selected */ |
55 | if ( sqgetGlobalVar('smaction', $action, SQ_POST) ) { |
b7f83b61 |
56 | |
32aa0074 |
57 | switch ($action) |
b7f83b61 |
58 | { |
32aa0074 |
59 | case 'create': |
60 | sqgetGlobalVar('folder_name', $folder_name, SQ_POST); |
61 | sqgetGlobalVar('subfolder', $subfolder, SQ_POST); |
62 | sqgetGlobalVar('contain_subs', $contain_subs, SQ_POST); |
63 | folders_create($imapConnection, $delimiter, $folder_name, $subfolder, $contain_subs); |
64 | $td_str = _("Created folder successfully."); |
b7f83b61 |
65 | break; |
32aa0074 |
66 | case 'rename': |
67 | if ( sqgetGlobalVar('cancelbutton', $dummy, SQ_POST) ) { |
68 | break; |
69 | } |
70 | if ( ! sqgetGlobalVar('new_name', $new_name, SQ_POST) ) { |
71 | sqgetGlobalVar('old_name', $old_name, SQ_POST); |
72 | folders_rename_getname($imapConnection, $delimiter, $old_name); |
73 | } else { |
74 | sqgetGlobalVar('orig', $orig, SQ_POST); |
75 | sqgetGlobalVar('old_name', $old_name, SQ_POST); |
76 | folders_rename_do($imapConnection, $delimiter, $orig, $old_name, $new_name); |
333daac7 |
77 | $td_str = _("Renamed successfully."); |
32aa0074 |
78 | } |
b7f83b61 |
79 | break; |
80 | case 'delete': |
32aa0074 |
81 | if ( sqgetGlobalVar('cancelbutton', $dummy, SQ_POST) ) { |
82 | break; |
83 | } |
84 | sqgetGlobalVar('folder_name', $folder_name, SQ_POST); |
85 | if ( sqgetGlobalVar('confirmed', $dummy, SQ_POST) ) { |
86 | folders_delete_do($imapConnection, $delimiter, $folder_name); |
87 | $td_str = _("Deleted folder successfully."); |
88 | } else { |
89 | folders_delete_ask($imapConnection, $folder_name); |
90 | } |
b7f83b61 |
91 | break; |
32aa0074 |
92 | case 'subscribe': |
93 | sqgetGlobalVar('folder_names', $folder_names, SQ_POST); |
94 | folders_subscribe($imapConnection, $folder_names); |
95 | $td_str = _("Subscribed successfully."); |
b7f83b61 |
96 | break; |
32aa0074 |
97 | case 'unsubscribe': |
98 | sqgetGlobalVar('folder_names', $folder_names, SQ_POST); |
99 | folders_unsubscribe($imapConnection, $folder_names); |
100 | $td_str = _("Unsubscribed successfully."); |
b7f83b61 |
101 | break; |
decb0c39 |
102 | default: |
103 | // TODO: add hook for plugin action processing. |
104 | $td_str = ''; |
105 | break; |
f8a1ed5a |
106 | } |
dcc1cc82 |
107 | |
e0c5664a |
108 | // if there are any messages, output them. |
109 | if ( !empty($td_str) ) { |
110 | echo html_tag( 'table', |
dcc1cc82 |
111 | html_tag( 'tr', |
32aa0074 |
112 | html_tag( 'td', '<b>' . $td_str . "</b><br />\n" . |
39bfea8f |
113 | '<a href="../src/left_main.php" target="left">' . |
dcc1cc82 |
114 | _("refresh folder list") . '</a>' , |
115 | 'center' ) |
116 | ) , |
117 | 'center', '', 'width="100%" cellpadding="4" cellspacing="0" border="0"' ); |
e0c5664a |
118 | } |
e634431a |
119 | } |
b7f83b61 |
120 | |
ff0969a0 |
121 | echo "\n<br />"; |
b7f83b61 |
122 | |
cedd503c |
123 | $boxes = sqimap_mailbox_list($imapConnection,true); |
e634431a |
124 | |
125 | /** CREATING FOLDERS **/ |
ac50138c |
126 | echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) . |
50ed645b |
127 | html_tag( 'tr', |
128 | html_tag( 'td', '<b>' . _("Create Folder") . '</b>', 'center', $color[9] ) |
129 | ) . |
130 | html_tag( 'tr' ) . |
131 | html_tag( 'td', '', 'center', $color[0] ) . |
32aa0074 |
132 | addForm('folders.php', 'post', 'cf'). |
133 | addHidden('smaction','create'). |
62366261 |
134 | addInput('folder_name', '', 25). |
ff0969a0 |
135 | "<br />\n". _("as a subfolder of"). '<br />'. |
136 | "<tt><select name=\"subfolder\">\n"; |
7f0a2c23 |
137 | |
45f836eb |
138 | $show_selected = array(); |
139 | $skip_folders = array(); |
7f0a2c23 |
140 | $server_type = strtolower($imap_server_type); |
decb0c39 |
141 | |
142 | // Special handling for courier |
7f0a2c23 |
143 | if ( $server_type == 'courier' ) { |
decb0c39 |
144 | /** |
145 | * If we use courier, we should hide system trash folder |
146 | * FIXME: (tokul) Who says that courier does not allow storing folders in |
147 | * INBOX.Trash or inbox.trash? Can't reproduce it 3.0.8. This entry is |
148 | * useless, because in_array() check is case sensitive and INBOX is in |
149 | * upper case. |
150 | */ |
151 | array_push($skip_folders, 'inbox.trash'); |
152 | |
153 | if ( $default_folder_prefix == 'INBOX.' ) { |
154 | // We don't need INBOX, since it is top folder |
155 | array_push($skip_folders, 'INBOX'); |
156 | } |
e498ebbd |
157 | } elseif ( $server_type == 'bincimap' ) { |
158 | if ( $default_folder_prefix == 'INBOX/' ) { |
159 | // We don't need INBOX, since it is top folder |
160 | array_push($skip_folders, 'INBOX'); |
161 | } |
7f0a2c23 |
162 | } |
163 | |
164 | if ( $default_sub_of_inbox == false ) { |
ff0969a0 |
165 | echo '<option selected="selected" value="">[ '._("None")." ]</option>\n"; |
e634431a |
166 | } else { |
ff0969a0 |
167 | echo '<option value="">[ '._("None")." ]</option>\n"; |
be2d5495 |
168 | $show_selected = array('inbox'); |
169 | } |
be2d5495 |
170 | |
6e2ae264 |
171 | // Call sqimap_mailbox_option_list, using existing connection to IMAP server, |
91e0dccc |
172 | // the arrays of folders to include or skip (assembled above), |
59a8e3e8 |
173 | // use 'noinferiors' as a mailbox filter to leave out folders that can not contain other folders. |
174 | // use the long format to show subfolders in an intelligible way if parent is missing (special folder) |
175 | echo sqimap_mailbox_option_list($imapConnection, $show_selected, $skip_folders, $boxes, 'noinferiors', true); |
be2d5495 |
176 | |
ff0969a0 |
177 | echo "</select></tt>\n"; |
e634431a |
178 | if ($show_contain_subfolders_option) { |
ff0969a0 |
179 | echo '<br />'. |
62366261 |
180 | addCheckBox('contain_subs', FALSE, '1') .' ' |
b7f83b61 |
181 | . _("Let this folder contain subfolders") |
ff0969a0 |
182 | . '<br />'; |
1c52ba77 |
183 | } |
ff0969a0 |
184 | echo "<input type=\"submit\" value=\""._("Create")."\" />\n"; |
185 | echo "</form></td></tr>\n"; |
e634431a |
186 | |
50ed645b |
187 | echo html_tag( 'tr', |
188 | html_tag( 'td', ' ', 'left', $color[4] ) |
189 | ) ."\n"; |
0037f048 |
190 | |
191 | /** count special folders **/ |
decb0c39 |
192 | foreach ($boxes as $index => $aBoxData) { |
193 | if (isSpecialMailbox($aBoxData['unformatted']) && |
194 | ! in_array($aBoxData['unformatted'],$skip_folders)) { |
195 | $skip_folders[] = $aBoxData['unformatted']; |
196 | } |
0037f048 |
197 | } |
198 | |
decb0c39 |
199 | /** |
200 | * Retrieve list of folders when special folders are excluded. Special folders |
201 | * should be unavailable in rename/delete/unsubscribe. Theoretically user can |
202 | * modify form and perform these operations with special folders, but if user |
203 | * manages to delete/rename/unsubscribe special folder by hacking form... |
204 | * |
205 | * If script or program depends on special folder, they should not assume that |
206 | * folder is available. |
207 | * |
208 | * $filtered_folders contains empty string or html formated option list. |
209 | */ |
210 | $filtered_folders = sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes, NULL, true); |
0037f048 |
211 | |
e634431a |
212 | /** RENAMING FOLDERS **/ |
50ed645b |
213 | echo html_tag( 'tr', |
214 | html_tag( 'td', '<b>' . _("Rename a Folder") . '</b>', 'center', $color[9] ) |
215 | ) . |
216 | html_tag( 'tr' ) . |
217 | html_tag( 'td', '', 'center', $color[0] ); |
218 | |
32aa0074 |
219 | /* show only if we have folders to rename */ |
decb0c39 |
220 | if (! empty($filtered_folders)) { |
32aa0074 |
221 | echo addForm('folders.php') |
222 | . addHidden('smaction', 'rename') |
223 | . "<tt><select name=\"old_name\">\n" |
ff0969a0 |
224 | . ' <option value="">[ ' . _("Select a folder") . " ]</option>\n"; |
be2d5495 |
225 | |
91e0dccc |
226 | // use existing IMAP connection, we have no special values to show, |
59a8e3e8 |
227 | // but we do include values to skip. Use the pre-created $boxes to save an IMAP query. |
228 | // send NULL for the flag - ALL folders are eligible for rename! |
229 | // use long format to make sure folder names make sense when parents may be missing. |
decb0c39 |
230 | echo $filtered_folders; |
be2d5495 |
231 | |
ff0969a0 |
232 | echo "</select></tt>\n". |
233 | '<input type="submit" value="'. |
1c52ba77 |
234 | _("Rename"). |
ff0969a0 |
235 | "\" />\n". |
236 | "</form></td></tr>\n"; |
e634431a |
237 | } else { |
ff0969a0 |
238 | echo _("No folders found") . '<br /><br /></td></tr>'; |
e634431a |
239 | } |
e634431a |
240 | |
50ed645b |
241 | echo html_tag( 'tr', |
242 | html_tag( 'td', ' ', 'left', $color[4] ) |
243 | ) ."\n"; |
e634431a |
244 | |
245 | /** DELETING FOLDERS **/ |
50ed645b |
246 | echo html_tag( 'tr', |
247 | html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[9] ) |
248 | ) . |
249 | html_tag( 'tr' ) . |
250 | html_tag( 'td', '', 'center', $color[0] ); |
e634431a |
251 | |
32aa0074 |
252 | /* show only if we have folders to delete */ |
decb0c39 |
253 | if (!empty($filtered_folders)) { |
32aa0074 |
254 | echo addForm('folders.php') |
255 | . addHidden('smaction', 'delete') |
256 | . "<tt><select name=\"folder_name\">\n" |
ff0969a0 |
257 | . ' <option value="">[ ' . _("Select a folder") . " ]</option>\n"; |
be2d5495 |
258 | |
59a8e3e8 |
259 | // send NULL for the flag - ALL folders are eligible for delete (except what we've got in skiplist) |
260 | // use long format to make sure folder names make sense when parents may be missing. |
decb0c39 |
261 | echo $filtered_folders; |
be2d5495 |
262 | |
ff0969a0 |
263 | echo "</select></tt>\n" |
264 | . '<input type="submit" value="' |
b7f83b61 |
265 | . _("Delete") |
ff0969a0 |
266 | . "\" />\n" |
b7f83b61 |
267 | . "</form></td></tr>\n"; |
e634431a |
268 | } else { |
ff0969a0 |
269 | echo _("No folders found") . "<br /><br /></td></tr>"; |
e634431a |
270 | } |
50ed645b |
271 | |
272 | echo html_tag( 'tr', |
273 | html_tag( 'td', ' ', 'left', $color[4] ) |
274 | ) ."</table>\n"; |
275 | |
e634431a |
276 | |
4d5f2b31 |
277 | if ($show_only_subscribed_folders) { |
decb0c39 |
278 | // FIXME: fix subscription options when top folder is not subscribed and sub folder is subscribed |
279 | // TODO: use checkboxes instead of select options. |
50ed645b |
280 | |
4d5f2b31 |
281 | /** UNSUBSCRIBE FOLDERS **/ |
282 | echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) . |
283 | html_tag( 'tr', |
284 | html_tag( 'td', '<b>' . _("Unsubscribe") . '/' . _("Subscribe") . '</b>', 'center', $color[9], 'colspan="2"' ) |
285 | ) . |
286 | html_tag( 'tr' ) . |
287 | html_tag( 'td', '', 'center', $color[0], 'width="50%"' ); |
288 | |
decb0c39 |
289 | if (!empty($filtered_folders)) { |
32aa0074 |
290 | echo addForm('folders.php') |
291 | . addHidden('smaction', 'unsubscribe') |
decb0c39 |
292 | . "<tt><select name=\"folder_names[]\" multiple=\"multiple\" size=\"8\">\n" |
293 | . $filtered_folders |
294 | . "</select></tt><br /><br />\n" |
4d5f2b31 |
295 | . '<input type="submit" value="' |
296 | . _("Unsubscribe") |
297 | . "\" />\n" |
298 | . "</form></td>\n"; |
299 | } else { |
333daac7 |
300 | echo _("No folders were found to unsubscribe from.") . '</td>'; |
e634431a |
301 | } |
4d5f2b31 |
302 | |
303 | /** SUBSCRIBE TO FOLDERS **/ |
304 | echo html_tag( 'td', '', 'center', $color[0], 'width="50%"' ); |
305 | if(!$no_list_for_subscribe) { |
32aa0074 |
306 | $boxes_all = sqimap_mailbox_list_all ($imapConnection); |
307 | |
308 | $subboxes = array(); |
309 | // here we filter out all boxes we're already subscribed to, |
310 | // so we keep only the unsubscribed ones. |
311 | foreach ($boxes_all as $box_a) { |
f8a1ed5a |
312 | |
32aa0074 |
313 | $use_folder = true; |
314 | foreach ( $boxes as $box ) { |
315 | if ($box_a['unformatted'] == $box['unformatted'] || |
316 | $box_a['unformatted-dm'] == $folder_prefix ) { |
317 | $use_folder = false; |
318 | } |
319 | } |
f8a1ed5a |
320 | |
32aa0074 |
321 | if ($use_folder == true) { |
f8a1ed5a |
322 | $box_enc = htmlspecialchars($box_a['unformatted-dm']); |
32aa0074 |
323 | $box_disp = htmlspecialchars(imap_utf7_decode_local($box_a['unformatted-disp'])); |
324 | $subboxes[$box_enc] = $box_disp; |
4d5f2b31 |
325 | } |
326 | } |
f8a1ed5a |
327 | |
32aa0074 |
328 | if ( count($subboxes) > 0 ) { |
329 | echo addForm('folders.php') |
330 | . addHidden('smaction', 'subscribe') |
331 | . '<tt><select name="folder_names[]" multiple="multiple" size="8">'; |
332 | |
333 | foreach($subboxes as $subbox_enc => $subbox_disp) { |
334 | echo ' <option value="' . $subbox_enc . '">'.$subbox_disp."</option>\n"; |
335 | } |
e634431a |
336 | |
32aa0074 |
337 | echo '</select></tt><br /><br />' |
338 | . '<input type="submit" value="'. _("Subscribe") . "\" />\n" |
339 | . "</form></td></tr></table><br />\n"; |
340 | } else { |
341 | echo _("No folders were found to subscribe to.") . '</td></tr></table>'; |
4d5f2b31 |
342 | } |
4d5f2b31 |
343 | } else { |
32aa0074 |
344 | /* don't perform the list action -- this is much faster */ |
345 | echo addForm('folders.php') |
346 | . addHidden('smaction', 'subscribe') |
4d5f2b31 |
347 | . _("Subscribe to:") . '<br />' |
32aa0074 |
348 | . '<tt><input type="text" name="folder_names[]" size="35" />' |
4d5f2b31 |
349 | . '<input type="submit" value="'. _("Subscribe") . "\" />\n" |
350 | . "</form></td></tr></table><br />\n"; |
e634431a |
351 | } |
e634431a |
352 | } |
e7db48af |
353 | |
b7f83b61 |
354 | do_hook('folders_bottom'); |
32aa0074 |
355 | sqimap_logout($imapConnection); |
a2b193bc |
356 | |
bd9bbfef |
357 | ?> |
e7db48af |
358 | </td></tr> |
359 | </table> |
e7db48af |
360 | </td></tr> |
361 | </table> |
f8a1ed5a |
362 | </body></html> |