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