Added tis-620 decoding
[squirrelmail.git] / src / folders.php
CommitLineData
59177427 1<?php
895905c0 2
35586184 3/**
4 * folders.php
5 *
76911253 6 * Copyright (c) 1999-2003 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$
14 */
15
86725763 16/* Path for SquirrelMail required files. */
17define('SM_PATH','../');
18
19/* SquirrelMail required files. */
08185f2a 20require_once(SM_PATH . 'include/validate.php');
86725763 21require_once(SM_PATH . 'functions/imap.php');
86725763 22require_once(SM_PATH . 'functions/plugin.php');
23require_once(SM_PATH . 'functions/html.php');
d3cdb279 24
e634431a 25displayPageHeader($color, 'None');
aa42fbfb 26
a32985a5 27/* get globals we may need */
28
f38b7cf0 29sqgetGlobalVar('username', $username, SQ_SESSION);
30sqgetGlobalVar('key', $key, SQ_COOKIE);
31sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
32sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
33
34sqgetGlobalVar('success', $success, SQ_GET);
a32985a5 35
36/* end of get globals */
37
2441907d 38echo '<br>' .
6206f6c4 39 html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) .
2441907d 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] );
aa42fbfb 45
b7f83b61 46if ( 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;
e634431a 70 }
71
b7f83b61 72 $td_str .= '</b><br>';
73
74
50ed645b 75 echo html_tag( 'table',
76 html_tag( 'tr',
77 html_tag( 'td', $td_str .
b7f83b61 78 '<a href="../src/left_main.php" target=left>' .
79 _("refresh folder list") . '</a>' ,
50ed645b 80 'center' )
81 ) ,
b7f83b61 82 'center', '', 'width="100%" cellpadding="4" cellspacing="0" border="0"' );
e634431a 83}
b7f83b61 84
85echo "\n<br>";
86
e634431a 87$imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
88$boxes = sqimap_mailbox_list($imapConnection);
89
90/** CREATING FOLDERS **/
ac50138c 91echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
50ed645b 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
1c52ba77 98 "<FORM NAME=cf ACTION=\"folders_create.php\" METHOD=\"POST\">\n".
6b4bd11f 99 "<input type=TEXT SIZE=25 NAME=folder_name><BR>\n".
1c52ba77 100 _("as a subfolder of").
b7f83b61 101 '<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);
107if ( $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
114if ( $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)
125echo sqimap_mailbox_option_list($imapConnection, $show_selected, $skip_folders, $boxes, 'noinferiors', true);
be2d5495 126
e634431a 127echo "</SELECT></TT>\n";
128if ($show_contain_subfolders_option) {
b7f83b61 129 echo '<br><input type=CHECKBOX NAME="contain_subs"> &nbsp;'
130 . _("Let this folder contain subfolders")
131 . '<BR>';
1c52ba77 132}
6b4bd11f 133echo "<input type=SUBMIT VALUE=\""._("Create")."\">\n";
134echo "</FORM></td></tr>\n";
e634431a 135
50ed645b 136echo html_tag( 'tr',
137 html_tag( 'td', '&nbsp;', 'left', $color[4] )
138 ) ."\n";
0037f048 139
140/** count special folders **/
74fff934 141
142// FIX ME, why not check if the folders are defined IMHO move_to_sent, move_to_trash has nothing todo with it
0037f048 143$count_special_folders = 0;
144$num_max = 1;
145if (strtolower($imap_server_type) == "courier" || $move_to_trash) {
45f836eb 146 $num_max++;
0037f048 147}
148if ($move_to_sent) {
45f836eb 149 $num_max++;
0037f048 150}
151if ($save_as_draft) {
45f836eb 152 $num_max++;
0037f048 153}
74fff934 154
155// What if move_to_sent = false and $sent_folder is set? Should it still be skipped?
156
336155db 157for ($p = 0, $cnt = count($boxes); $p < $cnt && $count_special_folders < $num_max; $p++) {
74fff934 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 }
0037f048 184}
185
186
e634431a 187/** RENAMING FOLDERS **/
50ed645b 188echo 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
0037f048 194if ($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";
be2d5495 198
59a8e3e8 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);
be2d5495 204
1c52ba77 205 echo "</SELECT></TT>\n".
6b4bd11f 206 "<input type=SUBMIT VALUE=\"".
1c52ba77 207 _("Rename").
208 "\">\n".
50ed645b 209 "</FORM></td></tr>\n";
e634431a 210} else {
b7f83b61 211 echo _("No folders found") . '<br><br></td></tr>';
e634431a 212}
213$boxes_sub = $boxes;
214
50ed645b 215echo html_tag( 'tr',
216 html_tag( 'td', '&nbsp;', 'left', $color[4] )
217 ) ."\n";
e634431a 218
219/** DELETING FOLDERS **/
50ed645b 220echo 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] );
e634431a 225
e634431a 226if ($count_special_folders < count($boxes)) {
0037f048 227 echo "<FORM ACTION=\"folders_delete.php\" METHOD=\"POST\">\n"
228 . "<TT><SELECT NAME=mailbox>\n"
229 . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
be2d5495 230
59a8e3e8 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);
be2d5495 234
b7f83b61 235 echo "</SELECT></TT>\n"
236 . '<input type=SUBMIT VALUE="'
237 . _("Delete")
238 . "\">\n"
239 . "</form></td></tr>\n";
e634431a 240} else {
6b4bd11f 241 echo _("No folders found") . "<br><br></td></tr>";
e634431a 242}
50ed645b 243
244echo html_tag( 'tr',
245 html_tag( 'td', '&nbsp;', 'left', $color[4] )
246 ) ."</table>\n";
247
e634431a 248
249/** UNSUBSCRIBE FOLDERS **/
12ff1cab 250echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
50ed645b 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
e634431a 257if ($count_special_folders < count($boxes)) {
b7f83b61 258 echo "<FORM ACTION=\"folders_subscribe.php?method=unsub\" METHOD=\"POST\">\n"
259 . "<TT><SELECT NAME=\"mailbox[]\" multiple size=8>\n";
e634431a 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)) {
0cf258ae 266 $box = htmlspecialchars($boxes[$i]["unformatted-dm"]);
46bc57c1 267 $box2 = str_replace(' ', '&nbsp;',
0cf258ae 268 htmlentities(imap_utf7_decode_local($boxes[$i]["unformatted-disp"])));
e634431a 269 echo " <OPTION VALUE=\"$box\">$box2\n";
270 }
271 }
b7f83b61 272 echo "</SELECT></TT><br><br>\n"
273 . '<input type=SUBMIT VALUE="'
274 . _("Unsubscribe")
275 . "\">\n"
276 . "</FORM></td>\n";
e634431a 277} else {
b7f83b61 278 echo _("No folders were found to unsubscribe from!") . '</td>';
e634431a 279}
280$boxes_sub = $boxes;
281
282/** SUBSCRIBE TO FOLDERS **/
50ed645b 283echo html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
52ed2f88 284if(!$no_list_for_subscribe) {
336155db 285 $boxes_all = sqimap_mailbox_list_all ($imapConnection);
52ed2f88 286
b7f83b61 287 $box = '';
288 $box2 = '';
52ed2f88 289 for ($i = 0, $q = 0; $i < count($boxes_all); $i++) {
e634431a 290 $use_folder = true;
291 for ($p = 0; $p < count ($boxes); $p++) {
b7f83b61 292 if ($boxes_all[$i]['unformatted'] == $boxes[$p]['unformatted']) {
e634431a 293 $use_folder = false;
294 continue;
b7f83b61 295 } else if ($boxes_all[$i]['unformatted-dm'] == $folder_prefix) {
e634431a 296 $use_folder = false;
297 }
298 }
7e235a1a 299 if ($use_folder == true) {
0cf258ae 300 $box[$q] = htmlspecialchars($boxes_all[$i]['unformatted-dm']);
301 $box2[$q] = htmlentities(imap_utf7_decode_local($boxes_all[$i]['unformatted-disp']));
e634431a 302 $q++;
303 }
52ed2f88 304 }
52ed2f88 305 if ($box && $box2) {
b7f83b61 306 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n"
307 . '<tt><select name="mailbox[]" multiple size=8>';
e634431a 308
309 for ($q = 0; $q < count($box); $q++) {
310 echo " <OPTION VALUE=\"$box[$q]\">".$box2[$q]."\n";
311 }
b7f83b61 312 echo '</select></tt><br><br>'
313 . '<input type=SUBMIT VALUE="'. _("Subscribe") . "\">\n"
314 . "</FORM></td></tr></table><BR>\n";
52ed2f88 315 } else {
b7f83b61 316 echo _("No folders were found to subscribe to!") . '</td></tr></table>';
52ed2f88 317 }
318} else {
319 /* don't perform the list action -- this is much faster */
b7f83b61 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";
e634431a 325}
e7db48af 326
b7f83b61 327do_hook('folders_bottom');
bd9bbfef 328?>
e7db48af 329
e7db48af 330 </td></tr>
331 </table>
332
333</td></tr>
334</table>
335
336<?php
1195c340 337 sqimap_logout($imapConnection);
aa42fbfb 338?>
e7db48af 339
0037f048 340</body></html>