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