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