Close the form. Otherwise selecting all results from one mailbox will select them...
[squirrelmail.git] / src / left_main.php
1 <?php
2
3 /**
4 * left_main.php
5 *
6 * Copyright (c) 1999-2004 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This is the code for the left bar. The left bar shows the folders
10 * available, and has cookie information.
11 *
12 * @version $Id$
13 * @package squirrelmail
14 */
15
16 /**
17 * Path for SquirrelMail required files.
18 * @ignore
19 */
20 define('SM_PATH','../');
21
22 /* SquirrelMail required files. */
23 require_once(SM_PATH . 'include/validate.php');
24 require_once(SM_PATH . 'functions/imap.php');
25 require_once(SM_PATH . 'functions/plugin.php');
26 require_once(SM_PATH . 'functions/page_header.php');
27 require_once(SM_PATH . 'functions/html.php');
28 require_once(SM_PATH . 'functions/date.php');
29
30 /* These constants are used for folder stuff. */
31 define('SM_BOX_UNCOLLAPSED', 0);
32 define('SM_BOX_COLLAPSED', 1);
33
34 /* --------------------- FUNCTIONS ------------------------- */
35
36 function formatMailboxName($imapConnection, $box_array) {
37
38 global $trash_folder, $color, $move_to_trash,
39 $unseen_notify, $unseen_type, $use_special_folder_color;
40 $real_box = $box_array['unformatted'];
41 $mailbox = str_replace('&nbsp;','',$box_array['formatted']);
42 $mailboxURL = urlencode($real_box);
43
44 /* Strip down the mailbox name. */
45 if (ereg("^( *)([^ ]*)$", $mailbox, $regs)) {
46 $mailbox = $regs[2];
47 }
48 $unseen = 0;
49 $status = array('','');
50 if (($unseen_notify == 2 && $real_box == 'INBOX') ||
51 $unseen_notify == 3) {
52 $tmp_status = create_unseen_string($real_box, $box_array, $imapConnection, $unseen_type );
53 if ($status !== false) {
54 $status = $tmp_status;
55 }
56 }
57 list($unseen_string, $unseen) = $status;
58 $special_color = ($use_special_folder_color && isSpecialMailbox($real_box));
59
60 /* Start off with a blank line. */
61 $line = '';
62
63 /* If there are unseen message, bold the line. */
64 if ($unseen > 0) { $line .= '<b>'; }
65
66 /* Create the link for this folder. */
67 if ($status !== false) {
68 $line .= '<a href="right_main.php?PG_SHOWALL=0&amp;startMessage=1&amp;mailbox='.
69 $mailboxURL.'" target="right" style="text-decoration:none">';
70 }
71 if ($special_color) {
72 $line .= "<font color=\"$color[11]\">";
73 }
74 if ( $mailbox == 'INBOX' ) {
75 $line .= _("INBOX");
76 } else {
77 $line .= str_replace(array(' ','<','>'),array('&nbsp;','&lt;','&gt;'),$mailbox);
78 }
79 if ($special_color == TRUE)
80 $line .= '</font>';
81 if ($status !== false) {
82 $line .= '</a>';
83 }
84
85 /* If there are unseen message, close bolding. */
86 if ($unseen > 0) { $line .= "</b>"; }
87
88 /* Print unseen information. */
89 if ($unseen_string != '') {
90 $line .= "&nbsp;<small>$unseen_string</small>";
91 }
92
93 /* If it's the trash folder, show a purge link when needed */
94 if (($move_to_trash) && ($real_box == $trash_folder)) {
95 if (! isset($numMessages)) {
96 $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
97 }
98
99 if (($numMessages > 0) or ($box_array['parent'] == 1)) {
100 $urlMailbox = urlencode($real_box);
101 $line .= "\n<small>\n" .
102 '&nbsp;&nbsp;[<a href="empty_trash.php">'._("Purge").'</a>]' .
103 '</small>';
104 }
105 }
106
107
108 // let plugins fiddle with end of line
109 $line .= concat_hook_function('left_main_after_each_folder',
110 array(isset($numMessages) ? $numMessages : '', $real_box, $imapConnection));
111
112
113 /* Return the final product. */
114 return ($line);
115 }
116
117 /**
118 * Recursive function that computes the collapsed status and parent
119 * (or not parent) status of this box, and the visiblity and collapsed
120 * status and parent (or not parent) status for all children boxes.
121 */
122 function compute_folder_children(&$parbox, $boxcount) {
123 global $boxes, $data_dir, $username, $collapse_folders;
124 $nextbox = $parbox + 1;
125
126 /* Retreive the name for the parent box. */
127 $parbox_name = $boxes[$parbox]['unformatted'];
128
129 /* 'Initialize' this parent box to childless. */
130 $boxes[$parbox]['parent'] = FALSE;
131
132 /* Compute the collapse status for this box. */
133 if( isset($collapse_folders) && $collapse_folders ) {
134 $collapse = getPref($data_dir, $username, 'collapse_folder_' . $parbox_name);
135 $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED : $collapse);
136 } else {
137 $collapse = SM_BOX_UNCOLLAPSED;
138 }
139 $boxes[$parbox]['collapse'] = $collapse;
140
141 /* Otherwise, get the name of the next box. */
142 if (isset($boxes[$nextbox]['unformatted'])) {
143 $nextbox_name = $boxes[$nextbox]['unformatted'];
144 } else {
145 $nextbox_name = '';
146 }
147
148 /* Compute any children boxes for this box. */
149 while (($nextbox < $boxcount) &&
150 (is_parent_box($boxes[$nextbox]['unformatted'], $parbox_name))) {
151
152 /* Note that this 'parent' box has at least one child. */
153 $boxes[$parbox]['parent'] = TRUE;
154
155 /* Compute the visiblity of this box. */
156 $boxes[$nextbox]['visible'] = ($boxes[$parbox]['visible'] &&
157 ($boxes[$parbox]['collapse'] != SM_BOX_COLLAPSED));
158
159 /* Compute the visibility of any child boxes. */
160 compute_folder_children($nextbox, $boxcount);
161 }
162
163 /* Set the parent box to the current next box. */
164 $parbox = $nextbox;
165 }
166
167 /**
168 * Create the link for a parent folder that will allow that
169 * parent folder to either be collapsed or expaned, as is
170 * currently appropriate.
171 */
172 function create_collapse_link($boxnum) {
173 global $boxes, $unseen_notify, $color, $use_icons, $icon_theme;
174 $mailbox = urlencode($boxes[$boxnum]['unformatted']);
175
176 /* Create the link for this collapse link. */
177 $link = '<a target="left" style="text-decoration:none" ' .
178 'href="left_main.php?';
179 if ($boxes[$boxnum]['collapse'] == SM_BOX_COLLAPSED) {
180 if ($use_icons && $icon_theme != 'none') {
181 $link .= "unfold=$mailbox\"><img src=\"" . SM_PATH . 'images/plus.png" border="0" height="7" width="7" />';
182 } else {
183 $link .= "unfold=$mailbox\">+";
184 }
185 } else {
186 if ($use_icons && $icon_theme != 'none') {
187 $link .= "fold=$mailbox\"><img src=\"" . SM_PATH . 'images/minus.png" border="0" height="7" width="7" />';
188 } else {
189 $link .= "fold=$mailbox\">-";
190 }
191 }
192 $link .= '</a>';
193
194 /* Return the finished product. */
195 return ($link);
196 }
197
198 /**
199 * create_unseen_string:
200 *
201 * Create unseen and total message count for both this folder and
202 * it's subfolders.
203 *
204 * @param string $boxName name of the current mailbox
205 * @param array $boxArray array for the current mailbox
206 * @param $imapConnection current imap connection in use
207 * @return array unseen message string (for display), unseen message count
208 */
209 function create_unseen_string($boxName, $boxArray, $imapConnection, $unseen_type) {
210 global $boxes, $color, $unseen_cum;
211
212 /* Initialize the return value. */
213 $result = array(0,0);
214
215 /* Initialize the counts for this folder. */
216 $boxUnseenCount = 0;
217 $boxMessageCount = 0;
218 $totalUnseenCount = 0;
219 $totalMessageCount = 0;
220
221 /* Collect the counts for this box alone. */
222 $status = sqimap_status_messages($imapConnection, $boxName);
223 $boxUnseenCount = $status['UNSEEN'];
224 if ($boxUnseenCount === false) {
225 return false;
226 }
227 if ($unseen_type == 2) {
228 $boxMessageCount = $status['MESSAGES'];
229 }
230
231 /* Initialize the total counts. */
232
233 if ($boxArray['collapse'] == SM_BOX_COLLAPSED && $unseen_cum) {
234 /* Collect the counts for this boxes subfolders. */
235 $curBoxLength = strlen($boxName);
236 $boxCount = count($boxes);
237
238 for ($i = 0; $i < $boxCount; ++$i) {
239 /* Initialize the counts for this subfolder. */
240 $subUnseenCount = 0;
241 $subMessageCount = 0;
242
243 /* Collect the counts for this subfolder. */
244 if (($boxName != $boxes[$i]['unformatted'])
245 && (substr($boxes[$i]['unformatted'], 0, $curBoxLength) == $boxName)
246 && !in_array('noselect', $boxes[$i]['flags'])) {
247 $status = sqimap_status_messages($imapConnection, $boxes[$i]['unformatted']);
248 $subUnseenCount = $status['UNSEEN'];
249 if ($unseen_type == 2) {
250 $subMessageCount = $status['MESSAGES'];;
251 }
252 /* Add the counts for this subfolder to the total. */
253 $totalUnseenCount += $subUnseenCount;
254 $totalMessageCount += $subMessageCount;
255 }
256 }
257
258 /* Add the counts for all subfolders to that of the box. */
259 $boxUnseenCount += $totalUnseenCount;
260 $boxMessageCount += $totalMessageCount;
261 }
262
263 /* And create the magic unseen count string. */
264 /* Really a lot more then just the unseen count. */
265 if (($unseen_type == 1) && ($boxUnseenCount > 0)) {
266 $result[0] = "($boxUnseenCount)";
267 } else if ($unseen_type == 2) {
268 $result[0] = "($boxUnseenCount/$boxMessageCount)";
269 $result[0] = "<font color=\"$color[11]\">$result[0]</font>";
270 }
271
272 /* Set the unseen count to return to the outside world. */
273 $result[1] = $boxUnseenCount;
274
275 /* Return our happy result. */
276 return ($result);
277 }
278
279 /**
280 * This simple function checks if a box is another box's parent.
281 */
282 function is_parent_box($curbox_name, $parbox_name) {
283 global $delimiter;
284
285 /* Extract the name of the parent of the current box. */
286 $curparts = explode($delimiter, $curbox_name);
287 $curname = array_pop($curparts);
288 $actual_parname = implode($delimiter, $curparts);
289 $actual_parname = substr($actual_parname,0,strlen($parbox_name));
290
291 /* Compare the actual with the given parent name. */
292 return ($parbox_name == $actual_parname);
293 }
294
295 function ListBoxes ($boxes, $j=0 ) {
296 global $data_dir, $username, $color, $unseen_notify, $unseen_type,
297 $move_to_trash, $trash_folder, $collapse_folders, $imapConnection,
298 $use_icons, $icon_theme, $use_special_folder_color;
299
300 if (!isset($boxes) || empty($boxes))
301 return;
302
303 $pre = '<nobr>';
304 $end = '';
305 $collapse = false;
306 $unseen_found = false;
307 $unseen = 0;
308
309 $mailbox = $boxes->mailboxname_full;
310 $leader = '<tt>';
311 $leader .= str_repeat('&nbsp;&nbsp;',$j);
312 $mailboxURL = urlencode($mailbox);
313
314 /* get unseen/total messages information */
315 /* Only need to display info when option is set */
316 if (isset($unseen_notify) && ($unseen_notify > 1) &&
317 (($boxes->unseen !== false) || ($boxes->total !== false))) {
318
319 if ($boxes->unseen !== false)
320 $unseen = $boxes->unseen;
321
322 /*
323 Should only display unseen info if the folder is inbox
324 or you set the option for all folders
325 */
326
327 if ((strtolower($mailbox) == 'inbox') || ($unseen_notify == 3)) {
328 $unseen_string = $unseen;
329
330 /* If users requests, display message count too */
331 if (isset($unseen_type) && ($unseen_type == 2) && ($boxes->total !== false)) {
332 $unseen_string .= '/' . $boxes->total;
333 }
334
335 $unseen_string = "<font color=\"$color[11]\">($unseen_string)</font>";
336
337 /*
338 Finally allow the script to display the values by setting a boolean.
339 This can only occur if the unseen count is great than 0 (if you have
340 unseen count only), or you have the message count too.
341 */
342 if (($unseen > 0) || (isset($unseen_type) && ($unseen_type ==2))) {
343 $unseen_found = true;
344 }
345 }
346 }
347
348 if (isset($boxes->mbxs[0]) && $collapse_folders) {
349 $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox);
350 $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED : $collapse);
351
352 $link = '<a target="left" style="text-decoration:none" ' .'href="left_main.php?';
353 if ($collapse) {
354 if ($use_icons && $icon_theme != 'none') {
355 $link .= "unfold=$mailboxURL\">$leader<img src=\"" . SM_PATH . 'images/plus.png" border="0" height="7" width="7" />&nbsp;</tt>';
356 } else {
357 $link .= "unfold=$mailboxURL\">$leader+&nbsp;</tt>";
358 }
359 } else {
360 if ($use_icons && $icon_theme != 'none') {
361 $link .= "fold=$mailboxURL\">$leader<img src=\"" . SM_PATH . 'images/minus.png" border="0" height="7" width="7" />&nbsp;</tt>';
362 } else {
363 $link .= "fold=$mailboxURL\">$leader-&nbsp;</tt>";
364 }
365 }
366 $link .= '</a>';
367 $pre .= $link;
368 } else {
369 $pre.= $leader . '&nbsp;&nbsp;</tt>';
370 }
371
372 /* If there are unseen message, bold the line. */
373 if (($move_to_trash) && ($mailbox == $trash_folder)) {
374 if (! isset($boxes->total)) {
375 $boxes->total = sqimap_status_messages($imapConnection, $mailbox);
376 }
377 if ($unseen > 0) {
378 $pre .= '<b>';
379 }
380 $pre .= "<a href=\"right_main.php?PG_SHOWALL=0&amp;startMessage=1&amp;mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
381 $end .= '</a>';
382 if ($unseen > 0) {
383 $end .= '</b>';
384 }
385 if ($boxes->total > 0) {
386 if ($unseen > 0) {
387 $pre .= '<b>';
388 }
389 $pre .= "<a href=\"right_main.php?PG_SHOWALL=0&amp;startMessage=1&amp;mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
390 if ($unseen > 0) {
391 $end .= '</b>';
392 }
393 /* Print unseen information. */
394 if ($unseen_found) {
395 $end .= "&nbsp;<small>$unseen_string</small>";
396 }
397 $end .= "\n<small>\n" .
398 '&nbsp;&nbsp;[<a href="empty_trash.php">'._("Purge").'</a>]'.
399 '</small>';
400 }
401 } else {
402 if (!$boxes->is_noselect) {
403 if ($unseen > 0) {
404 $pre .= '<b>';
405 }
406 $pre .= "<a href=\"right_main.php?PG_SHOWALL=0&amp;startMessage=1&amp;mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
407 $end .= '</a>';
408 if ($unseen > 0) {
409 $end .= '</b>';
410 }
411 }
412 /* Print unseen information. */
413 if ($unseen_found) {
414 $end .= "&nbsp;<small>$unseen_string</small>";
415 }
416
417 }
418
419 $font = '';
420 $fontend = '';
421 if ($use_special_folder_color && $boxes->is_special) {
422 $font = "<font color=\"$color[11]\">";
423 $fontend = "</font>";
424 }
425
426 // let plugins fiddle with end of line
427 $end .= concat_hook_function('left_main_after_each_folder',
428 array(isset($numMessages) ? $numMessages : '',
429 $boxes->mailboxname_full, $imapConnection));
430
431 $end .= '</nobr>';
432
433 if (!$boxes->is_root) {
434 echo "" . $pre .$font. str_replace(array(' ','<','>'),array('&nbsp;','&lt;','&gt;'),$boxes->mailboxname_sub) .$fontend . $end. '<br />' . "\n";
435 $j++;
436 }
437
438 if (!$collapse || $boxes->is_root) {
439 for ($i = 0; $i <count($boxes->mbxs); $i++) {
440 listBoxes($boxes->mbxs[$i],$j);
441 }
442 }
443 }
444
445 function ListAdvancedBoxes ($boxes, $mbx, $j='ID.0000' ) {
446 global $data_dir, $username, $color, $unseen_notify, $unseen_type,
447 $move_to_trash, $trash_folder, $collapse_folders, $use_special_folder_color;
448
449 if (!isset($boxes) || empty($boxes))
450 return;
451
452 /* use_folder_images only works if the images exist in ../images */
453 $use_folder_images = true;
454
455 $pre = '';
456 $end = '';
457 $collapse = false;
458 $unseen_found = false;
459 $unseen = 0;
460
461 $mailbox = $boxes->mailboxname_full;
462 $mailboxURL = urlencode($mailbox);
463
464 /* get unseen/total messages information */
465 /* Only need to display info when option is set */
466 if (isset($unseen_notify) && ($unseen_notify > 1) &&
467 (($boxes->unseen !== false) || ($boxes->total !== false))) {
468
469 if ($boxes->unseen !== false)
470 $unseen = $boxes->unseen;
471
472 /*
473 Should only display unseen info if the folder is inbox
474 or you set the option for all folders
475 */
476
477 if ((strtolower($mailbox) == 'inbox') || ($unseen_notify == 3)) {
478 $unseen_string = $unseen;
479
480 /* If users requests, display message count too */
481 if (isset($unseen_type) && ($unseen_type == 2) && ($boxes->total !== false)) {
482 $unseen_string .= '/' . $boxes->total;
483 }
484
485 $unseen_string = "<font color=\"$color[11]\">($unseen_string)</font>";
486
487 /*
488 Finally allow the script to display the values by setting a boolean.
489 This can only occur if the unseen count is great than 0 (if you have
490 unseen count only), or you have the message count too.
491 */
492 if (($unseen > 0) || (isset($unseen_type) && ($unseen_type ==2))) {
493 $unseen_found = true;
494 }
495 }
496 }
497
498 /* If there are unseen message, bold the line. */
499 if ($unseen > 0) { $pre .= '<b>'; }
500
501 /* color special boxes */
502 if ($use_special_folder_color && $boxes->is_special) {
503 $pre .= "<font color=\"$color[11]\">";
504 $end .= '</font>';
505 }
506
507 /* If there are unseen message, close bolding. */
508 if ($unseen > 0) { $end .= '</b>'; }
509
510 /* Print unseen information. */
511 if ($unseen_found) {
512 $end .= "&nbsp;$unseen_string";
513 }
514
515 if (($move_to_trash) && ($mailbox == $trash_folder)) {
516 if (! isset($numMessages)) {
517 $numMessages = $boxes->total;
518 }
519 $pre = "<a class=\"mbx_link\" href=\"right_main.php?PG_SHOWALL=0&amp;startMessage=1&amp;mailbox=$mailboxURL\" target=\"right\">" . $pre;
520 $end .= '</a>';
521 if ($numMessages > 0) {
522 $end .= "\n<small>\n" .
523 '&nbsp;&nbsp;[<a class="mbx_link" href="empty_trash.php">'._("Purge").'</a>]'.
524 '</small>';
525 }
526 } else {
527 if (!$boxes->is_noselect) { /* \Noselect boxes can't be selected */
528 $pre = "<a class=\"mbx_link\" href=\"right_main.php?PG_SHOWALL=0&amp;startMessage=1&amp;mailbox=$mailboxURL\" target=\"right\">" . $pre;
529 $end .= '</a>';
530 }
531 }
532
533 // let plugins fiddle with end of line
534 global $imapConnection;
535 $end .= concat_hook_function('left_main_after_each_folder',
536 array(isset($numMessages) ? $numMessages : '',
537 $boxes->mailboxname_full, $imapConnection));
538
539 if (!$boxes->is_root) {
540 if ($use_folder_images) {
541 if ($boxes->is_inbox) {
542 $folder_img = '../images/inbox.png';
543 } else if ($boxes->is_sent) {
544 $folder_img = '../images/senti.png';
545 } else if ($boxes->is_trash) {
546 $folder_img = '../images/delitem.png';
547 } else if ($boxes->is_draft) {
548 $folder_img = '../images/draft.png';
549 } else if ($boxes->is_noinferiors) {
550 $folder_img = '../images/folder_noinf.png';
551 } else {
552 $folder_img = '../images/folder.png';
553 }
554 $folder_img = '&nbsp;<img src="'.$folder_img.'" height="15" valign="center" />&nbsp;';
555 } else {
556 $folder_img = '';
557 }
558 if (!isset($boxes->mbxs[0])) {
559 echo ' ' . html_tag( 'div',
560 '<tt>'. $pre . $folder_img . '</tt>'. str_replace(array(' ','<','>'),array('&nbsp;','&lt;','&gt;'),$boxes->mailboxname_sub) . $end,
561 'left', '', 'class="mbx_sub" id="' .$j. '"' ) . "\n";
562 } else {
563 /* get collapse information */
564 if ($collapse_folders) {
565 $form_entry = $j.'F';
566 if (isset($mbx) && isset($mbx[$form_entry])) {
567 $collapse = $mbx[$form_entry];
568 setPref($data_dir, $username, 'collapse_folder_'.$boxes->mailboxname_full , $collapse ? SM_BOX_COLLAPSED : SM_BOX_UNCOLLAPSED);
569 } else {
570 $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox);
571 $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED : $collapse);
572 }
573 $img_src = ($collapse ? '../images/plus.png' : '../images/minus.png');
574 $collapse_link = '<a href="javascript:void(0)">'." <img src=\"$img_src\" border=\"1\" id=$j onclick=\"hidechilds(this)\" style=\"cursor:hand\" /></a>";
575 } else {
576 $collapse_link='';
577 }
578 echo ' ' . html_tag( 'div',
579 $collapse_link . $pre . $folder_img . '&nbsp;'. $boxes->mailboxname_sub . $end ,
580 'left', '', 'class="mbx_par" id="' .$j. 'P"' ) . "\n";
581 echo ' <input type="hidden" name="mbx['.$j. 'F]" value="'.$collapse.'" id="mbx['.$j.'F]" />'."\n";
582 }
583 }
584
585 $visible = ($collapse ? ' style="display:none"' : ' style="display:block"');
586 if (isset($boxes->mbxs[0]) && !$boxes->is_root) /* mailbox contains childs */
587 echo html_tag( 'div', '', 'left', '', 'class="par_area" id='.$j.'.0000 '. $visible ) . "\n";
588
589 if ($j !='ID.0000')
590 $j = $j .'.0000';
591 for ($i = 0; $i <count($boxes->mbxs); $i++) {
592 $j++;
593 ListAdvancedBoxes($boxes->mbxs[$i],$mbx,$j);
594 }
595 if (isset($boxes->mbxs[0]) && !$boxes->is_root)
596 echo '</div>'."\n\n";
597 }
598
599
600
601
602 /* -------------------- MAIN ------------------------ */
603
604 /* get globals */
605 sqgetGlobalVar('username', $username, SQ_SESSION);
606 sqgetGlobalVar('key', $key, SQ_COOKIE);
607 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
608 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
609
610 sqgetGlobalVar('fold', $fold, SQ_GET);
611 sqgetGlobalVar('unfold', $unfold, SQ_GET);
612
613 /* end globals */
614
615 // open a connection on the imap port (143)
616 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output
617
618 /**
619 * Using stristr since older preferences may contain "None" and "none".
620 */
621 if (isset($left_refresh) && ($left_refresh != '') &&
622 !stristr($left_refresh, 'none')){
623 $xtra = "\n<meta http-equiv=\"Expires\" content=\"Thu, 01 Dec 1994 16:00:00 GMT\" />\n" .
624 "<meta http-equiv=\"Pragma\" content=\"no-cache\" />\n".
625 "<meta http-equiv=\"REFRESH\" content=\"$left_refresh;URL=left_main.php\" />\n";
626 } else {
627 $xtra = '';
628 }
629
630 /**
631 * $advanced_tree and $oldway are boolean vars which are default set to default
632 * SM behaviour.
633 * Setting $oldway to false causes left_main.php to use the new experimental
634 * way of getting the mailbox-tree.
635 * Setting $advanced tree to true causes SM to display a experimental
636 * mailbox-tree with dhtml behaviour.
637 * It only works on browsers which supports css and javascript. The used
638 * javascript is experimental and doesn't support all browsers.
639 * It has been tested on IE6 an Konquerer 3.0.0-2.
640 * It is now tested and working on: (please test and update this list)
641 * Windows: IE 5.5 SP2, IE 6 SP1, Gecko based (Mozilla, Firebird) and Opera7
642 * XWindow: ?
643 * Mac: ?
644 * In the function ListAdvancedBoxes there is another var $use_folder_images.
645 * setting this to true is only usefull if the images exists in ../images.
646 *
647 * Feel free to experiment with the code and report bugs and enhancements
648 * to marc@its-projects.nl
649 **/
650
651 /* set this to true if you want to see a nicer mailboxtree */
652 if (! isset($advanced_tree) || $advanced_tree=="" ) {
653 $advanced_tree=false;
654 }
655 /* default SM behaviour */
656 if (! isset($oldway) || $oldway=="" ) {
657 $oldway=false;
658 }
659
660 if ($advanced_tree) {
661 $xtra .= <<<ECHO
662 <script language="Javascript" type="text/javascript">
663
664 <!--
665
666 function preload() {
667 if (document.images) {
668 var treeImages = new Array;
669 var arguments = preload.arguments;
670 for (var i = 0; i<arguments.length; i++) {
671 treeImages[i] = new Image();
672 treeImages[i].src = arguments[i];
673 }
674 }
675 }
676
677 var vTreeImg;
678 var vTreeDiv;
679 var vTreeSrc;
680
681 function fTreeTimeout() {
682 if (vTreeDiv.readyState == "complete")
683 vTreeImg.src = vTreeSrc;
684 else
685 setTimeout("fTreeTimeout()", 100);
686 }
687
688 function hidechilds(img) {
689 id = img.id + ".0000";
690 form_id = "mbx[" + img.id +"F]";
691 if (document.all) { //IE, Opera7
692 div = document.all[id];
693 if (div) {
694 if (div.style.display == "none") {
695 vTreeSrc = "../images/minus.png";
696 style = "block";
697 value = 0;
698 }
699 else {
700 vTreeSrc = "../images/plus.png";
701 style = "none";
702 value = 1;
703 }
704 vTreeImg = img;
705 vTreeDiv = div;
706 if (typeof vTreeDiv.readyState != "undefined") //IE
707 setTimeout("fTreeTimeout()",100);
708 else //Non IE
709 vTreeImg.src = vTreeSrc;
710 div.style.display = style;
711 document.all[form_id].value = value;
712 }
713 }
714 else if (document.getElementById) { //Gecko
715 div = document.getElementById(id);
716 if (div) {
717 if (div.style.display == "none") {
718 src = "../images/minus.png";
719 style = "block";
720 value = 0;
721 }
722 else {
723 src = "../images/plus.png";
724 style = "none";
725 value = 1;
726 }
727 div.style.display = style;
728 img.src = src;
729 document.getElementById(form_id).value = value;
730 }
731 }
732 }
733
734 function buttonover(el,on) {
735 if (!on) {
736 // el.style.borderColor="$color[9]";}
737 el.style.background="$color[0]";}
738 else {
739 el.style.background="$color[9]";}
740 }
741
742 function buttonclick(el,on) {
743 if (!on) {
744 el.style.border="groove";}
745 else {
746 el.style.border="ridge";}
747 }
748
749 function hideframe(hide) {
750
751 ECHO;
752 $xtra .= " left_size = \"$left_size\";\n";
753 $xtra .= <<<ECHO
754 if (document.all) {
755 masterf = window.parent.document.all["fs1"];
756 leftf = window.parent.document.all["left"];
757 leftcontent = document.all["leftframe"];
758 leftbutton = document.all["showf"];
759 } else if (document.getElementById) {
760 masterf = window.parent.document.getElementById("fs1");
761 leftf = window.parent.document.getElementById("left");
762 leftcontent = document.getElementById("leftframe");
763 leftbutton = document.getElementById("showf");
764 } else {
765 return false;
766 }
767 if(hide) {
768 new_col = calc_col("20");
769 masterf.cols = new_col;
770 document.body.scrollLeft=0;
771 document.body.style.overflow='hidden';
772 leftcontent.style.display = 'none';
773 leftbutton.style.display='block';
774 } else {
775 masterf.cols = calc_col(left_size);
776 document.body.style.overflow='';
777 leftbutton.style.display='none';
778 leftcontent.style.display='block';
779
780 }
781 }
782
783 function calc_col(c_w) {
784
785 ECHO;
786 if ($location_of_bar == 'right') {
787 $xtra .= ' right=true;';
788 } else {
789 $xtra .= ' right=false;';
790 }
791 $xtra .= "\n";
792 $xtra .= <<<ECHO
793 if (right) {
794 new_col = '*,'+c_w;
795 } else {
796 new_col = c_w+',*';
797 }
798 return new_col;
799 }
800
801 function resizeframe(direction) {
802 if (document.all) {
803 masterf = window.parent.document.all["fs1"];
804 } else if (document.getElementById) {
805 window.parent.document.getElementById("fs1");
806 } else {
807 return false;
808 }
809
810 ECHO;
811 if ($location_of_bar == 'right') {
812 $xtra .= ' colPat=/^\*,(\d+)$/;';
813 } else {
814 $xtra .= ' colPat=/^(\d+),.*$/;';
815 }
816 $xtra .= "\n";
817
818 $xtra .= <<<ECHO
819 old_col = masterf.cols;
820 colPat.exec(old_col);
821
822 if (direction) {
823 new_col_width = parseInt(RegExp.$1) + 25;
824
825 } else {
826 if (parseInt(RegExp.$1) > 35) {
827 new_col_width = parseInt(RegExp.$1) - 25;
828 }
829 }
830 masterf.cols = calc_col(new_col_width);
831 }
832
833 //-->
834
835 </script>
836
837 ECHO;
838
839 /* style definitions */
840
841 $xtra .= <<<ECHO
842
843 <style type="text/css">
844 <!--
845 body {
846 margin: 0px 0px 0px 0px;
847 padding: 5px 5px 5px 5px;
848 }
849
850 .button {
851 border:outset;
852 border-color: $color[9];
853 background:$color[0];
854 color:$color[6];
855 width:99%;
856 heigth:99%;
857 }
858
859 .mbx_par {
860 font-size:1.0em;
861 margin-left:4px;
862 margin-right:0px;
863 }
864
865 a.mbx_link {
866 text-decoration: none;
867 background-color: $color[0];
868 display: inline;
869 }
870
871 a:hover.mbx_link {
872 background-color: $color[9];
873 }
874
875 a.mbx_link img {
876 border-style: none;
877 }
878
879 .mbx_sub {
880 padding-left:5px;
881 padding-right:0px;
882 margin-left:4px;
883 margin-right:0px;
884 font-size:0.9em;
885 }
886
887 .par_area {
888 margin-top:0px;
889 margin-left:4px;
890 margin-right:0px;
891 padding-left:10px;
892 padding-bottom:5px;
893 border-left: solid;
894 border-left-width:0.1em;
895 border-left-color:$color[9];
896 border-bottom: solid;
897 border-bottom-width:0.1em;
898 border-bottom-color:$color[9];
899 display: block;
900 }
901
902 .mailboxes {
903 padding-bottom:3px;
904 margin-right:4px;
905 padding-right:4px;
906 margin-left:4px;
907 padding-left:4px;
908 border: groove;
909 border-width:0.1em;
910 border-color:$color[9];
911 background: $color[0];
912 }
913
914 -->
915
916 </style>
917
918 ECHO;
919
920 }
921
922 displayHtmlHeader( 'SquirrelMail', $xtra );
923 sqgetGlobalVar('auto_create_done',$auto_create_done,SQ_SESSION);
924 /* If requested and not yet complete, attempt to autocreate folders. */
925 if ($auto_create_special && !isset($auto_create_done)) {
926 $autocreate = array($sent_folder, $trash_folder, $draft_folder);
927 foreach( $autocreate as $folder ) {
928 if (($folder != '') && ($folder != 'none')) {
929 if ( !sqimap_mailbox_exists($imapConnection, $folder)) {
930 sqimap_mailbox_create($imapConnection, $folder, '');
931 } else {
932 //if (!sqimap_mailbox_is_subscribed($imapConnection, $folder)) {
933 // check for subscription is useless and expensive just
934 // surpress the NO response
935 sqimap_subscribe($imapConnection, $folder, false);
936 }
937 }
938 }
939
940 /* Let the world know that autocreation is complete! Hurrah! */
941 $auto_create_done = TRUE;
942 sqsession_register($auto_create_done, 'auto_create_done');
943 }
944
945 if ($advanced_tree) {
946 echo "\n<body" .
947 ' onload="preload(\'../images/minus.png\',\'../images/plus.png\')"' .
948 " bgcolor=\"$color[3]\" text=\"$color[6]\" link=\"$color[6]\" vlink=\"$color[6]\" alink=\"$color[6]\">\n";
949 } else {
950 echo "\n<body bgcolor=\"$color[3]\" text=\"$color[6]\" link=\"$color[6]\" vlink=\"$color[6]\" alink=\"$color[6]\">\n";
951 }
952
953 do_hook('left_main_before');
954 if ($advanced_tree) {
955 /* nice future feature, needs layout !! volunteers? */
956 $right_pos = $left_size - 20;
957 /* echo '<div style="position:absolute;top:0;border=solid;border-width:0.1em;border-color:blue;"><div id="hidef" style="width=20;font-size:12"><a href="javascript:hideframe(true)"><b>&lt;&lt;</b></a></div>';
958 echo '<div id="showf" style="width=20;font-size:12;display:none;"><a href="javascript:hideframe(false)"><b>&gt;&gt;</b></a></div>';
959 echo '<div id="incrf" style="width=20;font-size:12"><a href="javascript:resizeframe(true)"><b>&gt;</b></a></div>';
960 echo '<div id="decrf" style="width=20;font-size:12"><a href="javascript:resizeframe(false)"><b>&lt;</b></a></div></div>';
961 echo '<div id="leftframe"><br /><br />';*/
962 }
963
964 echo "\n\n" . html_tag( 'table', '', 'left', '', 'border="0" cellspacing="0" cellpadding="0" width="99%"' ) .
965 html_tag( 'tr' ) .
966 html_tag( 'td', '', 'left' ) .
967 html_tag( 'table', '', '', '', 'border="0" cellspacing="0" cellpadding="0" width="98%"' ) .
968 html_tag( 'tr' ) .
969 html_tag( 'td', '', 'center' ) .
970 '<font size="4"><b>'. _("Folders") . "</b><br /></font>\n\n";
971
972 if ($date_format != 6) {
973 /* First, display the clock. */
974 if ($hour_format == 1) {
975 $hr = 'G:i';
976 if ($date_format == 4) {
977 $hr .= ':s';
978 }
979 } else {
980 if ($date_format == 4) {
981 $hr = 'g:i:s a';
982 } else {
983 $hr = 'g:i a';
984 }
985 }
986
987 switch( $date_format ) {
988 case 0:
989 $clk = date('Y-m-d '.$hr. ' T', time());
990 break;
991 case 1:
992 $clk = date('m/d/y '.$hr, time());
993 break;
994 case 2:
995 $clk = date('d/m/y '.$hr, time());
996 break;
997 case 4:
998 case 5:
999 $clk = date($hr, time());
1000 break;
1001 default:
1002 $clk = getDayAbrv( date( 'w', time() ) ) . date( ', ' . $hr, time() );
1003 }
1004 $clk = str_replace(' ','&nbsp;',$clk);
1005
1006 echo '<small>' . str_replace(' ','&nbsp;',_("Last Refresh")) .
1007 ":<br />$clk</small><br />";
1008 }
1009
1010 /* Next, display the refresh button. */
1011 echo '<div style="white-space: nowrap;"><small>[<a href="../src/left_main.php" target="left">'.
1012 _("Check mail") . '</a>]</small></div></td></tr></table><br />';
1013
1014 /* Lastly, display the folder list. */
1015 if ( $collapse_folders ) {
1016 /* If directed, collapse or uncollapse a folder. */
1017 if (isset($fold)) {
1018 setPref($data_dir, $username, 'collapse_folder_' . $fold, SM_BOX_COLLAPSED);
1019 } else if (isset($unfold)) {
1020 setPref($data_dir, $username, 'collapse_folder_' . $unfold, SM_BOX_UNCOLLAPSED);
1021 }
1022 }
1023
1024 /* Get unseen/total display prefs */
1025 $unseen_type = getPref( $data_dir , $username , 'unseen_type' );
1026 $unseen_notify = getPref( $data_dir , $username , 'unseen_notify' );
1027
1028 if (!isset($unseen_type) || empty($unseen_type)) {
1029 if (isset($default_unseen_type) && !empty($default_unseen_type)) {
1030 $unseen_type = $default_unseen_type;
1031 } else {
1032 $unseen_type = 1;
1033 }
1034 }
1035
1036 if (!isset($unseen_notify) || empty($unseen_notify)) {
1037 if (isset($default_unseen_notify) && !empty($default_unseen_notify)) {
1038 $unseen_notify = $default_unseen_notify;
1039 } else {
1040 $unseen_notify = 0;
1041 }
1042 }
1043
1044 if ($oldway) { /* normal behaviour SM */
1045
1046 $boxes = sqimap_mailbox_list($imapConnection);
1047 /* Prepare do do out collapsedness and visibility computation. */
1048 $curbox = 0;
1049 $boxcount = count($boxes);
1050
1051 /* Compute the collapsedness and visibility of each box. */
1052
1053 while ($curbox < $boxcount) {
1054 $boxes[$curbox]['visible'] = TRUE;
1055 compute_folder_children($curbox, $boxcount);
1056 }
1057
1058 for ($i = 0; $i < count($boxes); $i++) {
1059 if ( $boxes[$i]['visible'] ) {
1060 $mailbox = $boxes[$i]['formatted'];
1061 $mblevel = substr_count($boxes[$i]['unformatted'], $delimiter) + 1;
1062
1063 /* Create the prefix for the folder name and link. */
1064 $prefix = str_repeat(' ',$mblevel);
1065 if (isset($collapse_folders) && $collapse_folders && $boxes[$i]['parent']) {
1066 $prefix = str_replace(' ','&nbsp;',substr($prefix,0,strlen($prefix)-2)).
1067 create_collapse_link($i) . '&nbsp;';
1068 } else {
1069 $prefix = str_replace(' ','&nbsp;',$prefix);
1070 }
1071 $line = "<nobr><tt>$prefix</tt>";
1072
1073 /* Add the folder name and link. */
1074 if (! isset($color[15])) {
1075 $color[15] = $color[6];
1076 }
1077
1078 if (in_array('noselect', $boxes[$i]['flags'])) {
1079 if( isSpecialMailbox( $boxes[$i]['unformatted']) ) {
1080 $line .= "<font color=\"$color[11]\">";
1081 } else {
1082 $line .= "<font color=\"$color[15]\">";
1083 }
1084 if (ereg("^( *)([^ ]*)", $mailbox, $regs)) {
1085 $mailbox = str_replace('&nbsp;','',$mailbox);
1086 $line .= str_replace(' ', '&nbsp;', $mailbox);
1087 }
1088 $line .= '</font>';
1089 } else {
1090 $line .= formatMailboxName($imapConnection, $boxes[$i]);
1091 }
1092
1093 /* Put the final touches on our folder line. */
1094 $line .= "</nobr><br />\n";
1095
1096 /* Output the line for this folder. */
1097 echo $line;
1098 }
1099 }
1100 } else { /* expiremental code */
1101 $boxes = sqimap_mailbox_tree($imapConnection);
1102 if (isset($advanced_tree) && $advanced_tree) {
1103 echo '<form name="collapse" action="left_main.php" method="post" ' .
1104 'enctype="multipart/form-data"'."\n";
1105 echo '<small>';
1106 echo '<button type="submit" class="button" onmouseover="buttonover(this,true)" onmouseout="buttonover(this,false)" onmousedown="buttonclick(this,true)" onmouseup="buttonclick(this,false)">'. _("Save folder tree") .'</button><br /><br />';
1107 echo '<div id="mailboxes" class="mailboxes">'."\n\n";
1108 sqgetGlobalVar('mbx', $mbx, SQ_POST);
1109 if (!isset($mbx)) $mbx=NULL;
1110 ListAdvancedBoxes($boxes, $mbx);
1111 echo '</div>';
1112 echo '</small>';
1113 echo '</form>'."\n";
1114 } else {
1115 //sqimap_get_status_mbx_tree($imap_stream,$boxes)
1116 ListBoxes($boxes);
1117 }
1118 } /* if ($oldway) else ... */
1119 do_hook('left_main_after');
1120 sqimap_logout($imapConnection);
1121
1122 ?>
1123 </td></tr></table>
1124 </body></html>