6 * Copyright (c) 1999-2005 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This is the code for the left bar. The left bar shows the folders
10 * available, and has cookie information.
13 * @package squirrelmail
17 * Path for SquirrelMail required files.
20 define('SM_PATH','../');
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');
30 /* These constants are used for folder stuff. */
31 define('SM_BOX_UNCOLLAPSED', 0);
32 define('SM_BOX_COLLAPSED', 1);
34 /* --------------------- FUNCTIONS ------------------------- */
36 function formatMailboxName($imapConnection, $box_array) {
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(' ','',$box_array['formatted']);
42 $mailboxURL = urlencode($real_box);
44 /* Strip down the mailbox name. */
45 if (ereg("^( *)([^ ]*)$", $mailbox, $regs)) {
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;
57 list($unseen_string, $unseen) = $status;
58 $special_color = ($use_special_folder_color && isSpecialMailbox($real_box));
60 /* Start off with a blank line. */
63 /* If there are unseen message, bold the line. */
64 if ($unseen > 0) { $line .= '<b>'; }
66 /* Create the link for this folder. */
67 if ($status !== false) {
68 $line .= '<a href="right_main.php?PG_SHOWALL=0&startMessage=1&mailbox='.
69 $mailboxURL.'" target="right" style="text-decoration:none">';
72 $line .= "<font color=\"$color[11]\">";
74 if ( $mailbox == 'INBOX' ) {
77 $line .= str_replace(array(' ','<','>'),array(' ','<','>'),$mailbox);
79 if ($special_color == TRUE)
81 if ($status !== false) {
85 /* If there are unseen message, close bolding. */
86 if ($unseen > 0) { $line .= "</b>"; }
88 /* Print unseen information. */
89 if ($unseen_string != '') {
90 $line .= " <small>$unseen_string</small>";
93 /* If it's the trash folder, show a purge link */
94 if (($move_to_trash) && ($real_box == $trash_folder)) {
95 $urlMailbox = urlencode($real_box);
96 $line .= "\n<small>\n" .
97 ' [<a href="empty_trash.php">'._("Purge").'</a>]' .
102 // let plugins fiddle with end of line
103 $line .= concat_hook_function('left_main_after_each_folder',
104 array(isset($numMessages) ?
$numMessages : '', $real_box, $imapConnection));
107 /* Return the final product. */
112 * Recursive function that computes the collapsed status and parent
113 * (or not parent) status of this box, and the visiblity and collapsed
114 * status and parent (or not parent) status for all children boxes.
116 function compute_folder_children(&$parbox, $boxcount) {
117 global $boxes, $data_dir, $username, $collapse_folders;
118 $nextbox = $parbox +
1;
120 /* Retreive the name for the parent box. */
121 $parbox_name = $boxes[$parbox]['unformatted'];
123 /* 'Initialize' this parent box to childless. */
124 $boxes[$parbox]['parent'] = FALSE;
126 /* Compute the collapse status for this box. */
127 if( isset($collapse_folders) && $collapse_folders ) {
128 $collapse = getPref($data_dir, $username, 'collapse_folder_' . $parbox_name);
129 $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED
: $collapse);
131 $collapse = SM_BOX_UNCOLLAPSED
;
133 $boxes[$parbox]['collapse'] = $collapse;
135 /* Otherwise, get the name of the next box. */
136 if (isset($boxes[$nextbox]['unformatted'])) {
137 $nextbox_name = $boxes[$nextbox]['unformatted'];
142 /* Compute any children boxes for this box. */
143 while (($nextbox < $boxcount) &&
144 (is_parent_box($boxes[$nextbox]['unformatted'], $parbox_name))) {
146 /* Note that this 'parent' box has at least one child. */
147 $boxes[$parbox]['parent'] = TRUE;
149 /* Compute the visiblity of this box. */
150 $boxes[$nextbox]['visible'] = ($boxes[$parbox]['visible'] &&
151 ($boxes[$parbox]['collapse'] != SM_BOX_COLLAPSED
));
153 /* Compute the visibility of any child boxes. */
154 compute_folder_children($nextbox, $boxcount);
157 /* Set the parent box to the current next box. */
162 * Create the link for a parent folder that will allow that
163 * parent folder to either be collapsed or expaned, as is
164 * currently appropriate.
166 function create_collapse_link($boxnum) {
167 global $boxes, $unseen_notify, $color, $use_icons, $icon_theme;
168 $mailbox = urlencode($boxes[$boxnum]['unformatted']);
170 /* Create the link for this collapse link. */
171 $link = '<a target="left" style="text-decoration:none" ' .
172 'href="left_main.php?';
173 if ($boxes[$boxnum]['collapse'] == SM_BOX_COLLAPSED
) {
174 if ($use_icons && $icon_theme != 'none') {
175 $link .= "unfold=$mailbox\"><img src=\"" . SM_PATH
. 'images/plus.png" border="0" height="7" width="7" />';
177 $link .= "unfold=$mailbox\">+";
180 if ($use_icons && $icon_theme != 'none') {
181 $link .= "fold=$mailbox\"><img src=\"" . SM_PATH
. 'images/minus.png" border="0" height="7" width="7" />';
183 $link .= "fold=$mailbox\">-";
188 /* Return the finished product. */
193 * create_unseen_string:
195 * Create unseen and total message count for both this folder and
198 * @param string $boxName name of the current mailbox
199 * @param array $boxArray array for the current mailbox
200 * @param $imapConnection current imap connection in use
201 * @return array unseen message string (for display), unseen message count
203 function create_unseen_string($boxName, $boxArray, $imapConnection, $unseen_type) {
204 global $boxes, $color, $unseen_cum;
206 /* Initialize the return value. */
207 $result = array(0,0);
209 /* Initialize the counts for this folder. */
211 $boxMessageCount = 0;
212 $totalUnseenCount = 0;
213 $totalMessageCount = 0;
215 /* Collect the counts for this box alone. */
216 $status = sqimap_status_messages($imapConnection, $boxName);
217 $boxUnseenCount = $status['UNSEEN'];
218 if ($boxUnseenCount === false) {
221 if ($unseen_type == 2) {
222 $boxMessageCount = $status['MESSAGES'];
225 /* Initialize the total counts. */
227 if ($boxArray['collapse'] == SM_BOX_COLLAPSED
&& $unseen_cum) {
228 /* Collect the counts for this boxes subfolders. */
229 $curBoxLength = strlen($boxName);
230 $boxCount = count($boxes);
232 for ($i = 0; $i < $boxCount; ++
$i) {
233 /* Initialize the counts for this subfolder. */
235 $subMessageCount = 0;
237 /* Collect the counts for this subfolder. */
238 if (($boxName != $boxes[$i]['unformatted'])
239 && (substr($boxes[$i]['unformatted'], 0, $curBoxLength) == $boxName)
240 && !in_array('noselect', $boxes[$i]['flags'])) {
241 $status = sqimap_status_messages($imapConnection, $boxes[$i]['unformatted']);
242 $subUnseenCount = $status['UNSEEN'];
243 if ($unseen_type == 2) {
244 $subMessageCount = $status['MESSAGES'];;
246 /* Add the counts for this subfolder to the total. */
247 $totalUnseenCount +
= $subUnseenCount;
248 $totalMessageCount +
= $subMessageCount;
252 /* Add the counts for all subfolders to that of the box. */
253 $boxUnseenCount +
= $totalUnseenCount;
254 $boxMessageCount +
= $totalMessageCount;
257 /* And create the magic unseen count string. */
258 /* Really a lot more then just the unseen count. */
259 if (($unseen_type == 1) && ($boxUnseenCount > 0)) {
260 $result[0] = "($boxUnseenCount)";
261 } else if ($unseen_type == 2) {
262 $result[0] = "($boxUnseenCount/$boxMessageCount)";
263 $result[0] = "<font color=\"$color[11]\">$result[0]</font>";
266 /* Set the unseen count to return to the outside world. */
267 $result[1] = $boxUnseenCount;
269 /* Return our happy result. */
274 * This simple function checks if a box is another box's parent.
276 function is_parent_box($curbox_name, $parbox_name) {
279 /* Extract the name of the parent of the current box. */
280 $curparts = explode($delimiter, $curbox_name);
281 $curname = array_pop($curparts);
282 $actual_parname = implode($delimiter, $curparts);
283 $actual_parname = substr($actual_parname,0,strlen($parbox_name));
285 /* Compare the actual with the given parent name. */
286 return ($parbox_name == $actual_parname);
289 function ListBoxes ($boxes, $j=0 ) {
290 global $data_dir, $username, $color, $unseen_notify, $unseen_type,
291 $move_to_trash, $trash_folder, $collapse_folders, $imapConnection,
292 $use_icons, $icon_theme, $use_special_folder_color;
294 if (!isset($boxes) ||
empty($boxes))
297 $pre = '<span style="white-space: nowrap;">';
300 $unseen_found = false;
303 $mailbox = $boxes->mailboxname_full
;
305 $leader .= str_repeat(' ',$j);
306 $mailboxURL = urlencode($mailbox);
308 /* get unseen/total messages information */
309 /* Only need to display info when option is set */
310 if (isset($unseen_notify) && ($unseen_notify > 1) &&
311 (($boxes->unseen
!== false) ||
($boxes->total
!== false))) {
313 if ($boxes->unseen
!== false)
314 $unseen = $boxes->unseen
;
317 Should only display unseen info if the folder is inbox
318 or you set the option for all folders
321 if ((strtolower($mailbox) == 'inbox') ||
($unseen_notify == 3)) {
322 $unseen_string = $unseen;
324 /* If users requests, display message count too */
325 if (isset($unseen_type) && ($unseen_type == 2) && ($boxes->total
!== false)) {
326 $unseen_string .= '/' . $boxes->total
;
329 $unseen_string = "<font color=\"$color[11]\">($unseen_string)</font>";
332 Finally allow the script to display the values by setting a boolean.
333 This can only occur if the unseen count is great than 0 (if you have
334 unseen count only), or you have the message count too.
336 if (($unseen > 0) ||
(isset($unseen_type) && ($unseen_type ==2))) {
337 $unseen_found = true;
342 if (isset($boxes->mbxs
[0]) && $collapse_folders) {
343 $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox);
344 $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED
: $collapse);
346 $link = '<a target="left" style="text-decoration:none" ' .'href="left_main.php?';
348 if ($use_icons && $icon_theme != 'none') {
349 $link .= "unfold=$mailboxURL\">$leader<img src=\"" . SM_PATH
. 'images/plus.png" border="0" height="7" width="7" /> </tt>';
351 $link .= "unfold=$mailboxURL\">$leader+ </tt>";
354 if ($use_icons && $icon_theme != 'none') {
355 $link .= "fold=$mailboxURL\">$leader<img src=\"" . SM_PATH
. 'images/minus.png" border="0" height="7" width="7" /> </tt>';
357 $link .= "fold=$mailboxURL\">$leader- </tt>";
363 $pre.= $leader . ' </tt>';
366 /* If there are unseen message, bold the line. */
367 if (($move_to_trash) && ($mailbox == $trash_folder)) {
368 if (! isset($boxes->total
)) {
369 $boxes->total
= sqimap_status_messages($imapConnection, $mailbox);
374 $pre .= "<a href=\"right_main.php?PG_SHOWALL=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
379 if ($boxes->total
> 0) {
383 $pre .= "<a href=\"right_main.php?PG_SHOWALL=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
387 /* Print unseen information. */
389 $end .= " <small>$unseen_string</small>";
392 $end .= "\n<small>\n" .
393 ' [<a href="empty_trash.php">'._("Purge").'</a>]'.
396 if (!$boxes->is_noselect
) {
400 $pre .= "<a href=\"right_main.php?PG_SHOWALL=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
406 /* Print unseen information. */
408 $end .= " <small>$unseen_string</small>";
415 if ($use_special_folder_color && $boxes->is_special
) {
416 $font = "<font color=\"$color[11]\">";
417 $fontend = "</font>";
420 // let plugins fiddle with end of line
421 $end .= concat_hook_function('left_main_after_each_folder',
422 array(isset($numMessages) ?
$numMessages : '',
423 $boxes->mailboxname_full
, $imapConnection));
427 if (!$boxes->is_root
) {
428 echo "" . $pre .$font. str_replace(array(' ','<','>'),array(' ','<','>'),$boxes->mailboxname_sub
) .$fontend . $end. '<br />' . "\n";
432 if (!$collapse ||
$boxes->is_root
) {
433 for ($i = 0; $i <count($boxes->mbxs
); $i++
) {
434 listBoxes($boxes->mbxs
[$i],$j);
439 function ListAdvancedBoxes ($boxes, $mbx, $j='ID.0000' ) {
440 global $data_dir, $username, $color, $unseen_notify, $unseen_type,
441 $move_to_trash, $trash_folder, $collapse_folders, $use_special_folder_color;
443 if (!isset($boxes) ||
empty($boxes))
446 /* use_folder_images only works if the images exist in ../images */
447 $use_folder_images = true;
452 $unseen_found = false;
455 $mailbox = $boxes->mailboxname_full
;
456 $mailboxURL = urlencode($mailbox);
458 /* get unseen/total messages information */
459 /* Only need to display info when option is set */
460 if (isset($unseen_notify) && ($unseen_notify > 1) &&
461 (($boxes->unseen
!== false) ||
($boxes->total
!== false))) {
463 if ($boxes->unseen
!== false)
464 $unseen = $boxes->unseen
;
467 Should only display unseen info if the folder is inbox
468 or you set the option for all folders
471 if ((strtolower($mailbox) == 'inbox') ||
($unseen_notify == 3)) {
472 $unseen_string = $unseen;
474 /* If users requests, display message count too */
475 if (isset($unseen_type) && ($unseen_type == 2) && ($boxes->total
!== false)) {
476 $unseen_string .= '/' . $boxes->total
;
479 $unseen_string = "<font color=\"$color[11]\">($unseen_string)</font>";
482 Finally allow the script to display the values by setting a boolean.
483 This can only occur if the unseen count is great than 0 (if you have
484 unseen count only), or you have the message count too.
486 if (($unseen > 0) ||
(isset($unseen_type) && ($unseen_type ==2))) {
487 $unseen_found = true;
492 /* If there are unseen message, bold the line. */
493 if ($unseen > 0) { $pre .= '<b>'; }
495 /* color special boxes */
496 if ($use_special_folder_color && $boxes->is_special
) {
497 $pre .= "<font color=\"$color[11]\">";
501 /* If there are unseen message, close bolding. */
502 if ($unseen > 0) { $end .= '</b>'; }
504 /* Print unseen information. */
506 $end .= " $unseen_string";
509 if (($move_to_trash) && ($mailbox == $trash_folder)) {
510 $pre = "<a class=\"mbx_link\" href=\"right_main.php?PG_SHOWALL=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\">" . $pre;
512 $end .= "\n<small>\n" .
513 ' [<a class="mbx_link" href="empty_trash.php">'._("Purge").'</a>]'.
516 if (!$boxes->is_noselect
) { /* \Noselect boxes can't be selected */
517 $pre = "<a class=\"mbx_link\" href=\"right_main.php?PG_SHOWALL=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\">" . $pre;
522 // let plugins fiddle with end of line
523 global $imapConnection;
524 $end .= concat_hook_function('left_main_after_each_folder',
525 array(isset($numMessages) ?
$numMessages : '',
526 $boxes->mailboxname_full
, $imapConnection));
528 if (!$boxes->is_root
) {
529 if ($use_folder_images) {
530 if ($boxes->is_inbox
) {
531 $folder_img = '../images/inbox.png';
532 } else if ($boxes->is_sent
) {
533 $folder_img = '../images/senti.png';
534 } else if ($boxes->is_trash
) {
535 $folder_img = '../images/delitem.png';
536 } else if ($boxes->is_draft
) {
537 $folder_img = '../images/draft.png';
538 } else if ($boxes->is_noinferiors
) {
539 $folder_img = '../images/folder_noinf.png';
541 $folder_img = '../images/folder.png';
543 $folder_img = ' <img src="'.$folder_img.'" height="15" valign="center" /> ';
547 if (!isset($boxes->mbxs
[0])) {
548 echo ' ' . html_tag( 'div',
549 '<tt>'. $pre . $folder_img . '</tt>'. str_replace(array(' ','<','>'),array(' ','<','>'),$boxes->mailboxname_sub
) . $end,
550 'left', '', 'class="mbx_sub" id="' .$j. '"' ) . "\n";
552 /* get collapse information */
553 if ($collapse_folders) {
554 $form_entry = $j.'F';
555 if (isset($mbx) && isset($mbx[$form_entry])) {
556 $collapse = $mbx[$form_entry];
557 setPref($data_dir, $username, 'collapse_folder_'.$boxes->mailboxname_full
, $collapse ? SM_BOX_COLLAPSED
: SM_BOX_UNCOLLAPSED
);
559 $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox);
560 $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED
: $collapse);
562 $img_src = ($collapse ?
'../images/plus.png' : '../images/minus.png');
563 $collapse_link = '<a href="javascript:void(0)">'." <img src=\"$img_src\" border=\"1\" id=$j onclick=\"hidechilds(this)\" style=\"cursor:hand\" /></a>";
567 echo ' ' . html_tag( 'div',
568 $collapse_link . $pre . $folder_img . ' '. $boxes->mailboxname_sub
. $end ,
569 'left', '', 'class="mbx_par" id="' .$j. 'P"' ) . "\n";
570 echo ' <input type="hidden" name="mbx['.$j. 'F]" value="'.$collapse.'" id="mbx['.$j.'F]" />'."\n";
574 $visible = ($collapse ?
' style="display:none"' : ' style="display:block"');
575 if (isset($boxes->mbxs
[0]) && !$boxes->is_root
) /* mailbox contains childs */
576 echo html_tag( 'div', '', 'left', '', 'class="par_area" id='.$j.'.0000 '. $visible ) . "\n";
580 for ($i = 0; $i <count($boxes->mbxs
); $i++
) {
582 ListAdvancedBoxes($boxes->mbxs
[$i],$mbx,$j);
584 if (isset($boxes->mbxs
[0]) && !$boxes->is_root
)
585 echo '</div>'."\n\n";
591 /* -------------------- MAIN ------------------------ */
594 sqgetGlobalVar('username', $username, SQ_SESSION
);
595 sqgetGlobalVar('key', $key, SQ_COOKIE
);
596 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
597 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION
);
599 sqgetGlobalVar('fold', $fold, SQ_GET
);
600 sqgetGlobalVar('unfold', $unfold, SQ_GET
);
604 // open a connection on the imap port (143)
605 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output
608 * Using stristr since older preferences may contain "None" and "none".
610 if (isset($left_refresh) && ($left_refresh != '') &&
611 !stristr($left_refresh, 'none')){
612 $xtra = "\n<meta http-equiv=\"Expires\" content=\"Thu, 01 Dec 1994 16:00:00 GMT\" />\n" .
613 "<meta http-equiv=\"Pragma\" content=\"no-cache\" />\n".
614 "<meta http-equiv=\"REFRESH\" content=\"$left_refresh;URL=left_main.php\" />\n";
620 * $advanced_tree and $oldway are boolean vars which are default set to default
622 * Setting $oldway to false causes left_main.php to use the new experimental
623 * way of getting the mailbox-tree.
624 * Setting $advanced tree to true causes SM to display a experimental
625 * mailbox-tree with dhtml behaviour.
626 * It only works on browsers which supports css and javascript. The used
627 * javascript is experimental and doesn't support all browsers.
628 * It has been tested on IE6 an Konquerer 3.0.0-2.
629 * It is now tested and working on: (please test and update this list)
630 * Windows: IE 5.5 SP2, IE 6 SP1, Gecko based (Mozilla, Firebird) and Opera7
633 * In the function ListAdvancedBoxes there is another var $use_folder_images.
634 * setting this to true is only usefull if the images exists in ../images.
636 * Feel free to experiment with the code and report bugs and enhancements
637 * to marc@its-projects.nl
640 /* set this to true if you want to see a nicer mailboxtree */
641 if (! isset($advanced_tree) ||
$advanced_tree=="" ) {
642 $advanced_tree=false;
644 /* default SM behaviour */
645 if (! isset($oldway) ||
$oldway=="" ) {
649 if ($advanced_tree) {
650 $xtra .= '<script language="Javascript" type="text/javascript">'."\n".
652 ' function preload() {'."\n".
653 ' if (document.images) {'."\n".
654 ' var treeImages = new Array;'."\n".
655 ' var arguments = preload.arguments;'."\n".
656 ' for (var i = 0; i<arguments.length; i++) {'."\n".
657 ' treeImages[i] = new Image();'."\n".
658 ' treeImages[i].src = arguments[i];'."\n".
662 'var vTreeImg;'."\n".
663 'var vTreeDiv;'."\n".
664 'var vTreeSrc;'."\n".
665 ' function fTreeTimeout() {'."\n".
666 ' if (vTreeDiv.readyState == "complete")'."\n".
667 ' vTreeImg.src = vTreeSrc;'."\n".
669 ' setTimeout("fTreeTimeout()", 100);'."\n".
671 ' function hidechilds(img) {'."\n".
672 ' id = img.id + ".0000";'."\n".
673 ' form_id = "mbx[" + img.id +"F]";'."\n".
674 ' if (document.all) { //IE, Opera7'."\n".
675 ' div = document.all[id];'."\n".
677 ' if (div.style.display == "none") {'."\n".
678 ' vTreeSrc = "../images/minus.png";'."\n".
679 ' style = "block";'."\n".
683 ' vTreeSrc = "../images/plus.png";'."\n".
684 ' style = "none";'."\n".
687 ' vTreeImg = img;'."\n".
688 ' vTreeDiv = div;'."\n".
689 ' if (typeof vTreeDiv.readyState != "undefined") //IE'."\n".
690 ' setTimeout("fTreeTimeout()",100);'."\n".
691 ' else //Non IE'."\n".
692 ' vTreeImg.src = vTreeSrc;'."\n".
693 ' div.style.display = style;'."\n".
694 ' document.all[form_id].value = value;'."\n".
697 ' else if (document.getElementById) { //Gecko'."\n".
698 ' div = document.getElementById(id);'."\n".
700 ' if (div.style.display == "none") {'."\n".
701 ' src = "../images/minus.png";'."\n".
702 ' style = "block";'."\n".
706 ' src = "../images/plus.png";'."\n".
707 ' style = "none";'."\n".
710 ' div.style.display = style;'."\n".
711 ' img.src = src;'."\n".
712 ' document.getElementById(form_id).value = value;'."\n".
716 ' function buttonover(el,on) {'."\n".
718 "// el.style.borderColor=\"$color[9]\";}\n".
719 " el.style.background=\"$color[0]\";}\n".
721 " el.style.background=\"$color[9]\";}\n".
723 ' function buttonclick(el,on) {'."\n".
725 ' el.style.border="groove";}'."\n".
727 ' el.style.border="ridge";}'."\n".
729 ' function hideframe(hide) {'."\n".
730 ' left_size = "' . $left_size . '";'."\n".
731 ' if (document.all) {'."\n".
732 ' masterf = window.parent.document.all["fs1"];'."\n".
733 ' leftf = window.parent.document.all["left"];'."\n".
734 ' leftcontent = document.all["leftframe"];'."\n".
735 ' leftbutton = document.all["showf"];'."\n".
736 ' } else if (document.getElementById) {'."\n".
737 ' masterf = window.parent.document.getElementById("fs1");'."\n".
738 ' leftf = window.parent.document.getElementById("left");'."\n".
739 ' leftcontent = document.getElementById("leftframe");'."\n".
740 ' leftbutton = document.getElementById("showf");'."\n".
742 ' return false;'."\n".
745 ' new_col = calc_col("20");'."\n".
746 ' masterf.cols = new_col;'."\n".
747 ' document.body.scrollLeft=0;'."\n".
748 ' document.body.style.overflow="hidden";'."\n".
749 ' leftcontent.style.display = "none";'."\n".
750 ' leftbutton.style.display="block";'."\n".
752 ' masterf.cols = calc_col(left_size);'."\n".
753 ' document.body.style.overflow="";'."\n".
754 ' leftbutton.style.display="none";'."\n".
755 ' leftcontent.style.display="block";'."\n".
758 ' function calc_col(c_w) {'."\n";
760 if ($location_of_bar == 'right') {
761 $xtra .= ' right=true;';
763 $xtra .= ' right=false;';
767 $xtra .= 'if (right) {'."\n".
768 " new_col = '*,'+c_w;"."\n".
770 " new_col = c_w+',*';"."\n".
772 ' return new_col;'."\n".
774 ' function resizeframe(direction) {'."\n".
775 ' if (document.all) {'."\n".
776 ' masterf = window.parent.document.all["fs1"];'."\n".
777 ' } else if (document.getElementById) {'."\n".
778 ' window.parent.document.getElementById("fs1");'."\n".
780 ' return false;'."\n".
783 if ($location_of_bar == 'right') {
784 $xtra .= ' colPat=/^\*,(\d+)$/;';
786 $xtra .= ' colPat=/^(\d+),.*$/;';
790 $xtra .= 'old_col = masterf.cols;'."\n".
791 ' colPat.exec(old_col);'."\n".
792 ' if (direction) {'."\n".
793 ' new_col_width = parseInt(RegExp.$1) + 25;'."\n".
795 ' if (parseInt(RegExp.$1) > 35) {'."\n".
796 ' new_col_width = parseInt(RegExp.$1) - 25;'."\n".
799 ' masterf.cols = calc_col(new_col_width);'."\n".
804 /* style definitions */
806 $xtra .= '<style type="text/css">'."\n".
809 ' margin: 0px 0px 0px 0px;'."\n".
810 ' padding: 5px 5px 5px 5px;'."\n".
813 ' border:outset;'."\n".
814 " border-color: $color[9];\n".
815 " background:$color[0];\n".
816 " color:$color[6];\n".
821 ' font-size:1.0em;'."\n".
822 ' margin-left:4px;'."\n".
823 ' margin-right:0px;'."\n".
825 ' a.mbx_link {'."\n".
826 ' text-decoration: none;'."\n".
827 " background-color: $color[0];\n".
828 ' display: inline;'."\n".
830 ' a:hover.mbx_link {'."\n".
831 " background-color: $color[9];\n".
833 ' a.mbx_link img {'."\n".
834 ' border-style: none;'."\n".
837 ' padding-left:5px;'."\n".
838 ' padding-right:0px;'."\n".
839 ' margin-left:4px;'."\n".
840 ' margin-right:0px;'."\n".
841 ' font-size:0.9em;'."\n".
844 ' margin-top:0px;'."\n".
845 ' margin-left:4px;'."\n".
846 ' margin-right:0px;'."\n".
847 ' padding-left:10px;'."\n".
848 ' padding-bottom:5px;'."\n".
849 ' border-left: solid;'."\n".
850 ' border-left-width:0.1em;'."\n".
851 " border-left-color:$color[9];\n".
852 ' border-bottom: solid;'."\n".
853 ' border-bottom-width:0.1em;'."\n".
854 " border-bottom-color:$color[9];\n".
855 ' display: block;'."\n".
857 ' .mailboxes {'."\n".
858 ' padding-bottom:3px;'."\n".
859 ' margin-right:4px;'."\n".
860 ' padding-right:4px;'."\n".
861 ' margin-left:4px;'."\n".
862 ' padding-left:4px;'."\n".
863 ' border: groove;'."\n".
864 ' border-width:0.1em;'."\n".
865 " border-color:$color[9];\n".
866 " background: $color[0];\n".
872 displayHtmlHeader( 'SquirrelMail', $xtra );
873 sqgetGlobalVar('auto_create_done',$auto_create_done,SQ_SESSION
);
874 /* If requested and not yet complete, attempt to autocreate folders. */
875 if ($auto_create_special && !isset($auto_create_done)) {
876 $autocreate = array($sent_folder, $trash_folder, $draft_folder);
877 foreach( $autocreate as $folder ) {
878 if (($folder != '') && ($folder != 'none')) {
879 if ( !sqimap_mailbox_exists($imapConnection, $folder)) {
880 sqimap_mailbox_create($imapConnection, $folder, '');
882 // check for subscription is useless and expensive, just
883 // surpress the NO response. Unless we're on Mecury, which
884 // will just subscribe a folder again if it's already
886 if ( strtolower($imap_server_type) != 'mercury32' ||
887 !sqimap_mailbox_is_subscribed($imapConnection, $folder) ) {
888 sqimap_subscribe($imapConnection, $folder, false);
894 /* Let the world know that autocreation is complete! Hurrah! */
895 $auto_create_done = TRUE;
896 sqsession_register($auto_create_done, 'auto_create_done');
899 if ($advanced_tree) {
901 ' onload="preload(\'../images/minus.png\',\'../images/plus.png\')"' .
902 " bgcolor=\"$color[3]\" text=\"$color[6]\" link=\"$color[6]\" vlink=\"$color[6]\" alink=\"$color[6]\">\n";
904 echo "\n<body bgcolor=\"$color[3]\" text=\"$color[6]\" link=\"$color[6]\" vlink=\"$color[6]\" alink=\"$color[6]\">\n";
907 do_hook('left_main_before');
908 if ($advanced_tree) {
909 /* nice future feature, needs layout !! volunteers? */
910 $right_pos = $left_size - 20;
911 /* 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><<</b></a></div>';
912 echo '<div id="showf" style="width=20;font-size:12;display:none;"><a href="javascript:hideframe(false)"><b>>></b></a></div>';
913 echo '<div id="incrf" style="width=20;font-size:12"><a href="javascript:resizeframe(true)"><b>></b></a></div>';
914 echo '<div id="decrf" style="width=20;font-size:12"><a href="javascript:resizeframe(false)"><b><</b></a></div></div>';
915 echo '<div id="leftframe"><br /><br />';*/
918 echo "\n\n" . html_tag( 'table', '', 'left', '', 'border="0" cellspacing="0" cellpadding="0" width="99%"' ) .
920 html_tag( 'td', '', 'left' ) .
921 html_tag( 'table', '', '', '', 'border="0" cellspacing="0" cellpadding="0" width="98%"' ) .
923 html_tag( 'td', '', 'center' ) .
924 '<font size="4"><b>'. _("Folders") . "</b><br /></font>\n\n";
926 if ($date_format != 6) {
927 /* First, display the clock. */
928 if ($hour_format == 1) {
930 if ($date_format == 4) {
934 if ($date_format == 4) {
941 switch( $date_format ) {
943 $clk = date('Y-m-d '.$hr. ' T', time());
946 $clk = date('m/d/y '.$hr, time());
949 $clk = date('d/m/y '.$hr, time());
953 $clk = date($hr, time());
956 $clk = getDayAbrv( date( 'w', time() ) ) . date( ', ' . $hr, time() );
958 $clk = str_replace(' ',' ',$clk);
960 echo '<small><span style="white-space: nowrap;">'
961 . str_replace(' ', ' ', _("Last Refresh"))
962 . ":</span><br /><span style=\"white-space: nowrap;\">$clk</span></small><br />";
965 /* Next, display the refresh button. */
966 echo '<div style="white-space: nowrap;"><small>[<a href="../src/left_main.php" target="left">'.
967 _("Check mail") . '</a>]</small></div></td></tr></table><br />';
969 /* Lastly, display the folder list. */
970 if ( $collapse_folders ) {
971 /* If directed, collapse or uncollapse a folder. */
973 setPref($data_dir, $username, 'collapse_folder_' . $fold, SM_BOX_COLLAPSED
);
974 } else if (isset($unfold)) {
975 setPref($data_dir, $username, 'collapse_folder_' . $unfold, SM_BOX_UNCOLLAPSED
);
979 /* Get unseen/total display prefs */
980 $unseen_type = getPref( $data_dir , $username , 'unseen_type' );
981 $unseen_notify = getPref( $data_dir , $username , 'unseen_notify' );
983 if (!isset($unseen_type) ||
empty($unseen_type)) {
984 if (isset($default_unseen_type) && !empty($default_unseen_type)) {
985 $unseen_type = $default_unseen_type;
991 if (!isset($unseen_notify) ||
empty($unseen_notify)) {
992 if (isset($default_unseen_notify) && !empty($default_unseen_notify)) {
993 $unseen_notify = $default_unseen_notify;
999 if ($oldway) { /* normal behaviour SM */
1001 $boxes = sqimap_mailbox_list($imapConnection);
1002 /* Prepare do do out collapsedness and visibility computation. */
1004 $boxcount = count($boxes);
1006 /* Compute the collapsedness and visibility of each box. */
1008 while ($curbox < $boxcount) {
1009 $boxes[$curbox]['visible'] = TRUE;
1010 compute_folder_children($curbox, $boxcount);
1013 for ($i = 0; $i < count($boxes); $i++
) {
1014 if ( $boxes[$i]['visible'] ) {
1015 $mailbox = $boxes[$i]['formatted'];
1016 $mblevel = substr_count($boxes[$i]['unformatted'], $delimiter) +
1;
1018 /* Create the prefix for the folder name and link. */
1019 $prefix = str_repeat(' ',$mblevel);
1020 if (isset($collapse_folders) && $collapse_folders && $boxes[$i]['parent']) {
1021 $prefix = str_replace(' ',' ',substr($prefix,0,strlen($prefix)-2)).
1022 create_collapse_link($i) . ' ';
1024 $prefix = str_replace(' ',' ',$prefix);
1026 $line = "<span style=\"white-space: nowrap;\"><tt>$prefix</tt>";
1028 /* Add the folder name and link. */
1029 if (! isset($color[15])) {
1030 $color[15] = $color[6];
1033 if (in_array('noselect', $boxes[$i]['flags'])) {
1034 if( isSpecialMailbox( $boxes[$i]['unformatted']) ) {
1035 $line .= "<font color=\"$color[11]\">";
1037 $line .= "<font color=\"$color[15]\">";
1039 if (ereg("^( *)([^ ]*)", $mailbox, $regs)) {
1040 $mailbox = str_replace(' ','',$mailbox);
1041 $line .= str_replace(' ', ' ', $mailbox);
1045 $line .= formatMailboxName($imapConnection, $boxes[$i]);
1048 /* Put the final touches on our folder line. */
1049 $line .= "</span><br />\n";
1051 /* Output the line for this folder. */
1055 } else { /* expiremental code */
1056 $boxes = sqimap_mailbox_tree($imapConnection);
1057 if (isset($advanced_tree) && $advanced_tree) {
1058 echo '<form name="collapse" action="left_main.php" method="post" ' .
1059 'enctype="multipart/form-data"'."\n";
1061 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 />';
1062 echo '<div id="mailboxes" class="mailboxes">'."\n\n";
1063 sqgetGlobalVar('mbx', $mbx, SQ_POST
);
1064 if (!isset($mbx)) $mbx=NULL;
1065 ListAdvancedBoxes($boxes, $mbx);
1068 echo '</form>'."\n";
1070 //sqimap_get_status_mbx_tree($imap_stream,$boxes)
1073 } /* if ($oldway) else ... */
1074 do_hook('left_main_after');
1075 sqimap_logout($imapConnection);