59177427 |
1 | <?php |
895905c0 |
2 | |
35586184 |
3 | /** |
4 | * folders.php |
5 | * |
82d304a0 |
6 | * Copyright (c) 1999-2004 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'); |
86725763 |
26 | require_once(SM_PATH . 'functions/plugin.php'); |
27 | require_once(SM_PATH . 'functions/html.php'); |
62366261 |
28 | require_once(SM_PATH . 'functions/forms.php'); |
d3cdb279 |
29 | |
e634431a |
30 | displayPageHeader($color, 'None'); |
aa42fbfb |
31 | |
a32985a5 |
32 | /* get globals we may need */ |
33 | |
f38b7cf0 |
34 | sqgetGlobalVar('username', $username, SQ_SESSION); |
35 | sqgetGlobalVar('key', $key, SQ_COOKIE); |
36 | sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION); |
37 | sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION); |
38 | |
39 | sqgetGlobalVar('success', $success, SQ_GET); |
a32985a5 |
40 | |
41 | /* end of get globals */ |
42 | |
2441907d |
43 | echo '<br>' . |
6206f6c4 |
44 | html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) . |
2441907d |
45 | html_tag( 'tr' ) . |
46 | html_tag( 'td', '', 'center' ) . '<b>' . _("Folders") . '</b>' . |
47 | html_tag( 'table', '', 'center', '', 'width="100%" cellpadding="5" cellspacing="0" border="0"' ) . |
48 | html_tag( 'tr' ) . |
49 | html_tag( 'td', '', 'center', $color[4] ); |
aa42fbfb |
50 | |
b7f83b61 |
51 | if ( isset($success) && $success ) { |
52 | |
53 | $td_str = '<b>'; |
54 | |
55 | switch ($success) |
56 | { |
57 | case 'subscribe': |
58 | $td_str .= _("Subscribed successfully!"); |
59 | break; |
60 | case 'unsubscribe': |
61 | $td_str .= _("Unsubscribed successfully!"); |
62 | break; |
63 | case 'delete': |
64 | $td_str .= _("Deleted folder successfully!"); |
65 | break; |
66 | case 'create': |
67 | $td_str .= _("Created folder successfully!"); |
68 | break; |
69 | case 'rename': |
70 | $td_str .= _("Renamed successfully!"); |
71 | break; |
72 | case 'subscribe-doesnotexist': |
73 | $td_str .= _("Subscription Unsuccessful - Folder does not exist."); |
74 | break; |
e634431a |
75 | } |
76 | |
b7f83b61 |
77 | $td_str .= '</b><br>'; |
78 | |
dcc1cc82 |
79 | |
80 | echo html_tag( 'table', |
81 | html_tag( 'tr', |
82 | html_tag( 'td', $td_str . |
83 | '<a href="../src/left_main.php" target=left>' . |
84 | _("refresh folder list") . '</a>' , |
85 | 'center' ) |
86 | ) , |
87 | 'center', '', 'width="100%" cellpadding="4" cellspacing="0" border="0"' ); |
e634431a |
88 | } |
b7f83b61 |
89 | |
90 | echo "\n<br>"; |
91 | |
e634431a |
92 | $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0); |
cedd503c |
93 | $boxes = sqimap_mailbox_list($imapConnection,true); |
e634431a |
94 | |
95 | /** CREATING FOLDERS **/ |
ac50138c |
96 | echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) . |
50ed645b |
97 | html_tag( 'tr', |
98 | html_tag( 'td', '<b>' . _("Create Folder") . '</b>', 'center', $color[9] ) |
99 | ) . |
100 | html_tag( 'tr' ) . |
101 | html_tag( 'td', '', 'center', $color[0] ) . |
62366261 |
102 | addForm('folders_create.php', 'POST', 'cf'). |
103 | addInput('folder_name', '', 25). |
104 | "<BR>\n". _("as a subfolder of"). '<BR>'. |
1c52ba77 |
105 | "<TT><SELECT NAME=subfolder>\n"; |
7f0a2c23 |
106 | |
45f836eb |
107 | $show_selected = array(); |
108 | $skip_folders = array(); |
7f0a2c23 |
109 | $server_type = strtolower($imap_server_type); |
110 | if ( $server_type == 'courier' ) { |
45f836eb |
111 | array_push($skip_folders, 'inbox.trash'); |
7c8b7b4f |
112 | if ( $default_folder_prefix == 'INBOX.' ) { |
113 | array_push($skip_folders, 'inbox'); |
114 | } |
7f0a2c23 |
115 | } |
116 | |
117 | if ( $default_sub_of_inbox == false ) { |
e634431a |
118 | echo '<OPTION SELECTED VALUE="">[ '._("None")." ]\n"; |
119 | } else { |
120 | echo '<OPTION VALUE="">[ '._("None")." ]\n"; |
be2d5495 |
121 | $show_selected = array('inbox'); |
122 | } |
be2d5495 |
123 | |
6e2ae264 |
124 | // Call sqimap_mailbox_option_list, using existing connection to IMAP server, |
125 | // the arrays of folders to include or skip (assembled above), |
59a8e3e8 |
126 | // use 'noinferiors' as a mailbox filter to leave out folders that can not contain other folders. |
127 | // use the long format to show subfolders in an intelligible way if parent is missing (special folder) |
128 | echo sqimap_mailbox_option_list($imapConnection, $show_selected, $skip_folders, $boxes, 'noinferiors', true); |
be2d5495 |
129 | |
e634431a |
130 | echo "</SELECT></TT>\n"; |
131 | if ($show_contain_subfolders_option) { |
62366261 |
132 | echo '<br>'. |
133 | addCheckBox('contain_subs', FALSE, '1') .' ' |
b7f83b61 |
134 | . _("Let this folder contain subfolders") |
135 | . '<BR>'; |
1c52ba77 |
136 | } |
6b4bd11f |
137 | echo "<input type=SUBMIT VALUE=\""._("Create")."\">\n"; |
138 | echo "</FORM></td></tr>\n"; |
e634431a |
139 | |
50ed645b |
140 | echo html_tag( 'tr', |
141 | html_tag( 'td', ' ', 'left', $color[4] ) |
142 | ) ."\n"; |
0037f048 |
143 | |
144 | /** count special folders **/ |
74fff934 |
145 | |
146 | // FIX ME, why not check if the folders are defined IMHO move_to_sent, move_to_trash has nothing todo with it |
0037f048 |
147 | $count_special_folders = 0; |
148 | $num_max = 1; |
149 | if (strtolower($imap_server_type) == "courier" || $move_to_trash) { |
45f836eb |
150 | $num_max++; |
0037f048 |
151 | } |
152 | if ($move_to_sent) { |
45f836eb |
153 | $num_max++; |
0037f048 |
154 | } |
155 | if ($save_as_draft) { |
45f836eb |
156 | $num_max++; |
0037f048 |
157 | } |
74fff934 |
158 | |
159 | // What if move_to_sent = false and $sent_folder is set? Should it still be skipped? |
160 | |
336155db |
161 | for ($p = 0, $cnt = count($boxes); $p < $cnt && $count_special_folders < $num_max; $p++) { |
74fff934 |
162 | switch ($boxes[$p]['unformatted']) |
163 | { |
164 | case (strtoupper($boxes[$p]['unformatted']) == 'INBOX'): |
165 | ++$count_special_folders; |
166 | $skip_folders[] = $boxes[$p]['unformatted']; |
167 | break; |
168 | // FIX ME inbox.trash should be set in conf.pl |
169 | case 'inbox.trash': |
170 | if (strtolower($imap_server_type) == 'courier') { |
171 | ++$count_special_folders; |
172 | } |
173 | break; |
174 | case $trash_folder: |
175 | ++$count_special_folders; |
176 | $skip_folders[] = $trash_folder; |
177 | break; |
178 | case $sent_folder: |
179 | ++$count_special_folders; |
180 | $skip_folders[] = $sent_folder; |
181 | break; |
182 | case $draft_folder: |
183 | ++$count_special_folders; |
184 | $skip_folders[] = $draft_folder; |
185 | break; |
186 | default: break; |
187 | } |
0037f048 |
188 | } |
189 | |
190 | |
e634431a |
191 | /** RENAMING FOLDERS **/ |
50ed645b |
192 | echo html_tag( 'tr', |
193 | html_tag( 'td', '<b>' . _("Rename a Folder") . '</b>', 'center', $color[9] ) |
194 | ) . |
195 | html_tag( 'tr' ) . |
196 | html_tag( 'td', '', 'center', $color[0] ); |
197 | |
0037f048 |
198 | if ($count_special_folders < count($boxes)) { |
62366261 |
199 | echo addForm('folders_rename_getname.php') |
0037f048 |
200 | . "<TT><SELECT NAME=old>\n" |
201 | . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n"; |
be2d5495 |
202 | |
59a8e3e8 |
203 | // use existing IMAP connection, we have no special values to show, |
204 | // but we do include values to skip. Use the pre-created $boxes to save an IMAP query. |
205 | // send NULL for the flag - ALL folders are eligible for rename! |
206 | // use long format to make sure folder names make sense when parents may be missing. |
207 | echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes, NULL, true); |
be2d5495 |
208 | |
1c52ba77 |
209 | echo "</SELECT></TT>\n". |
6b4bd11f |
210 | "<input type=SUBMIT VALUE=\"". |
1c52ba77 |
211 | _("Rename"). |
212 | "\">\n". |
50ed645b |
213 | "</FORM></td></tr>\n"; |
e634431a |
214 | } else { |
b7f83b61 |
215 | echo _("No folders found") . '<br><br></td></tr>'; |
e634431a |
216 | } |
217 | $boxes_sub = $boxes; |
218 | |
50ed645b |
219 | echo html_tag( 'tr', |
220 | html_tag( 'td', ' ', 'left', $color[4] ) |
221 | ) ."\n"; |
e634431a |
222 | |
223 | /** DELETING FOLDERS **/ |
50ed645b |
224 | echo html_tag( 'tr', |
225 | html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[9] ) |
226 | ) . |
227 | html_tag( 'tr' ) . |
228 | html_tag( 'td', '', 'center', $color[0] ); |
e634431a |
229 | |
e634431a |
230 | if ($count_special_folders < count($boxes)) { |
62366261 |
231 | echo addForm('folders_delete.php') |
0037f048 |
232 | . "<TT><SELECT NAME=mailbox>\n" |
233 | . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n"; |
be2d5495 |
234 | |
59a8e3e8 |
235 | // send NULL for the flag - ALL folders are eligible for delete (except what we've got in skiplist) |
236 | // use long format to make sure folder names make sense when parents may be missing. |
237 | echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes, NULL, true); |
be2d5495 |
238 | |
b7f83b61 |
239 | echo "</SELECT></TT>\n" |
240 | . '<input type=SUBMIT VALUE="' |
241 | . _("Delete") |
242 | . "\">\n" |
243 | . "</form></td></tr>\n"; |
e634431a |
244 | } else { |
6b4bd11f |
245 | echo _("No folders found") . "<br><br></td></tr>"; |
e634431a |
246 | } |
50ed645b |
247 | |
248 | echo html_tag( 'tr', |
249 | html_tag( 'td', ' ', 'left', $color[4] ) |
250 | ) ."</table>\n"; |
251 | |
e634431a |
252 | |
253 | /** UNSUBSCRIBE FOLDERS **/ |
12ff1cab |
254 | echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) . |
50ed645b |
255 | html_tag( 'tr', |
256 | html_tag( 'td', '<b>' . _("Unsubscribe") . '/' . _("Subscribe") . '</b>', 'center', $color[9], 'colspan="2"' ) |
257 | ) . |
258 | html_tag( 'tr' ) . |
259 | html_tag( 'td', '', 'center', $color[0], 'width="50%"' ); |
260 | |
e634431a |
261 | if ($count_special_folders < count($boxes)) { |
62366261 |
262 | echo addForm('folders_subscribe.php?method=unsub') |
b7f83b61 |
263 | . "<TT><SELECT NAME=\"mailbox[]\" multiple size=8>\n"; |
e634431a |
264 | for ($i = 0; $i < count($boxes); $i++) { |
265 | $use_folder = true; |
266 | if ((strtolower($boxes[$i]["unformatted"]) != "inbox") && |
267 | ($boxes[$i]["unformatted"] != $trash_folder) && |
268 | ($boxes[$i]["unformatted"] != $sent_folder) && |
269 | ($boxes[$i]["unformatted"] != $draft_folder)) { |
0cf258ae |
270 | $box = htmlspecialchars($boxes[$i]["unformatted-dm"]); |
46bc57c1 |
271 | $box2 = str_replace(' ', ' ', |
a722a461 |
272 | htmlspecialchars(imap_utf7_decode_local($boxes[$i]["unformatted-disp"]))); |
e634431a |
273 | echo " <OPTION VALUE=\"$box\">$box2\n"; |
274 | } |
275 | } |
b7f83b61 |
276 | echo "</SELECT></TT><br><br>\n" |
277 | . '<input type=SUBMIT VALUE="' |
278 | . _("Unsubscribe") |
279 | . "\">\n" |
280 | . "</FORM></td>\n"; |
e634431a |
281 | } else { |
b7f83b61 |
282 | echo _("No folders were found to unsubscribe from!") . '</td>'; |
e634431a |
283 | } |
284 | $boxes_sub = $boxes; |
285 | |
286 | /** SUBSCRIBE TO FOLDERS **/ |
50ed645b |
287 | echo html_tag( 'td', '', 'center', $color[0], 'width="50%"' ); |
52ed2f88 |
288 | if(!$no_list_for_subscribe) { |
336155db |
289 | $boxes_all = sqimap_mailbox_list_all ($imapConnection); |
52ed2f88 |
290 | |
b7f83b61 |
291 | $box = ''; |
292 | $box2 = ''; |
52ed2f88 |
293 | for ($i = 0, $q = 0; $i < count($boxes_all); $i++) { |
e634431a |
294 | $use_folder = true; |
295 | for ($p = 0; $p < count ($boxes); $p++) { |
b7f83b61 |
296 | if ($boxes_all[$i]['unformatted'] == $boxes[$p]['unformatted']) { |
e634431a |
297 | $use_folder = false; |
298 | continue; |
b7f83b61 |
299 | } else if ($boxes_all[$i]['unformatted-dm'] == $folder_prefix) { |
e634431a |
300 | $use_folder = false; |
301 | } |
302 | } |
7e235a1a |
303 | if ($use_folder == true) { |
0cf258ae |
304 | $box[$q] = htmlspecialchars($boxes_all[$i]['unformatted-dm']); |
a722a461 |
305 | $box2[$q] = htmlspecialchars(imap_utf7_decode_local($boxes_all[$i]['unformatted-disp'])); |
e634431a |
306 | $q++; |
307 | } |
52ed2f88 |
308 | } |
52ed2f88 |
309 | if ($box && $box2) { |
62366261 |
310 | echo addForm('folders_subscribe.php?method=sub') |
b7f83b61 |
311 | . '<tt><select name="mailbox[]" multiple size=8>'; |
e634431a |
312 | |
313 | for ($q = 0; $q < count($box); $q++) { |
314 | echo " <OPTION VALUE=\"$box[$q]\">".$box2[$q]."\n"; |
315 | } |
b7f83b61 |
316 | echo '</select></tt><br><br>' |
317 | . '<input type=SUBMIT VALUE="'. _("Subscribe") . "\">\n" |
318 | . "</FORM></td></tr></table><BR>\n"; |
52ed2f88 |
319 | } else { |
b7f83b61 |
320 | echo _("No folders were found to subscribe to!") . '</td></tr></table>'; |
52ed2f88 |
321 | } |
322 | } else { |
323 | /* don't perform the list action -- this is much faster */ |
62366261 |
324 | echo addForm('folders_subscribe.php?method=sub') |
b7f83b61 |
325 | . _("Subscribe to:") . '<br>' |
326 | . '<tt><input type="text" name="mailbox[]" size=35>' |
327 | . '<INPUT TYPE=SUBMIT VALUE="'. _("Subscribe") . "\">\n" |
328 | . "</FORM></TD></TR></TABLE><BR>\n"; |
e634431a |
329 | } |
e7db48af |
330 | |
b7f83b61 |
331 | do_hook('folders_bottom'); |
bd9bbfef |
332 | ?> |
e7db48af |
333 | |
e7db48af |
334 | </td></tr> |
335 | </table> |
336 | |
337 | </td></tr> |
338 | </table> |
339 | |
340 | <?php |
1195c340 |
341 | sqimap_logout($imapConnection); |
dcc1cc82 |
342 | ?> |
343 | |
344 | </body></html> |