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