Merge utf7_decode_local and utf7_encode_local into one file.
[squirrelmail.git] / src / folders.php
CommitLineData
59177427 1<?php
895905c0 2
35586184 3/**
4 * folders.php
5 *
15e6162e 6 * Copyright (c) 1999-2002 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
29$username = $_SESSION['username'];
30$key = $_COOKIE['key'];
31$delimiter = $_SESSION['delimiter'];
32$onetimepad = $_SESSION['onetimepad'];
33if (isset($_GET['success'])) {
34 $success = $_GET['success'];
35}
36
37/* end of get globals */
38
2441907d 39echo '<br>' .
6206f6c4 40 html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) .
2441907d 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] );
aa42fbfb 46
b7f83b61 47if ( 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;
e634431a 71 }
72
b7f83b61 73 $td_str .= '</b><br>';
74
75
50ed645b 76 echo html_tag( 'table',
77 html_tag( 'tr',
78 html_tag( 'td', $td_str .
b7f83b61 79 '<a href="../src/left_main.php" target=left>' .
80 _("refresh folder list") . '</a>' ,
50ed645b 81 'center' )
82 ) ,
b7f83b61 83 'center', '', 'width="100%" cellpadding="4" cellspacing="0" border="0"' );
e634431a 84}
b7f83b61 85
86echo "\n<br>";
87
e634431a 88$imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
89$boxes = sqimap_mailbox_list($imapConnection);
90
91/** CREATING FOLDERS **/
ac50138c 92echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
50ed645b 93 html_tag( 'tr',
94 html_tag( 'td', '<b>' . _("Create Folder") . '</b>', 'center', $color[9] )
95 ) .
96 html_tag( 'tr' ) .
97 html_tag( 'td', '', 'center', $color[0] ) .
98
1c52ba77 99 "<FORM NAME=cf ACTION=\"folders_create.php\" METHOD=\"POST\">\n".
6b4bd11f 100 "<input type=TEXT SIZE=25 NAME=folder_name><BR>\n".
1c52ba77 101 _("as a subfolder of").
b7f83b61 102 '<BR>'.
1c52ba77 103 "<TT><SELECT NAME=subfolder>\n";
e634431a 104if ($default_sub_of_inbox == false) {
105 echo '<OPTION SELECTED VALUE="">[ '._("None")." ]\n";
106} else {
107 echo '<OPTION VALUE="">[ '._("None")." ]\n";
108}
109
be2d5495 110$show_selected = 0;
111if ( $default_sub_of_inbox ) {
112 $show_selected = array('inbox');
113}
114$skip_folders = 0;
115if ( strtolower($imap_server_type) == 'courier' ) {
116 $skip_folders = array('inbox.trash');
e634431a 117}
be2d5495 118
119echo sqimap_mailbox_option_list($imapConnection, $show_selected, $skip_folders, $boxes, 'noinferiors');
120
e634431a 121echo "</SELECT></TT>\n";
122if ($show_contain_subfolders_option) {
b7f83b61 123 echo '<br><input type=CHECKBOX NAME="contain_subs"> &nbsp;'
124 . _("Let this folder contain subfolders")
125 . '<BR>';
1c52ba77 126}
6b4bd11f 127echo "<input type=SUBMIT VALUE=\""._("Create")."\">\n";
128echo "</FORM></td></tr>\n";
e634431a 129
50ed645b 130echo html_tag( 'tr',
131 html_tag( 'td', '&nbsp;', 'left', $color[4] )
132 ) ."\n";
0037f048 133
134/** count special folders **/
135$count_special_folders = 0;
136$num_max = 1;
137if (strtolower($imap_server_type) == "courier" || $move_to_trash) {
138 $num_max++;
139}
140if ($move_to_sent) {
141 $num_max++;
142}
143if ($save_as_draft) {
144 $num_max++;
145}
336155db 146for ($p = 0, $cnt = count($boxes); $p < $cnt && $count_special_folders < $num_max; $p++) {
0037f048 147 if (strtolower($boxes[$p]['unformatted']) == 'inbox')
148 $count_special_folders++;
149 else if (strtolower($imap_server_type) == 'courier' &&
150 strtolower($boxes[$p]['unformatted']) == 'inbox.trash')
151 $count_special_folders++;
152 else if ($boxes[$p]['unformatted'] == $trash_folder && $trash_folder)
153 $count_special_folders++;
154 else if ($boxes[$p]['unformatted'] == $sent_folder && $sent_folder)
155 $count_special_folders++;
156 else if ($boxes[$p]['unformatted'] == $draft_folder && $draft_folder)
157 $count_special_folders++;
158}
159
160
e634431a 161/** RENAMING FOLDERS **/
50ed645b 162echo html_tag( 'tr',
163 html_tag( 'td', '<b>' . _("Rename a Folder") . '</b>', 'center', $color[9] )
164 ) .
165 html_tag( 'tr' ) .
166 html_tag( 'td', '', 'center', $color[0] );
167
0037f048 168if ($count_special_folders < count($boxes)) {
169 echo "<FORM ACTION=\"folders_rename_getname.php\" METHOD=\"POST\">\n"
170 . "<TT><SELECT NAME=old>\n"
171 . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
be2d5495 172
173 echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes);
174
1c52ba77 175 echo "</SELECT></TT>\n".
6b4bd11f 176 "<input type=SUBMIT VALUE=\"".
1c52ba77 177 _("Rename").
178 "\">\n".
50ed645b 179 "</FORM></td></tr>\n";
e634431a 180} else {
b7f83b61 181 echo _("No folders found") . '<br><br></td></tr>';
e634431a 182}
183$boxes_sub = $boxes;
184
50ed645b 185echo html_tag( 'tr',
186 html_tag( 'td', '&nbsp;', 'left', $color[4] )
187 ) ."\n";
e634431a 188
189/** DELETING FOLDERS **/
50ed645b 190echo html_tag( 'tr',
191 html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[9] )
192 ) .
193 html_tag( 'tr' ) .
194 html_tag( 'td', '', 'center', $color[0] );
e634431a 195
e634431a 196if ($count_special_folders < count($boxes)) {
0037f048 197 echo "<FORM ACTION=\"folders_delete.php\" METHOD=\"POST\">\n"
198 . "<TT><SELECT NAME=mailbox>\n"
199 . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
be2d5495 200
201 echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes);
202
b7f83b61 203 echo "</SELECT></TT>\n"
204 . '<input type=SUBMIT VALUE="'
205 . _("Delete")
206 . "\">\n"
207 . "</form></td></tr>\n";
e634431a 208} else {
6b4bd11f 209 echo _("No folders found") . "<br><br></td></tr>";
e634431a 210}
50ed645b 211
212echo html_tag( 'tr',
213 html_tag( 'td', '&nbsp;', 'left', $color[4] )
214 ) ."</table>\n";
215
e634431a 216
217/** UNSUBSCRIBE FOLDERS **/
12ff1cab 218echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
50ed645b 219 html_tag( 'tr',
220 html_tag( 'td', '<b>' . _("Unsubscribe") . '/' . _("Subscribe") . '</b>', 'center', $color[9], 'colspan="2"' )
221 ) .
222 html_tag( 'tr' ) .
223 html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
224
e634431a 225if ($count_special_folders < count($boxes)) {
b7f83b61 226 echo "<FORM ACTION=\"folders_subscribe.php?method=unsub\" METHOD=\"POST\">\n"
227 . "<TT><SELECT NAME=\"mailbox[]\" multiple size=8>\n";
e634431a 228 for ($i = 0; $i < count($boxes); $i++) {
229 $use_folder = true;
230 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
231 ($boxes[$i]["unformatted"] != $trash_folder) &&
232 ($boxes[$i]["unformatted"] != $sent_folder) &&
233 ($boxes[$i]["unformatted"] != $draft_folder)) {
234 $box = $boxes[$i]["unformatted-dm"];
46bc57c1 235 $box2 = str_replace(' ', '&nbsp;',
236 imap_utf7_decode_local($boxes[$i]["unformatted-disp"]));
e634431a 237 echo " <OPTION VALUE=\"$box\">$box2\n";
238 }
239 }
b7f83b61 240 echo "</SELECT></TT><br><br>\n"
241 . '<input type=SUBMIT VALUE="'
242 . _("Unsubscribe")
243 . "\">\n"
244 . "</FORM></td>\n";
e634431a 245} else {
b7f83b61 246 echo _("No folders were found to unsubscribe from!") . '</td>';
e634431a 247}
248$boxes_sub = $boxes;
249
250/** SUBSCRIBE TO FOLDERS **/
50ed645b 251echo html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
52ed2f88 252if(!$no_list_for_subscribe) {
336155db 253 $boxes_all = sqimap_mailbox_list_all ($imapConnection);
52ed2f88 254
b7f83b61 255 $box = '';
256 $box2 = '';
52ed2f88 257 for ($i = 0, $q = 0; $i < count($boxes_all); $i++) {
e634431a 258 $use_folder = true;
259 for ($p = 0; $p < count ($boxes); $p++) {
b7f83b61 260 if ($boxes_all[$i]['unformatted'] == $boxes[$p]['unformatted']) {
e634431a 261 $use_folder = false;
262 continue;
b7f83b61 263 } else if ($boxes_all[$i]['unformatted-dm'] == $folder_prefix) {
e634431a 264 $use_folder = false;
265 }
266 }
7e235a1a 267 if ($use_folder == true) {
b7f83b61 268 $box[$q] = $boxes_all[$i]['unformatted-dm'];
269 $box2[$q] = imap_utf7_decode_local($boxes_all[$i]['unformatted-disp']);
e634431a 270 $q++;
271 }
52ed2f88 272 }
52ed2f88 273 if ($box && $box2) {
b7f83b61 274 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n"
275 . '<tt><select name="mailbox[]" multiple size=8>';
e634431a 276
277 for ($q = 0; $q < count($box); $q++) {
278 echo " <OPTION VALUE=\"$box[$q]\">".$box2[$q]."\n";
279 }
b7f83b61 280 echo '</select></tt><br><br>'
281 . '<input type=SUBMIT VALUE="'. _("Subscribe") . "\">\n"
282 . "</FORM></td></tr></table><BR>\n";
52ed2f88 283 } else {
b7f83b61 284 echo _("No folders were found to subscribe to!") . '</td></tr></table>';
52ed2f88 285 }
286} else {
287 /* don't perform the list action -- this is much faster */
b7f83b61 288 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n"
289 . _("Subscribe to:") . '<br>'
290 . '<tt><input type="text" name="mailbox[]" size=35>'
291 . '<INPUT TYPE=SUBMIT VALUE="'. _("Subscribe") . "\">\n"
292 . "</FORM></TD></TR></TABLE><BR>\n";
e634431a 293}
e7db48af 294
b7f83b61 295do_hook('folders_bottom');
bd9bbfef 296?>
e7db48af 297
e7db48af 298 </td></tr>
299 </table>
300
301</td></tr>
302</table>
303
304<?php
1195c340 305 sqimap_logout($imapConnection);
aa42fbfb 306?>
e7db48af 307
0037f048 308</body></html>