83175f63ae67eaf741072c6deb4ff675ddadea95
[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 * $Id$
13 * @package squirrelmail
14 */
15
16 /** Path for SquirrelMail required files. */
17 define('SM_PATH','../');
18
19 /* SquirrelMail required files. */
20 require_once(SM_PATH . 'include/validate.php');
21 require_once(SM_PATH . 'functions/imap.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');
25 require_once(SM_PATH . 'functions/date.php');
26
27 /* These constants are used for folder stuff. */
28 define('SM_BOX_UNCOLLAPSED', 0);
29 define('SM_BOX_COLLAPSED', 1);
30
31 /* --------------------- FUNCTIONS ------------------------- */
32
33 function formatMailboxName($imapConnection, $box_array) {
34
35 global $folder_prefix, $trash_folder, $sent_folder,
36 $color, $move_to_sent, $move_to_trash,
37 $unseen_notify, $unseen_type, $collapse_folders,
38 $draft_folder, $save_as_draft,
39 $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;sort=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(' ','&nbsp;',$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\" style=\"text-decoration:none\">"._("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, $imapConnection, $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, $unseen_type, $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, $startmessage, $color, $unseen_notify, $unseen_type,
297 $move_to_trash, $trash_folder, $collapse_folders, $imapConnection,
298 $use_icons, $icon_theme;
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;sort=0;startMessage=1&amp;mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
381 if ($unseen > 0) {
382 $end .= '</b>';
383 }
384 $end .= '</a>';
385 if ($boxes->total > 0) {
386 if ($unseen > 0) {
387 $pre .= '<b>';
388 }
389 $pre .= "<a href=\"right_main.php?PG_SHOWALL=0&amp;sort=0;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\" style=\"text-decoration:none\">"._("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;sort=0&amp;startMessage=1&amp;mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
407 if ($unseen > 0) {
408 $end .= '</b>';
409 }
410 $end .= '</a>';
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 ($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. $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, $startmessage, $color, $unseen_notify, $unseen_type,
447 $move_to_trash, $trash_folder, $collapse_folders;
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 ($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;sort=0&amp;startMessage=1&amp;mailbox=$mailboxURL\" target=\"right\">" . $pre;
520 $end .= '</a>';
521 if ($numMessages > 0) {
522 $urlMailbox = urlencode($mailbox);
523 $end .= "\n<small>\n" .
524 "&nbsp;&nbsp;(<a class=\"mbx_link\" href=\"empty_trash.php\">"._("purge")."</a>)" .
525 "</small>";
526 }
527 } else {
528 if (!$boxes->is_noselect) { /* \Noselect boxes can't be selected */
529 $pre = "<a class=\"mbx_link\" href=\"right_main.php?PG_SHOWALL=0&amp;sort=0&amp;startMessage=1&amp;mailbox=$mailboxURL\" target=\"right\">" . $pre;
530 $end .= '</a>';
531 }
532 }
533
534 // let plugins fiddle with end of line
535 global $imapConnection;
536 $end .= concat_hook_function('left_main_after_each_folder',
537 array(isset($numMessages) ? $numMessages : '',
538 $boxes->mailboxname_full, $imapConnection));
539
540 if (!$boxes->is_root) {
541 if ($use_folder_images) {
542 if ($boxes->is_inbox) {
543 $folder_img = '../images/inbox.png';
544 } else if ($boxes->is_sent) {
545 $folder_img = '../images/senti.png';
546 } else if ($boxes->is_trash) {
547 $folder_img = '../images/delitem.png';
548 } else if ($boxes->is_draft) {
549 $folder_img = '../images/draft.png';
550 } else if ($boxes->is_noinferiors) {
551 $folder_img = '../images/folder_noinf.png';
552 } else {
553 $folder_img = '../images/folder.png';
554 }
555 $folder_img = '&nbsp;<img src="'.$folder_img.'" height="15" valign="center" />&nbsp;';
556 } else {
557 $folder_img = '';
558 }
559 if (!isset($boxes->mbxs[0])) {
560 echo ' ' . html_tag( 'div',
561 '<tt>'. $pre . $folder_img . '</tt>'. $boxes->mailboxname_sub . $end,
562 'left', '', 'class="mbx_sub" id="' .$j. '"' ) . "\n";
563 } else {
564 /* get collapse information */
565 if ($collapse_folders) {
566 $form_entry = $j.'F';
567 if (isset($mbx) && isset($mbx[$form_entry])) {
568 $collapse = $mbx[$form_entry];
569 setPref($data_dir, $username, 'collapse_folder_'.$boxes->mailboxname_full , $collapse ? SM_BOX_COLLAPSED : SM_BOX_UNCOLLAPSED);
570 } else {
571 $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox);
572 $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED : $collapse);
573 }
574 $img_src = ($collapse ? '../images/plus.png' : '../images/minus.png');
575 $collapse_link = '<a href="javascript:void(0)">'." <img src=\"$img_src\" border=\"1\" id=$j onclick=\"hidechilds(this)\" style=\"cursor:hand\" /></a>";
576 } else {
577 $collapse_link='';
578 }
579 echo ' ' . html_tag( 'div',
580 $collapse_link . $pre . $folder_img . '&nbsp;'. $boxes->mailboxname_sub . $end ,
581 'left', '', 'class="mbx_par" id="' .$j. 'P"' ) . "\n";
582 echo ' <input type="hidden" name="mbx['.$j. 'F]" value="'.$collapse.'" id="mbx['.$j.'F]" />'."\n";
583 }
584 }
585
586 $visible = ($collapse ? ' style="display:none"' : ' style="display:block"');
587 if (isset($boxes->mbxs[0]) && !$boxes->is_root) /* mailbox contains childs */
588 echo html_tag( 'div', '', 'left', '', 'class="par_area" id='.$j.'.0000 '. $visible ) . "\n";
589
590 if ($j !='ID.0000')
591 $j = $j .'.0000';
592 for ($i = 0; $i <count($boxes->mbxs); $i++) {
593 $j++;
594 ListAdvancedBoxes($boxes->mbxs[$i],$mbx,$j);
595 }
596 if (isset($boxes->mbxs[0]) && !$boxes->is_root)
597 echo '</div>'."\n\n";
598 }
599
600
601
602
603 /* -------------------- MAIN ------------------------ */
604
605 /* get globals */
606 sqgetGlobalVar('username', $username, SQ_SESSION);
607 sqgetGlobalVar('key', $key, SQ_COOKIE);
608 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
609 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
610
611 sqgetGlobalVar('fold', $fold, SQ_GET);
612 sqgetGlobalVar('unfold', $unfold, SQ_GET);
613
614 /* end globals */
615
616 // open a connection on the imap port (143)
617 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output
618
619 /**
620 * Using stristr since older preferences may contain "None" and "none".
621 */
622 if (isset($left_refresh) && ($left_refresh != '') &&
623 !stristr($left_refresh, 'none')){
624 $xtra = "\n<meta http-equiv=\"Expires\" content=\"Thu, 01 Dec 1994 16:00:00 GMT\" />\n" .
625 "<meta http-equiv=\"Pragma\" content=\"no-cache\" />\n".
626 "<meta http-equiv=\"REFRESH\" content=\"$left_refresh;URL=left_main.php\" />\n";
627 } else {
628 $xtra = '';
629 }
630
631 /**
632 * $advanced_tree and $oldway are boolean vars which are default set to default
633 * SM behaviour.
634 * Setting $oldway to false causes left_main.php to use the new experimental
635 * way of getting the mailbox-tree.
636 * Setting $advanced tree to true causes SM to display a experimental
637 * mailbox-tree with dhtml behaviour.
638 * It only works on browsers which supports css and javascript. The used
639 * javascript is experimental and doesn't support all browsers.
640 * It has been tested on IE6 an Konquerer 3.0.0-2.
641 * It is now tested and working on: (please test and update this list)
642 * Windows: IE 5.5 SP2, IE 6 SP1, Gecko based (Mozilla, Firebird) and Opera7
643 * XWindow: ?
644 * Mac: ?
645 * In the function ListAdvancedBoxes there is another var $use_folder_images.
646 * setting this to true is only usefull if the images exists in ../images.
647 *
648 * Feel free to experiment with the code and report bugs and enhancements
649 * to marc@its-projects.nl
650 **/
651
652 /* set this to true if you want to see a nicer mailboxtree */
653 if (! isset($advanced_tree) || $advanced_tree=="" ) {
654 $advanced_tree=false;
655 }
656 /* default SM behaviour */
657 if (! isset($oldway) || $oldway=="" ) {
658 $oldway=false;
659 }
660
661 if ($advanced_tree) {
662 $xtra .= <<<ECHO
663 <script language="Javascript" TYPE="text/javascript">
664
665 <!--
666
667 function preload() {
668 if (document.images) {
669 var treeImages = new Array;
670 var arguments = preload.arguments;
671 for (var i = 0; i<arguments.length; i++) {
672 treeImages[i] = new Image();
673 treeImages[i].src = arguments[i];
674 }
675 }
676 }
677
678 var vTreeImg;
679 var vTreeDiv;
680 var vTreeSrc;
681
682 function fTreeTimeout() {
683 if (vTreeDiv.readyState == "complete")
684 vTreeImg.src = vTreeSrc;
685 else
686 setTimeout("fTreeTimeout()", 100);
687 }
688
689 function hidechilds(img) {
690 id = img.id + ".0000";
691 form_id = "mbx[" + img.id +"F]";
692 if (document.all) { //IE, Opera7
693 div = document.all[id];
694 if (div) {
695 if (div.style.display == "none") {
696 vTreeSrc = "../images/minus.png";
697 style = "block";
698 value = 0;
699 }
700 else {
701 vTreeSrc = "../images/plus.png";
702 style = "none";
703 value = 1;
704 }
705 vTreeImg = img;
706 vTreeDiv = div;
707 if (typeof vTreeDiv.readyState != "undefined") //IE
708 setTimeout("fTreeTimeout()",100);
709 else //Non IE
710 vTreeImg.src = vTreeSrc;
711 div.style.display = style;
712 document.all[form_id].value = value;
713 }
714 }
715 else if (document.getElementById) { //Gecko
716 div = document.getElementById(id);
717 if (div) {
718 if (div.style.display == "none") {
719 src = "../images/minus.png";
720 style = "block";
721 value = 0;
722 }
723 else {
724 src = "../images/plus.png";
725 style = "none";
726 value = 1;
727 }
728 div.style.display = style;
729 img.src = src;
730 document.getElementById(form_id).value = value;
731 }
732 }
733 }
734
735 function buttonover(el,on) {
736 if (!on) {
737 // el.style.borderColor="$color[9]";}
738 el.style.background="$color[0]";}
739 else {
740 el.style.background="$color[9]";}
741 }
742
743 function buttonclick(el,on) {
744 if (!on) {
745 el.style.border="groove";}
746 else {
747 el.style.border="ridge";}
748 }
749
750 function hideframe(hide) {
751
752 ECHO;
753 $xtra .= " left_size = \"$left_size\";\n";
754 $xtra .= <<<ECHO
755 if (document.all) {
756 masterf = window.parent.document.all["fs1"];
757 leftf = window.parent.document.all["left"];
758 leftcontent = document.all["leftframe"];
759 leftbutton = document.all["showf"];
760 } else if (document.getElementById) {
761 masterf = window.parent.document.getElementById("fs1");
762 leftf = window.parent.document.getElementById("left");
763 leftcontent = document.getElementById("leftframe");
764 leftbutton = document.getElementById("showf");
765 } else {
766 return false;
767 }
768 if(hide) {
769 new_col = calc_col("20");
770 masterf.cols = new_col;
771 document.body.scrollLeft=0;
772 document.body.style.overflow='hidden';
773 leftcontent.style.display = 'none';
774 leftbutton.style.display='block';
775 } else {
776 masterf.cols = calc_col(left_size);
777 document.body.style.overflow='';
778 leftbutton.style.display='none';
779 leftcontent.style.display='block';
780
781 }
782 }
783
784 function calc_col(c_w) {
785
786 ECHO;
787 if ($location_of_bar == 'right') {
788 $xtra .= ' right=true;';
789 } else {
790 $xtra .= ' right=false;';
791 }
792 $xtra .= "\n";
793 $xtra .= <<<ECHO
794 if (right) {
795 new_col = '*,'+c_w;
796 } else {
797 new_col = c_w+',*';
798 }
799 return new_col;
800 }
801
802 function resizeframe(direction) {
803 if (document.all) {
804 masterf = window.parent.document.all["fs1"];
805 } else if (document.getElementById) {
806 window.parent.document.getElementById("fs1");
807 } else {
808 return false;
809 }
810
811 ECHO;
812 if ($location_of_bar == 'right') {
813 $xtra .= ' colPat=/^\*,(\d+)$/;';
814 } else {
815 $xtra .= ' colPat=/^(\d+),.*$/;';
816 }
817 $xtra .= "\n";
818
819 $xtra .= <<<ECHO
820 old_col = masterf.cols;
821 colPat.exec(old_col);
822
823 if (direction) {
824 new_col_width = parseInt(RegExp.$1) + 25;
825
826 } else {
827 if (parseInt(RegExp.$1) > 35) {
828 new_col_width = parseInt(RegExp.$1) - 25;
829 }
830 }
831 masterf.cols = calc_col(new_col_width);
832 }
833
834 //-->
835
836 </script>
837
838 ECHO;
839
840 /* style definitions */
841
842 $xtra .= <<<ECHO
843
844 <style type="text/css">
845 <!--
846 body {
847 margin: 0px 0px 0px 0px;
848 padding: 5px 5px 5px 5px;
849 }
850
851 .button {
852 border:outset;
853 border-color: $color[9];
854 background:$color[0];
855 color:$color[6];
856 width:99%;
857 heigth:99%;
858 }
859
860 .mbx_par {
861 font-size:1.0em;
862 margin-left:4px;
863 margin-right:0px;
864 }
865
866 a.mbx_link {
867 text-decoration: none;
868 background-color: $color[0];
869 display: inline;
870 }
871
872 a:hover.mbx_link {
873 background-color: $color[9];
874 }
875
876 a.mbx_link img {
877 border-style: none;
878 }
879
880 .mbx_sub {
881 padding-left:5px;
882 padding-right:0px;
883 margin-left:4px;
884 margin-right:0px;
885 font-size:0.9em;
886 }
887
888 .par_area {
889 margin-top:0px;
890 margin-left:4px;
891 margin-right:0px;
892 padding-left:10px;
893 padding-bottom:5px;
894 border-left: solid;
895 border-left-width:0.1em;
896 border-left-color:$color[9];
897 border-bottom: solid;
898 border-bottom-width:0.1em;
899 border-bottom-color:$color[9];
900 display: block;
901 }
902
903 .mailboxes {
904 padding-bottom:3px;
905 margin-right:4px;
906 padding-right:4px;
907 margin-left:4px;
908 padding-left:4px;
909 border: groove;
910 border-width:0.1em;
911 border-color:$color[9];
912 background: $color[0];
913 }
914
915 -->
916
917 </style>
918
919 ECHO;
920
921 }
922
923 displayHtmlHeader( 'SquirrelMail', $xtra );
924
925 /* If requested and not yet complete, attempt to autocreate folders. */
926 if ($auto_create_special && !isset($auto_create_done)) {
927 $autocreate = array($sent_folder, $trash_folder, $draft_folder);
928 foreach( $autocreate as $folder ) {
929 if (($folder != '') && ($folder != 'none')) {
930 if ( !sqimap_mailbox_exists($imapConnection, $folder)) {
931 sqimap_mailbox_create($imapConnection, $folder, '');
932 } else if (!sqimap_mailbox_is_subscribed($imapConnection, $folder)) {
933 sqimap_subscribe($imapConnection, $folder);
934 }
935 }
936 }
937
938 /* Let the world know that autocreation is complete! Hurrah! */
939 $auto_create_done = TRUE;
940 sqsession_register($auto_create_done, 'auto_create_done');
941 }
942
943 if ($advanced_tree)
944 echo "\n<body" .
945 ' onload="preload(\'../images/minus.png\',\'../images/plus.png\')"' .
946 " bgcolor=\"$color[3]\" text=\"$color[6]\" link=\"$color[6]\" vlink=\"$color[6]\" alink=\"$color[6]\">\n";
947 else
948 echo "\n<body bgcolor=\"$color[3]\" text=\"$color[6]\" link=\"$color[6]\" vlink=\"$color[6]\" alink=\"$color[6]\">\n";
949
950 do_hook('left_main_before');
951 if ($advanced_tree) {
952 /* nice future feature, needs layout !! volunteers? */
953 $right_pos = $left_size - 20;
954 /* 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>';
955 echo '<div ID="showf" style="width=20;font-size:12;display:none;"><a href="javascript:hideframe(false)"><b>>></b></a></div>';
956 echo '<div ID="incrf" style="width=20;font-size:12"><a href="javascript:resizeframe(true)"><b>></b></a></div>';
957 echo '<div ID="decrf" style="width=20;font-size:12"><a href="javascript:resizeframe(false)"><b><</b></a></div></div>';
958 echo '<div ID="leftframe"><br /><br />';*/
959 }
960
961 echo "\n\n" . html_tag( 'table', '', 'left', '', 'border="0" cellspacing="0" cellpadding="0" width="99%"' ) .
962 html_tag( 'tr' ) .
963 html_tag( 'td', '', 'left' ) .
964 '<center><font size="4"><b>'. _("Folders") . "</b><br /></font>\n\n";
965
966 if ($date_format != 6) {
967 /* First, display the clock. */
968 if ($hour_format == 1) {
969 $hr = 'G:i';
970 if ($date_format == 4) {
971 $hr .= ':s';
972 }
973 } else {
974 if ($date_format == 4) {
975 $hr = 'g:i:s a';
976 } else {
977 $hr = 'g:i a';
978 }
979 }
980
981 switch( $date_format ) {
982 case 1:
983 $clk = date('m/d/y '.$hr, time());
984 break;
985 case 2:
986 $clk = date('d/m/y '.$hr, time());
987 break;
988 case 4:
989 case 5:
990 $clk = date($hr, time());
991 break;
992 default:
993 $clk = getDayAbrv( date( 'w', time() ) ) . date( ', ' . $hr, time() );
994 }
995 $clk = str_replace(' ','&nbsp;',$clk);
996
997 echo '<center><small>' . str_replace(' ','&nbsp;',_("Last Refresh")) .
998 ": $clk</small></center>";
999 }
1000
1001 /* Next, display the refresh button. */
1002 echo '<small>(<a href="../src/left_main.php" target="left">'.
1003 _("refresh folder list") . '</a>)</small></center><br />';
1004
1005 /* Lastly, display the folder list. */
1006 if ( $collapse_folders ) {
1007 /* If directed, collapse or uncollapse a folder. */
1008 if (isset($fold)) {
1009 setPref($data_dir, $username, 'collapse_folder_' . $fold, SM_BOX_COLLAPSED);
1010 } else if (isset($unfold)) {
1011 setPref($data_dir, $username, 'collapse_folder_' . $unfold, SM_BOX_UNCOLLAPSED);
1012 }
1013 }
1014
1015 /* Get unseen/total display prefs */
1016 $unseen_type = getPref( $data_dir , $username , 'unseen_type' );
1017 $unseen_notify = getPref( $data_dir , $username , 'unseen_notify' );
1018
1019 if (!isset($unseen_type) || empty($unseen_type)) {
1020 if (isset($default_unseen_type) && !empty($default_unseen_type)) {
1021 $unseen_type = $default_unseen_type;
1022 } else {
1023 $unseen_type = 1;
1024 }
1025 }
1026
1027 if (!isset($unseen_notify) || empty($unseen_notify)) {
1028 if (isset($default_unseen_notify) && !empty($default_unseen_notify)) {
1029 $unseen_notify = $default_unseen_notify;
1030 } else {
1031 $unseen_notify = 0;
1032 }
1033 }
1034
1035 if ($oldway) { /* normal behaviour SM */
1036
1037 $boxes = sqimap_mailbox_list($imapConnection);
1038 /* Prepare do do out collapsedness and visibility computation. */
1039 $curbox = 0;
1040 $boxcount = count($boxes);
1041
1042 /* Compute the collapsedness and visibility of each box. */
1043
1044 while ($curbox < $boxcount) {
1045 $boxes[$curbox]['visible'] = TRUE;
1046 compute_folder_children($curbox, $boxcount);
1047 }
1048
1049 for ($i = 0; $i < count($boxes); $i++) {
1050 if ( $boxes[$i]['visible'] ) {
1051 $mailbox = $boxes[$i]['formatted'];
1052 $mblevel = substr_count($boxes[$i]['unformatted'], $delimiter) + 1;
1053
1054 /* Create the prefix for the folder name and link. */
1055 $prefix = str_repeat(' ',$mblevel);
1056 if (isset($collapse_folders) && $collapse_folders && $boxes[$i]['parent']) {
1057 $prefix = str_replace(' ','&nbsp;',substr($prefix,0,strlen($prefix)-2)).
1058 create_collapse_link($i) . '&nbsp;';
1059 } else {
1060 $prefix = str_replace(' ','&nbsp;',$prefix);
1061 }
1062 $line = "<nobr><tt>$prefix</tt>";
1063
1064 /* Add the folder name and link. */
1065 if (! isset($color[15])) {
1066 $color[15] = $color[6];
1067 }
1068
1069 if (in_array('noselect', $boxes[$i]['flags'])) {
1070 if( isSpecialMailbox( $boxes[$i]['unformatted']) ) {
1071 $line .= "<font color=\"$color[11]\">";
1072 } else {
1073 $line .= "<font color=\"$color[15]\">";
1074 }
1075 if (ereg("^( *)([^ ]*)", $mailbox, $regs)) {
1076 $mailbox = str_replace('&nbsp;','',$mailbox);
1077 $line .= str_replace(' ', '&nbsp;', $mailbox);
1078 }
1079 $line .= '</font>';
1080 } else {
1081 $line .= formatMailboxName($imapConnection, $boxes[$i]);
1082 }
1083
1084 /* Put the final touches on our folder line. */
1085 $line .= "</nobr><br>\n";
1086
1087 /* Output the line for this folder. */
1088 echo $line;
1089 }
1090 }
1091 } else { /* expiremental code */
1092 $boxes = sqimap_mailbox_tree($imapConnection);
1093 if (isset($advanced_tree) && $advanced_tree) {
1094 echo '<form name="collapse" action="left_main.php" method="post" ' .
1095 'enctype="multipart/form-data"'."\n";
1096 echo '<small>';
1097 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 />';
1098 echo '<div id="mailboxes" class="mailboxes">'."\n\n";
1099 sqgetGlobalVar('mbx', $mbx, SQ_POST);
1100 if (!isset($mbx)) $mbx=NULL;
1101 ListAdvancedBoxes($boxes, $mbx);
1102 echo '</div>';
1103 echo '</small>';
1104 echo '</form>'."\n";
1105 } else {
1106 //sqimap_get_status_mbx_tree($imap_stream,$boxes)
1107 ListBoxes($boxes);
1108 }
1109 } /* if ($oldway) else ... */
1110 do_hook('left_main_after');
1111 sqimap_logout($imapConnection);
1112
1113 echo '</td></tr></table>' . "\n".
1114 "</div></body></html>\n";
1115
1116 ?>