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