removed local directory name used for testing.
[squirrelmail.git] / src / folders.php
1 <?php
2
3 /**
4 * folders.php
5 *
6 * Copyright (c) 1999-2005 The SquirrelMail Project Team
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 * @version $Id$
14 * @package squirrelmail
15 */
16
17 /**
18 * Path for SquirrelMail required files.
19 * @ignore
20 */
21 define('SM_PATH','../');
22
23 /* SquirrelMail required files. */
24 require_once(SM_PATH . 'include/validate.php');
25 require_once(SM_PATH . 'functions/imap.php');
26 require_once(SM_PATH . 'functions/folder_manip.php');
27 require_once(SM_PATH . 'functions/plugin.php');
28 require_once(SM_PATH . 'functions/html.php');
29 require_once(SM_PATH . 'functions/forms.php');
30
31 displayPageHeader($color, 'None');
32
33 /* get globals we may need */
34
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
40 sqgetGlobalVar('smaction', $action, SQ_POST);
41
42 /* end of get globals */
43
44 echo '<br />' .
45 html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) .
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] );
51
52 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
53
54 /* switch to the right function based on what the user selected */
55 if ( sqgetGlobalVar('smaction', $action, SQ_POST) ) {
56
57 switch ($action)
58 {
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.");
65 break;
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 }
79 break;
80 case 'delete':
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 }
91 break;
92 case 'subscribe':
93 sqgetGlobalVar('folder_names', $folder_names, SQ_POST);
94 folders_subscribe($imapConnection, $folder_names);
95 $td_str = _("Subscribed successfully.");
96 break;
97 case 'unsubscribe':
98 sqgetGlobalVar('folder_names', $folder_names, SQ_POST);
99 folders_unsubscribe($imapConnection, $folder_names);
100 $td_str = _("Unsubscribed successfully.");
101 break;
102 default:
103 // TODO: add hook for plugin action processing.
104 $td_str = '';
105 break;
106 }
107
108 // if there are any messages, output them.
109 if ( !empty($td_str) ) {
110 echo html_tag( 'table',
111 html_tag( 'tr',
112 html_tag( 'td', '<b>' . $td_str . "</b><br />\n" .
113 '<a href="../src/left_main.php" target="left">' .
114 _("refresh folder list") . '</a>' ,
115 'center' )
116 ) ,
117 'center', '', 'width="100%" cellpadding="4" cellspacing="0" border="0"' );
118 }
119 }
120
121 echo "\n<br />";
122
123 $boxes = sqimap_mailbox_list($imapConnection,true);
124
125 /** CREATING FOLDERS **/
126 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
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] ) .
132 addForm('folders.php', 'post', 'cf').
133 addHidden('smaction','create').
134 addInput('folder_name', '', 25).
135 "<br />\n". _("as a subfolder of"). '<br />'.
136 "<tt><select name=\"subfolder\">\n";
137
138 $show_selected = array();
139 $skip_folders = array();
140 $server_type = strtolower($imap_server_type);
141
142 // Special handling for courier
143 if ( $server_type == 'courier' ) {
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 }
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 }
162 }
163
164 if ( $default_sub_of_inbox == false ) {
165 echo '<option selected="selected" value="">[ '._("None")." ]</option>\n";
166 } else {
167 echo '<option value="">[ '._("None")." ]</option>\n";
168 $show_selected = array('inbox');
169 }
170
171 // Call sqimap_mailbox_option_list, using existing connection to IMAP server,
172 // the arrays of folders to include or skip (assembled above),
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);
176
177 echo "</select></tt>\n";
178 if ($show_contain_subfolders_option) {
179 echo '<br />'.
180 addCheckBox('contain_subs', FALSE, '1') .' &nbsp;'
181 . _("Let this folder contain subfolders")
182 . '<br />';
183 }
184 echo "<input type=\"submit\" value=\""._("Create")."\" />\n";
185 echo "</form></td></tr>\n";
186
187 echo html_tag( 'tr',
188 html_tag( 'td', '&nbsp;', 'left', $color[4] )
189 ) ."\n";
190
191 /** count special folders **/
192 foreach ($boxes as $index => $aBoxData) {
193 if (isSpecialMailbox($aBoxData['unformatted']) &&
194 ! in_array($aBoxData['unformatted'],$skip_folders)) {
195 $skip_folders[] = $aBoxData['unformatted'];
196 }
197 }
198
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);
211
212 /** RENAMING FOLDERS **/
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
219 /* show only if we have folders to rename */
220 if (! empty($filtered_folders)) {
221 echo addForm('folders.php')
222 . addHidden('smaction', 'rename')
223 . "<tt><select name=\"old_name\">\n"
224 . ' <option value="">[ ' . _("Select a folder") . " ]</option>\n";
225
226 // use existing IMAP connection, we have no special values to show,
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.
230 echo $filtered_folders;
231
232 echo "</select></tt>\n".
233 '<input type="submit" value="'.
234 _("Rename").
235 "\" />\n".
236 "</form></td></tr>\n";
237 } else {
238 echo _("No folders found") . '<br /><br /></td></tr>';
239 }
240
241 echo html_tag( 'tr',
242 html_tag( 'td', '&nbsp;', 'left', $color[4] )
243 ) ."\n";
244
245 /** DELETING FOLDERS **/
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] );
251
252 /* show only if we have folders to delete */
253 if (!empty($filtered_folders)) {
254 echo addForm('folders.php')
255 . addHidden('smaction', 'delete')
256 . "<tt><select name=\"folder_name\">\n"
257 . ' <option value="">[ ' . _("Select a folder") . " ]</option>\n";
258
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.
261 echo $filtered_folders;
262
263 echo "</select></tt>\n"
264 . '<input type="submit" value="'
265 . _("Delete")
266 . "\" />\n"
267 . "</form></td></tr>\n";
268 } else {
269 echo _("No folders found") . "<br /><br /></td></tr>";
270 }
271
272 echo html_tag( 'tr',
273 html_tag( 'td', '&nbsp;', 'left', $color[4] )
274 ) ."</table>\n";
275
276
277 if ($show_only_subscribed_folders) {
278 // FIXME: fix subscription options when top folder is not subscribed and sub folder is subscribed
279 // TODO: use checkboxes instead of select options.
280
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
289 if (!empty($filtered_folders)) {
290 echo addForm('folders.php')
291 . addHidden('smaction', 'unsubscribe')
292 . "<tt><select name=\"folder_names[]\" multiple=\"multiple\" size=\"8\">\n"
293 . $filtered_folders
294 . "</select></tt><br /><br />\n"
295 . '<input type="submit" value="'
296 . _("Unsubscribe")
297 . "\" />\n"
298 . "</form></td>\n";
299 } else {
300 echo _("No folders were found to unsubscribe from.") . '</td>';
301 }
302
303 /** SUBSCRIBE TO FOLDERS **/
304 echo html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
305 if(!$no_list_for_subscribe) {
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) {
312
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 }
320
321 if ($use_folder == true) {
322 $box_enc = htmlspecialchars($box_a['unformatted-dm']);
323 $box_disp = htmlspecialchars(imap_utf7_decode_local($box_a['unformatted-disp']));
324 $subboxes[$box_enc] = $box_disp;
325 }
326 }
327
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 }
336
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>';
342 }
343 } else {
344 /* don't perform the list action -- this is much faster */
345 echo addForm('folders.php')
346 . addHidden('smaction', 'subscribe')
347 . _("Subscribe to:") . '<br />'
348 . '<tt><input type="text" name="folder_names[]" size="35" />'
349 . '<input type="submit" value="'. _("Subscribe") . "\" />\n"
350 . "</form></td></tr></table><br />\n";
351 }
352 }
353
354 do_hook('folders_bottom');
355 sqimap_logout($imapConnection);
356
357 ?>
358 </td></tr>
359 </table>
360 </td></tr>
361 </table>
362 </body></html>