6 * Copyright (c) 1999-2002 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.
15 /* Path for SquirrelMail required files. */
16 define('SM_PATH','../');
18 /* SquirrelMail required files. */
19 require_once(SM_PATH
. 'include/validate.php');
20 require_once(SM_PATH
. 'functions/array.php');
21 require_once(SM_PATH
. 'functions/imap.php');
22 require_once(SM_PATH
. 'functions/plugin.php');
23 require_once(SM_PATH
. 'functions/page_header.php');
24 require_once(SM_PATH
. 'functions/html.php');
26 /* These constants are used for folder stuff. */
27 define('SM_BOX_UNCOLLAPSED', 0);
28 define('SM_BOX_COLLAPSED', 1);
30 /* --------------------- FUNCTIONS ------------------------- */
32 function formatMailboxName($imapConnection, $box_array) {
34 global $folder_prefix, $trash_folder, $sent_folder,
35 $color, $move_to_sent, $move_to_trash,
36 $unseen_notify, $unseen_type, $collapse_folders,
37 $draft_folder, $save_as_draft,
38 $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 list($unseen_string, $unseen) = create_unseen_string($real_box, $box_array, $imapConnection);
50 $special_color = ($use_special_folder_color && isSpecialMailbox($real_box));
52 /* Start off with a blank line. */
55 /* If there are unseen message, bold the line. */
56 if ($unseen > 0) { $line .= '<B>'; }
58 /* Create the link for this folder. */
59 $line .= '<a href="right_main.php?PG_SHOWALL=0&sort=0&startMessage=1&mailbox='.
60 $mailboxURL.'" TARGET="right" STYLE="text-decoration:none">';
63 $line .= "<font color=\"$color[11]\">";
65 if ( $mailbox == 'INBOX' ) {
68 $line .= str_replace(' ',' ',$mailbox);
70 if ($special_color == TRUE)
74 /* If there are unseen message, close bolding. */
75 if ($unseen > 0) { $line .= "</B>"; }
77 /* Print unseen information. */
78 if ($unseen_string != '') {
79 $line .= " <SMALL>$unseen_string</SMALL>";
82 if (($move_to_trash) && ($real_box == $trash_folder)) {
83 if (! isset($numMessages)) {
84 $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
87 if ($numMessages > 0) {
88 $urlMailbox = urlencode($real_box);
89 $line .= "\n<small>\n" .
90 " (<A HREF=\"empty_trash.php\" style=\"text-decoration:none\">"._("purge")."</A>)" .
95 /* Return the final product. */
100 * Recursive function that computes the collapsed status and parent
101 * (or not parent) status of this box, and the visiblity and collapsed
102 * status and parent (or not parent) status for all children boxes.
104 function compute_folder_children(&$parbox, $boxcount) {
105 global $boxes, $data_dir, $username, $collapse_folders;
106 $nextbox = $parbox +
1;
108 /* Retreive the name for the parent box. */
109 $parbox_name = $boxes[$parbox]['unformatted'];
111 /* 'Initialize' this parent box to childless. */
112 $boxes[$parbox]['parent'] = FALSE;
114 /* Compute the collapse status for this box. */
115 if( isset($collapse_folders) && $collapse_folders ) {
116 $collapse = getPref($data_dir, $username, 'collapse_folder_' . $parbox_name);
117 $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED
: $collapse);
119 $collapse = SM_BOX_UNCOLLAPSED
;
121 $boxes[$parbox]['collapse'] = $collapse;
123 /* Otherwise, get the name of the next box. */
124 if (isset($boxes[$nextbox]['unformatted'])) {
125 $nextbox_name = $boxes[$nextbox]['unformatted'];
130 /* Compute any children boxes for this box. */
131 while (($nextbox < $boxcount) &&
132 (is_parent_box($boxes[$nextbox]['unformatted'], $parbox_name))) {
134 /* Note that this 'parent' box has at least one child. */
135 $boxes[$parbox]['parent'] = TRUE;
137 /* Compute the visiblity of this box. */
138 $boxes[$nextbox]['visible'] = ($boxes[$parbox]['visible'] &&
139 ($boxes[$parbox]['collapse'] != SM_BOX_COLLAPSED
));
141 /* Compute the visibility of any child boxes. */
142 compute_folder_children($nextbox, $boxcount);
145 /* Set the parent box to the current next box. */
150 * Create the link for a parent folder that will allow that
151 * parent folder to either be collapsed or expaned, as is
152 * currently appropriate.
154 function create_collapse_link($boxnum) {
155 global $boxes, $imapConnection, $unseen_notify, $color;
156 $mailbox = urlencode($boxes[$boxnum]['unformatted']);
158 /* Create the link for this collapse link. */
159 $link = '<a target="left" style="text-decoration:none" ' .
160 'href="left_main.php?';
161 if ($boxes[$boxnum]['collapse'] == SM_BOX_COLLAPSED
) {
162 $link .= "unfold=$mailbox\">+";
164 $link .= "fold=$mailbox\">-";
168 /* Return the finished product. */
173 * create_unseen_string:
175 * Create unseen and total message count for both this folder and
178 * @param string $boxName name of the current mailbox
179 * @param array $boxArray array for the current mailbox
180 * @param $imapConnection current imap connection in use
181 * @return array[0] unseen message string (for display)
182 * @return array[1] unseen message count
184 function create_unseen_string($boxName, $boxArray, $imapConnection) {
185 global $boxes, $unseen_type, $color;
187 /* Initialize the return value. */
190 /* Initialize the counts for this folder. */
192 $boxMessageCount = 0;
193 $totalUnseenCount = 0;
194 $totalMessageCount = 0;
196 /* Collect the counts for this box alone. */
197 $boxUnseenCount = sqimap_unseen_messages($imapConnection, $boxName);
198 if ($unseen_type == 2) {
199 $boxMessageCount = sqimap_get_num_messages($imapConnection, $boxName);
202 /* Initialize the total counts. */
204 if ($boxArray['collapse'] == SM_BOX_COLLAPSED
) {
205 /* Collect the counts for this boxes subfolders. */
206 $curBoxLength = strlen($boxName);
207 $boxCount = count($boxes);
209 for ($i = 0; $i < $boxCount; ++
$i) {
210 /* Initialize the counts for this subfolder. */
212 $subMessageCount = 0;
214 /* Collect the counts for this subfolder. */
215 if (($boxName != $boxes[$i]['unformatted'])
216 && (substr($boxes[$i]['unformatted'], 0, $curBoxLength) == $boxName)
217 && !in_array('noselect', $boxes[$i]['flags'])) {
218 $subUnseenCount = sqimap_unseen_messages($imapConnection, $boxes[$i]['unformatted']);
219 if ($unseen_type == 2) {
220 $subMessageCount = sqimap_get_num_messages($imapConnection, $boxes[$i]['unformatted']);
223 /* Add the counts for this subfolder to the total. */
224 $totalUnseenCount +
= $subUnseenCount;
225 $totalMessageCount +
= $subMessageCount;
229 /* Add the counts for all subfolders to that of the box. */
230 $boxUnseenCount +
= $totalUnseenCount;
231 $boxMessageCount +
= $totalMessageCount;
234 /* And create the magic unseen count string. */
235 /* Really a lot more then just the unseen count. */
236 if (($unseen_type == 1) && ($boxUnseenCount > 0)) {
237 $result[0] = "($boxUnseenCount)";
238 } else if ($unseen_type == 2) {
239 $result[0] = "($boxUnseenCount/$boxMessageCount)";
240 $result[0] = "<font color=\"$color[11]\">$result[0]</font>";
243 /* Set the unseen count to return to the outside world. */
244 $result[1] = $boxUnseenCount;
246 /* Return our happy result. */
251 * This simple function checks if a box is another box's parent.
253 function is_parent_box($curbox_name, $parbox_name) {
256 /* Extract the name of the parent of the current box. */
257 $curparts = explode($delimiter, $curbox_name);
258 $curname = array_pop($curparts);
259 $actual_parname = implode($delimiter, $curparts);
260 $actual_parname = substr($actual_parname,0,strlen($parbox_name));
262 /* Compare the actual with the given parent name. */
263 return ($parbox_name == $actual_parname);
266 function listBoxes ($boxes, $j=0 ) {
267 global $data_dir, $username, $startmessage, $color, $unseen_notify, $unseen_type,
268 $move_to_trash, $trash_folder, $collapse_folders;
273 $mailbox = $boxes->mailboxname_full
;
275 for ($k = 0; $k < $j; $k++
) {
276 $leader.= '   ';
278 $mailboxURL = urlencode($mailbox);
280 /* get unseen/total messages information */
281 if ($boxes->unseen
) {
282 $unseen = $boxes->unseen
;
283 $unseen_string = "($unseen)";
284 if ($unseen>0) $unseen_found = TRUE;
286 $numMessages = $boxes->total
;
287 $unseen_string = "<font color=\"$color[11]\">($unseen/$numMessages)</font>";
293 if (isset($boxes->mbxs
[0]) && $collapse_folders) {
294 $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox);
295 $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED
: $collapse);
297 $link = '<a target="left" style="text-decoration:none" ' .'href="left_main.php?';
299 $link .= "unfold=$mailboxURL\">$leader + ";
301 $link .= "fold=$mailboxURL\">$leader - ";
306 $pre.= $leader . '   ';
310 /* If there are unseen message, bold the line. */
311 if ($unseen > 0) { $pre .= '<B>'; }
313 if (($move_to_trash) && ($mailbox == $trash_folder)) {
314 if (! isset($numMessages)) {
315 $numMessages = sqimap_get_num_messages($imapConnection, $mailbox);
318 if ($numMessages > 0) {
319 $urlMailbox = urlencode($mailbox);
320 $pre .= "\n<small>\n" .
321 " (<A HREF=\"empty_trash.php\" style=\"text-decoration:none\">"._("purge")."</A>)" .
325 if (!$boxes->is_noselect
) {
326 $pre .= "<a HREF=\"right_main.php?PG_SHOWALL=0&sort=0&startMessage=1&mailbox=$mailboxURL\" TARGET=\"right\">";
331 /* If there are unseen message, close bolding. */
332 if ($unseen > 0) { $end .= "</B>"; }
334 /* Print unseen information. */
335 if (isset($unseen_found) && $unseen_found) {
336 $end .= " <SMALL>$unseen_string</SMALL>";
341 if ($boxes->is_special
) {
342 $font = "<FONT COLOR=\"$color[11]\">";
343 $fontend = "</FONT>";
346 if (!$boxes->is_root
) {
347 echo "" . $pre .$font. $boxes->mailboxname_sub
.$fontend . $end. '<br>';
350 if (!$collapse ||
$boxes->is_root
) {
351 for ($i = 0; $i <count($boxes->mbxs
); $i++
) {
352 listBoxes($boxes->mbxs
[$i],$j);
359 function ListAdvancedBoxes ($boxes, $mbx, $j='ID.0000' ) {
360 global $data_dir, $username, $startmessage, $color, $unseen_notify, $unseen_type,
361 $move_to_trash, $trash_folder, $collapse_folders;
363 /* use_folder_images only works if the images exist in ../images */
364 $use_folder_images = true;
371 $mailbox = $boxes->mailboxname_full
;
372 $mailboxURL = urlencode($mailbox);
374 /* get unseen/total messages information */
375 if ($boxes->unseen
) {
376 $unseen = $boxes->unseen
;
377 $unseen_string = "($unseen)";
378 if ($unseen>0) $unseen_found = TRUE;
380 $numMessages = $boxes->total
;
381 $unseen_string = "<font color=\"$color[11]\">($unseen/$numMessages)</font>";
385 /* If there are unseen message, bold the line. */
386 if ($unseen > 0) { $pre .= '<B>'; }
388 /* color special boxes */
389 if ($boxes->is_special
) {
390 $pre .= "<FONT COLOR=\"$color[11]\">";
394 /* If there are unseen message, close bolding. */
395 if ($unseen > 0) { $end .= "</B>"; }
397 /* Print unseen information. */
398 if (isset($unseen_found) && $unseen_found) {
399 $end .= " $unseen_string";
402 if (($move_to_trash) && ($mailbox == $trash_folder)) {
403 if (! isset($numMessages)) {
404 $numMessages = $boxes->total
;
406 if ($numMessages > 0) {
407 $urlMailbox = urlencode($mailbox);
408 $pre .= "\n<small>\n" .
409 " (<a class=\"mbx_link\" HREF=\"empty_trash.php\">"._("purge")."</a>)" .
413 if (!$boxes->is_noselect
) { /* \Noselect boxes can't be selected */
414 $pre .= "<a class=\"mbx_link\" HREF=\"right_main.php?PG_SHOWALL=0&sort=0&startMessage=1&mailbox=$mailboxURL\" TARGET=\"right\">";
419 if (!$boxes->is_root
) {
420 if ($use_folder_images) {
421 if ($boxes->is_inbox
) {
422 $folder_img = '../images/inbox.gif';
423 } else if ($boxes->is_sent
) {
424 $folder_img = '../images/senti.gif';
425 } else if ($boxes->is_trash
) {
426 $folder_img = '../images/delitem.gif';
427 } else if ($boxes->is_draft
) {
428 $folder_img = '../images/draft.gif';
429 } else $folder_img = '../images/folder.gif';
430 $folder_img = ' <img src="'.$folder_img.'" height="15" valign="center"> ';
431 } else $folder_img = '';
432 if (!isset($boxes->mbxs
[0])) {
433 echo ' ' . html_tag( 'div',
434 $pre . $folder_img . $boxes->mailboxname_sub
. $end ,
435 'left', '', 'class="mbx_sub" id="' .$j. '"' )
438 /* get collapse information */
439 if ($collapse_folders) {
440 $link = '<a target="left" style="text-decoration:none" ' .'href="left_main.php?';
441 $form_entry = $j.'F';
442 if (isset($mbx) && isset($mbx[$form_entry])) {
443 $collapse = $mbx[$form_entry];
445 setPref($data_dir, $username, 'collapse_folder_'.$boxes->mailboxname_full
, SM_BOX_COLLAPSED
);
447 setPref($data_dir, $username, 'collapse_folder_'.$boxes->mailboxname_full
, SM_BOX_UNCOLLAPSED
);
450 $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox);
451 $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED
: $collapse);
454 $link = '<a href="javascript:void(0)">'." <img src=\"../images/plus.gif\" border=\"1\" id=$j onclick=\"hidechilds(this)\"></A>";
456 $link = '<a href="javascript:void(0)">'."<img src=\"../images/minus.gif\" border=\"1\" id=$j onclick=\"hidechilds(this)\"></a>";
458 $collapse_link = $link;
459 } else $collapse_link='';
460 echo ' ' . html_tag( 'div',
461 $collapse_link . $pre . $folder_img . ' '. $boxes->mailboxname_sub
. $end ,
462 'left', '', 'class="mbx_par" id="' .$j. 'P"' )
464 echo ' <INPUT TYPE="hidden" name=mbx['.$j. 'F] value="'.$collapse.'" id="mbx['.$j.'F]">'."\n";
468 $visible = ' STYLE="display:none;"';
470 $visible = ' STYLE="display:block;"';
473 if (isset($boxes->mbxs
[0]) && !$boxes->is_root
) /* mailbox contains childs */
474 echo html_tag( 'div', '', 'left', '', 'class="par_area" id='.$j.'.0000 '. $visible ) . "\n";
476 if ($j !='ID.0000') {
479 for ($i = 0; $i <count($boxes->mbxs
); $i++
) {
481 listAdvancedBoxes($boxes->mbxs
[$i],$mbx,$j);
483 if (isset($boxes->mbxs
[0]) && !$boxes->is_root
) echo '</div>'."\n\n";
490 /* -------------------- MAIN ------------------------ */
492 global $delimiter, $default_folder_prefix, $left_size;
494 // open a connection on the imap port (143)
495 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output
498 * Using stristr since older preferences may contain "None" and "none".
500 if (isset($left_refresh) && ($left_refresh != '') &&
501 !stristr($left_refresh, "none")){
502 $xtra = "\n<META HTTP-EQUIV=\"Expires\" CONTENT=\"Thu, 01 Dec 1994 16:00:00 GMT\">\n" .
503 "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n".
504 "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"$left_refresh;URL=left_main.php\">\n";
510 * $advanced_tree and $oldway are boolean vars which are default set to default
512 * Setting $oldway to false causes left_main.php to use the new experimental
513 * way of getting the mailbox-tree.
514 * Setting $advanced tree to true causes SM to display a experimental
515 * mailbox-tree with dhtml behaviour.
516 * It only works on browsers which supports css and javascript. The used
517 * javascript is experimental and doesn't support all browsers. It is tested on
518 * IE6 an Konquerer 3.0.0-2.
519 * In the function ListAdvancedBoxes there is another var $use_folder_images.
520 * setting this to true is only usefull if the images exists in ../images.
522 * Feel free to experiment with the code and report bugs and enhancements
523 * to marc@its-projects.nl
526 $advanced_tree = false; /* set this to true if you want to see a nicer mailboxtree */
527 $oldway = true; /* default SM behaviour */
529 if ($advanced_tree) {
531 <script language="Javascript" TYPE="text/javascript">
535 function hidechilds(el) {
537 form_id = "mbx[" + el.id +"F]";
539 ele = document.all[id];
541 if(ele.style.display == "none") {
542 ele.style.display = "block";
543 ele.style.visibility = "visible"
544 el.src="../images/minus.gif";
545 document.all[form_id].value=0;
547 ele.style.display = "none";
548 ele.style.visibility = "hidden"
549 el.src="../images/plus.gif";
550 document.all[form_id].value=1;
553 } else if (document.getElementById) {
554 ele = document.getElementById(id);
556 if(ele.style.display == "none") {
557 ele.style.display = "block";
558 ele.style.visibility = "visible"
559 el.src="../images/minus.gif";
560 document.getElementById(form_id).value=0;
562 ele.style.display = "none";
563 ele.style.visibility = "hidden"
564 el.src="../images/plus.gif";
565 document.getElementById(form_id).value=1;
572 if (!document.images) return;
573 var ar = new Array();
574 var arguments = preload.arguments;
575 for (var i = 0; i<arguments.length; i++) {
577 ar[i].src = arguments[i];
581 function buttonover(el,on) {
583 el.style.borderColor="blue";}
585 el.style.borderColor="orange";}
588 function buttonclick(el,on) {
590 el.style.border="groove"}
592 el.style.border="ridge";}
595 function hideframe(hide) {
598 $xtra .= " left_size = \"$left_size\";\n";
601 masterf = window.parent.document.all["fs1"];
602 leftf = window.parent.document.all["left"];
603 leftcontent = document.all["leftframe"];
604 leftbutton = document.all["showf"];
605 } else if (document.getElementById) {
606 masterf = window.parent.document.getElementById("fs1");
607 leftf = window.parent.document.getElementById("left");
608 leftcontent = document.getElementById("leftframe");
609 leftbutton = document.getElementById("showf");
614 new_col = calc_col("20");
615 masterf.cols = new_col;
616 document.body.scrollLeft=0;
617 document.body.style.overflow='hidden';
618 leftcontent.style.display = 'none';
619 leftbutton.style.display='block';
621 masterf.cols = calc_col(left_size);
622 document.body.style.overflow='';
623 leftbutton.style.display='none';
624 leftcontent.style.display='block';
629 function calc_col(c_w) {
632 if ($location_of_bar == 'right') {
633 $xtra .= ' right=true;';
635 $xtra .= ' right=false;';
647 function resizeframe(direction) {
649 masterf = window.parent.document.all["fs1"];
650 } else if (document.getElementById) {
651 window.parent.document.getElementById("fs1");
657 if ($location_of_bar == 'right') {
658 $xtra .= ' colPat=/^\*,(\d+)$/;';
660 $xtra .= ' colPat=/^(\d+),.*$/;';
665 old_col = masterf.cols;
666 colPat.exec(old_col);
669 new_col_width = parseInt(RegExp.$1) + 25;
672 if (parseInt(RegExp.$1) > 35) {
673 new_col_width = parseInt(RegExp.$1) - 25;
676 masterf.cols = calc_col(new_col_width);
685 /* style definitions */
689 <STYLE TYPE="text/css">
692 margin: 0px 0px 0px 0px;
693 padding: 5px 5px 5px 5px;
711 text-decoration: none;
712 background-color: $color[0];
717 background-color: $color[9];
739 border-left-width:0.1em;
740 border-left-color:blue;
741 border-bottom: solid;
742 border-bottom-width:0.1em;
743 border-bottom-color:blue;
756 background: $color[0];
770 displayHtmlHeader( 'SquirrelMail', $xtra );
772 /* If requested and not yet complete, attempt to autocreate folders. */
773 if ($auto_create_special && !isset($auto_create_done)) {
774 $autocreate = array($sent_folder, $trash_folder, $draft_folder);
775 foreach( $autocreate as $folder ) {
776 if (($folder != '') && ($folder != 'none')) {
777 if ( !sqimap_mailbox_exists($imapConnection, $folder)) {
778 sqimap_mailbox_create($imapConnection, $folder, '');
779 } else if (!sqimap_mailbox_is_subscribed($imapConnection, $folder)) {
780 sqimap_subscribe($imapConnection, $folder);
785 /* Let the world know that autocreation is complete! Hurrah! */
786 $auto_create_done = TRUE;
787 session_register('auto_create_done');
790 echo "\n<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">\n";
792 do_hook('left_main_before');
793 if ($advanced_tree) {
794 /* nice future feature, needs layout !! volunteers? */
795 $right_pos = $left_size - 20;
796 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>';
797 echo '<div ID="showf" style="width=20;font-size:12;display:none;"><A HREF="javascript:hideframe(false)"><b>>></b></a></div>';
798 echo '<div ID="incrf" style="width=20;font-size:12"><A HREF="javascript:resizeframe(true)"><b>></b></a></div>';
799 echo '<div ID="decrf" style="width=20;font-size:12"><A HREF="javascript:resizeframe(false)"><b><</b></a></div></div>';
800 echo '<div ID="leftframe"><br><br>';
803 echo "\n\n" . html_tag( 'table', '', '', '', 'border="0" cellspacing="0" cellpadding="0" width="100%"' ) .
805 html_tag( 'td', '', 'left' ) .
806 '<center><font size="4"><b>'. _("Folders") . "</b><br></font>\n\n";
808 if ($date_format != 6) {
809 /* First, display the clock. */
810 if ($hour_format == 1) {
812 if ($date_format == 4) {
816 if ($date_format == 4) {
823 switch( $date_format ) {
825 $clk = date('m/d/y '.$hr, time());
828 $clk = date('d/m/y '.$hr, time());
832 $clk = date($hr, time());
835 $clk = substr( getDayName( date( 'w', time() ) ), 0, 3 ) . date( ', ' . $hr, time() );
837 $clk = str_replace(' ',' ',$clk);
839 echo '<center><small>' . str_replace(' ',' ',_("Last Refresh")) .
840 ": $clk</small></center>";
843 /* Next, display the refresh button. */
844 echo '<small>(<a href="../src/left_main.php" target="left">'.
845 _("refresh folder list") . '</a>)</small></center><br>';
847 /* Lastly, display the folder list. */
848 if ( $collapse_folders ) {
849 /* If directed, collapse or uncollapse a folder. */
851 setPref($data_dir, $username, 'collapse_folder_' . $fold, SM_BOX_COLLAPSED
);
852 } else if (isset($unfold)) {
853 setPref($data_dir, $username, 'collapse_folder_' . $unfold, SM_BOX_UNCOLLAPSED
);
857 if ($oldway) { /* normal behaviour SM */
859 $boxes = sqimap_mailbox_list($imapConnection);
860 /* Prepare do do out collapsedness and visibility computation. */
862 $boxcount = count($boxes);
864 /* Compute the collapsedness and visibility of each box. */
866 while ($curbox < $boxcount) {
867 $boxes[$curbox]['visible'] = TRUE;
868 compute_folder_children($curbox, $boxcount);
872 for ($i = 0; $i < count($boxes); $i++
) {
873 if ( $boxes[$i]['visible'] ) {
874 $mailbox = $boxes[$i]['formatted'];
875 $mblevel = substr_count($boxes[$i]['unformatted'], $delimiter) +
1;
877 /* Create the prefix for the folder name and link. */
878 $prefix = str_repeat(' ',$mblevel);
879 if (isset($collapse_folders) && $collapse_folders && $boxes[$i]['parent']) {
880 $prefix = str_replace(' ',' ',substr($prefix,0,strlen($prefix)-2)).
881 create_collapse_link($i) . ' ';
883 $prefix = str_replace(' ',' ',$prefix);
885 $line = "<NOBR><TT>$prefix</TT>";
887 /* Add the folder name and link. */
888 if (! isset($color[15])) {
889 $color[15] = $color[6];
892 if (in_array('noselect', $boxes[$i]['flags'])) {
893 if( isSpecialMailbox( $boxes[$i]['unformatted']) ) {
894 $line .= "<FONT COLOR=\"$color[11]\">";
896 $line .= "<FONT COLOR=\"$color[15]\">";
898 if (ereg("^( *)([^ ]*)", $mailbox, $regs)) {
899 $mailbox = str_replace(' ','',$mailbox);
900 $line .= str_replace(' ', ' ', $mailbox);
904 $line .= formatMailboxName($imapConnection, $boxes[$i]);
907 /* Put the final touches on our folder line. */
908 $line .= "</NOBR><BR>\n";
910 /* Output the line for this folder. */
914 } else { /* expiremental code */
915 $boxes = sqimap_mailbox_tree($imapConnection);
916 if (isset($advanced_tree) && $advanced_tree) {
917 echo '<FORM name=collapse action="left_main.php" METHOD=POST' .
918 'ENCTYPE="multipart/form-data"'."\n";
919 echo '<small><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>';
920 echo '<DIV ID=mailboxes CLASS=mailboxes>'."\n\n";
921 if (!isset($mbx)) $mbx=NULL;
922 ListAdvancedBoxes($boxes, $mbx);
923 echo '</div></small>'."\n";
928 } /* if ($oldway) else ... */
929 do_hook('left_main_after');
930 sqimap_logout($imapConnection);
932 echo '</td></tr></table>' . "\n".
933 "</div></body></html>\n";