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