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); |
77 | $td_str = _("Renamed successfully!"); |
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; |
32aa0074 |
102 | } |
dcc1cc82 |
103 | |
e0c5664a |
104 | // if there are any messages, output them. |
105 | if ( !empty($td_str) ) { |
106 | echo html_tag( 'table', |
dcc1cc82 |
107 | html_tag( 'tr', |
32aa0074 |
108 | html_tag( 'td', '<b>' . $td_str . "</b><br />\n" . |
39bfea8f |
109 | '<a href="../src/left_main.php" target="left">' . |
dcc1cc82 |
110 | _("refresh folder list") . '</a>' , |
111 | 'center' ) |
112 | ) , |
113 | 'center', '', 'width="100%" cellpadding="4" cellspacing="0" border="0"' ); |
e0c5664a |
114 | } |
e634431a |
115 | } |
b7f83b61 |
116 | |
ff0969a0 |
117 | echo "\n<br />"; |
b7f83b61 |
118 | |
cedd503c |
119 | $boxes = sqimap_mailbox_list($imapConnection,true); |
e634431a |
120 | |
121 | /** CREATING FOLDERS **/ |
ac50138c |
122 | echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) . |
50ed645b |
123 | html_tag( 'tr', |
124 | html_tag( 'td', '<b>' . _("Create Folder") . '</b>', 'center', $color[9] ) |
125 | ) . |
126 | html_tag( 'tr' ) . |
127 | html_tag( 'td', '', 'center', $color[0] ) . |
32aa0074 |
128 | addForm('folders.php', 'post', 'cf'). |
129 | addHidden('smaction','create'). |
62366261 |
130 | addInput('folder_name', '', 25). |
ff0969a0 |
131 | "<br />\n". _("as a subfolder of"). '<br />'. |
132 | "<tt><select name=\"subfolder\">\n"; |
7f0a2c23 |
133 | |
45f836eb |
134 | $show_selected = array(); |
135 | $skip_folders = array(); |
7f0a2c23 |
136 | $server_type = strtolower($imap_server_type); |
137 | if ( $server_type == 'courier' ) { |
45f836eb |
138 | array_push($skip_folders, 'inbox.trash'); |
7c8b7b4f |
139 | if ( $default_folder_prefix == 'INBOX.' ) { |
99e400a4 |
140 | array_push($skip_folders, 'INBOX'); |
7c8b7b4f |
141 | } |
7f0a2c23 |
142 | } |
143 | |
144 | if ( $default_sub_of_inbox == false ) { |
ff0969a0 |
145 | echo '<option selected="selected" value="">[ '._("None")." ]</option>\n"; |
e634431a |
146 | } else { |
ff0969a0 |
147 | echo '<option value="">[ '._("None")." ]</option>\n"; |
be2d5495 |
148 | $show_selected = array('inbox'); |
149 | } |
be2d5495 |
150 | |
6e2ae264 |
151 | // Call sqimap_mailbox_option_list, using existing connection to IMAP server, |
91e0dccc |
152 | // the arrays of folders to include or skip (assembled above), |
59a8e3e8 |
153 | // use 'noinferiors' as a mailbox filter to leave out folders that can not contain other folders. |
154 | // use the long format to show subfolders in an intelligible way if parent is missing (special folder) |
155 | echo sqimap_mailbox_option_list($imapConnection, $show_selected, $skip_folders, $boxes, 'noinferiors', true); |
be2d5495 |
156 | |
ff0969a0 |
157 | echo "</select></tt>\n"; |
e634431a |
158 | if ($show_contain_subfolders_option) { |
ff0969a0 |
159 | echo '<br />'. |
62366261 |
160 | addCheckBox('contain_subs', FALSE, '1') .' ' |
b7f83b61 |
161 | . _("Let this folder contain subfolders") |
ff0969a0 |
162 | . '<br />'; |
1c52ba77 |
163 | } |
ff0969a0 |
164 | echo "<input type=\"submit\" value=\""._("Create")."\" />\n"; |
165 | echo "</form></td></tr>\n"; |
e634431a |
166 | |
50ed645b |
167 | echo html_tag( 'tr', |
168 | html_tag( 'td', ' ', 'left', $color[4] ) |
169 | ) ."\n"; |
0037f048 |
170 | |
171 | /** count special folders **/ |
74fff934 |
172 | |
173 | // FIX ME, why not check if the folders are defined IMHO move_to_sent, move_to_trash has nothing todo with it |
0037f048 |
174 | $count_special_folders = 0; |
175 | $num_max = 1; |
176 | if (strtolower($imap_server_type) == "courier" || $move_to_trash) { |
45f836eb |
177 | $num_max++; |
0037f048 |
178 | } |
179 | if ($move_to_sent) { |
45f836eb |
180 | $num_max++; |
0037f048 |
181 | } |
182 | if ($save_as_draft) { |
45f836eb |
183 | $num_max++; |
0037f048 |
184 | } |
74fff934 |
185 | |
186 | // What if move_to_sent = false and $sent_folder is set? Should it still be skipped? |
187 | |
336155db |
188 | for ($p = 0, $cnt = count($boxes); $p < $cnt && $count_special_folders < $num_max; $p++) { |
134e4174 |
189 | switch ($boxes[$p]['unformatted']) { |
190 | case (strtoupper($boxes[$p]['unformatted']) == 'INBOX'): |
191 | ++$count_special_folders; |
192 | $skip_folders[] = $boxes[$p]['unformatted']; |
193 | break; |
194 | // FIX ME inbox.trash should be set in conf.pl |
195 | case 'inbox.trash': |
196 | if (strtolower($imap_server_type) == 'courier') { |
197 | ++$count_special_folders; |
198 | } |
199 | break; |
200 | case $trash_folder: |
201 | ++$count_special_folders; |
202 | $skip_folders[] = $trash_folder; |
203 | break; |
204 | case $sent_folder: |
205 | ++$count_special_folders; |
206 | $skip_folders[] = $sent_folder; |
207 | break; |
208 | case $draft_folder: |
209 | ++$count_special_folders; |
210 | $skip_folders[] = $draft_folder; |
211 | break; |
212 | default: break; |
213 | } |
0037f048 |
214 | } |
215 | |
216 | |
e634431a |
217 | /** RENAMING FOLDERS **/ |
50ed645b |
218 | echo html_tag( 'tr', |
219 | html_tag( 'td', '<b>' . _("Rename a Folder") . '</b>', 'center', $color[9] ) |
220 | ) . |
221 | html_tag( 'tr' ) . |
222 | html_tag( 'td', '', 'center', $color[0] ); |
223 | |
32aa0074 |
224 | /* show only if we have folders to rename */ |
0037f048 |
225 | if ($count_special_folders < count($boxes)) { |
32aa0074 |
226 | echo addForm('folders.php') |
227 | . addHidden('smaction', 'rename') |
228 | . "<tt><select name=\"old_name\">\n" |
ff0969a0 |
229 | . ' <option value="">[ ' . _("Select a folder") . " ]</option>\n"; |
be2d5495 |
230 | |
91e0dccc |
231 | // use existing IMAP connection, we have no special values to show, |
59a8e3e8 |
232 | // but we do include values to skip. Use the pre-created $boxes to save an IMAP query. |
233 | // send NULL for the flag - ALL folders are eligible for rename! |
234 | // use long format to make sure folder names make sense when parents may be missing. |
235 | echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes, NULL, true); |
be2d5495 |
236 | |
ff0969a0 |
237 | echo "</select></tt>\n". |
238 | '<input type="submit" value="'. |
1c52ba77 |
239 | _("Rename"). |
ff0969a0 |
240 | "\" />\n". |
241 | "</form></td></tr>\n"; |
e634431a |
242 | } else { |
ff0969a0 |
243 | echo _("No folders found") . '<br /><br /></td></tr>'; |
e634431a |
244 | } |
e634431a |
245 | |
50ed645b |
246 | echo html_tag( 'tr', |
247 | html_tag( 'td', ' ', 'left', $color[4] ) |
248 | ) ."\n"; |
e634431a |
249 | |
250 | /** DELETING FOLDERS **/ |
50ed645b |
251 | echo html_tag( 'tr', |
252 | html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[9] ) |
253 | ) . |
254 | html_tag( 'tr' ) . |
255 | html_tag( 'td', '', 'center', $color[0] ); |
e634431a |
256 | |
32aa0074 |
257 | /* show only if we have folders to delete */ |
e634431a |
258 | if ($count_special_folders < count($boxes)) { |
32aa0074 |
259 | echo addForm('folders.php') |
260 | . addHidden('smaction', 'delete') |
261 | . "<tt><select name=\"folder_name\">\n" |
ff0969a0 |
262 | . ' <option value="">[ ' . _("Select a folder") . " ]</option>\n"; |
be2d5495 |
263 | |
59a8e3e8 |
264 | // send NULL for the flag - ALL folders are eligible for delete (except what we've got in skiplist) |
265 | // use long format to make sure folder names make sense when parents may be missing. |
266 | echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes, NULL, true); |
be2d5495 |
267 | |
ff0969a0 |
268 | echo "</select></tt>\n" |
269 | . '<input type="submit" value="' |
b7f83b61 |
270 | . _("Delete") |
ff0969a0 |
271 | . "\" />\n" |
b7f83b61 |
272 | . "</form></td></tr>\n"; |
e634431a |
273 | } else { |
ff0969a0 |
274 | echo _("No folders found") . "<br /><br /></td></tr>"; |
e634431a |
275 | } |
50ed645b |
276 | |
277 | echo html_tag( 'tr', |
278 | html_tag( 'td', ' ', 'left', $color[4] ) |
279 | ) ."</table>\n"; |
280 | |
e634431a |
281 | |
4d5f2b31 |
282 | if ($show_only_subscribed_folders) { |
50ed645b |
283 | |
4d5f2b31 |
284 | /** UNSUBSCRIBE FOLDERS **/ |
285 | echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) . |
286 | html_tag( 'tr', |
287 | html_tag( 'td', '<b>' . _("Unsubscribe") . '/' . _("Subscribe") . '</b>', 'center', $color[9], 'colspan="2"' ) |
288 | ) . |
289 | html_tag( 'tr' ) . |
290 | html_tag( 'td', '', 'center', $color[0], 'width="50%"' ); |
291 | |
292 | if ($count_special_folders < count($boxes)) { |
32aa0074 |
293 | echo addForm('folders.php') |
294 | . addHidden('smaction', 'unsubscribe') |
295 | . "<tt><select name=\"folder_names[]\" multiple=\"multiple\" size=\"8\">\n"; |
296 | foreach ( $boxes as $box ) { |
4d5f2b31 |
297 | $use_folder = true; |
32aa0074 |
298 | if ((strtolower($box["unformatted"]) != "inbox") && |
299 | ($box['unformatted'] != $trash_folder) && |
300 | ($box['unformatted'] != $sent_folder) && |
301 | ($box['unformatted'] != $draft_folder)) { |
302 | $box_enc = htmlspecialchars($box['unformatted-dm']); |
303 | $box_disp = str_replace(' ', ' ', |
304 | htmlspecialchars(imap_utf7_decode_local($box["unformatted-disp"]))); |
305 | echo " <option value=\"$box_enc\">$box_disp</option>\n"; |
4d5f2b31 |
306 | } |
307 | } |
308 | echo "</select></tt><br /><br />\n" |
309 | . '<input type="submit" value="' |
310 | . _("Unsubscribe") |
311 | . "\" />\n" |
312 | . "</form></td>\n"; |
313 | } else { |
314 | echo _("No folders were found to unsubscribe from!") . '</td>'; |
e634431a |
315 | } |
4d5f2b31 |
316 | |
317 | /** SUBSCRIBE TO FOLDERS **/ |
318 | echo html_tag( 'td', '', 'center', $color[0], 'width="50%"' ); |
319 | if(!$no_list_for_subscribe) { |
32aa0074 |
320 | $boxes_all = sqimap_mailbox_list_all ($imapConnection); |
321 | |
322 | $subboxes = array(); |
323 | // here we filter out all boxes we're already subscribed to, |
324 | // so we keep only the unsubscribed ones. |
325 | foreach ($boxes_all as $box_a) { |
326 | |
327 | $use_folder = true; |
328 | foreach ( $boxes as $box ) { |
329 | if ($box_a['unformatted'] == $box['unformatted'] || |
330 | $box_a['unformatted-dm'] == $folder_prefix ) { |
331 | $use_folder = false; |
332 | } |
333 | } |
334 | |
335 | if ($use_folder == true) { |
336 | $box_enc = htmlspecialchars($box_a['unformatted-dm']); |
337 | $box_disp = htmlspecialchars(imap_utf7_decode_local($box_a['unformatted-disp'])); |
338 | $subboxes[$box_enc] = $box_disp; |
4d5f2b31 |
339 | } |
340 | } |
32aa0074 |
341 | |
342 | if ( count($subboxes) > 0 ) { |
343 | echo addForm('folders.php') |
344 | . addHidden('smaction', 'subscribe') |
345 | . '<tt><select name="folder_names[]" multiple="multiple" size="8">'; |
346 | |
347 | foreach($subboxes as $subbox_enc => $subbox_disp) { |
348 | echo ' <option value="' . $subbox_enc . '">'.$subbox_disp."</option>\n"; |
349 | } |
e634431a |
350 | |
32aa0074 |
351 | echo '</select></tt><br /><br />' |
352 | . '<input type="submit" value="'. _("Subscribe") . "\" />\n" |
353 | . "</form></td></tr></table><br />\n"; |
354 | } else { |
355 | echo _("No folders were found to subscribe to.") . '</td></tr></table>'; |
4d5f2b31 |
356 | } |
4d5f2b31 |
357 | } else { |
32aa0074 |
358 | /* don't perform the list action -- this is much faster */ |
359 | echo addForm('folders.php') |
360 | . addHidden('smaction', 'subscribe') |
4d5f2b31 |
361 | . _("Subscribe to:") . '<br />' |
32aa0074 |
362 | . '<tt><input type="text" name="folder_names[]" size="35" />' |
4d5f2b31 |
363 | . '<input type="submit" value="'. _("Subscribe") . "\" />\n" |
364 | . "</form></td></tr></table><br />\n"; |
e634431a |
365 | } |
e634431a |
366 | } |
e7db48af |
367 | |
b7f83b61 |
368 | do_hook('folders_bottom'); |
32aa0074 |
369 | sqimap_logout($imapConnection); |
bd9bbfef |
370 | ?> |
e7db48af |
371 | </td></tr> |
372 | </table> |
e7db48af |
373 | </td></tr> |
374 | </table> |
4d5f2b31 |
375 | </body></html> |