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