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