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