546e0b6644859776225b94f0f54c7bb56f28c394
6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This contains functions that display mailbox information, such as the
10 * table row that has sender, date, subject, etc...
15 require_once(SM_PATH
. 'functions/strings.php');
16 require_once(SM_PATH
. 'functions/html.php');
17 require_once(SM_PATH
. 'class/html.class.php');
18 require_once(SM_PATH
. 'functions/imap_mailbox.php');
20 /* Default value for page_selector_max. */
21 define('PG_SEL_MAX', 10);
23 function elapsed($start)
26 list($start2, $start1) = explode(" ", $start);
27 list($end2, $end1) = explode(" ", $end);
28 $diff1 = $end1 - $start1;
29 $diff2 = $end2 - $start2;
34 return $diff2 +
$diff1;
37 function printMessageInfo($imapConnection, $t, $not_last=true, $key, $mailbox,
38 $start_msg, $where, $what) {
40 $color, $msgs, $msort, $td_str, $msg,
41 $default_use_priority,
42 $message_highlight_list,
44 $indent_array, /* indent subject by */
45 $pos, /* Search postion (if any) */
46 $thread_sort_messages, /* thread sorting on/off */
47 $server_sort_order, /* sort value when using server-sorting */
49 $allow_server_sort; /* enable/disable server-side sorting */
50 $color_string = $color[4];
52 if ($GLOBALS['alt_index_colors']) {
53 if (!isset($row_count)) {
58 if (!isset($color[12])) {
59 $color[12] = '#EAEAEA';
61 $color_string = $color[12];
66 if($mailbox == 'None') {
67 $boxes = sqimap_mailbox_list($imapConnection);
68 $mailbox = $boxes[0]['unformatted'];
71 $urlMailbox = urlencode($mailbox);
73 if (handleAsSent($mailbox)) {
74 $msg['FROM'] = $msg['TO'];
76 $msg['FROM'] = parseAddress($msg['FROM'],1);
79 * This is done in case you're looking into Sent folders,
80 * because you can have multiple receivers.
83 $senderNames = $msg['FROM'];
85 if (sizeof($senderNames)){
86 foreach ($senderNames as $senderNames_part) {
87 if ($senderName != '') {
90 if ($senderNames_part[1]) {
91 $senderName .= decodeHeader($senderNames_part[1]);
93 $senderName .= htmlspecialchars($senderNames_part[0]);
97 $senderName = str_replace(' ',' ',$senderName);
98 echo html_tag( 'tr','','','','VALIGN="top"') . "\n";
100 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
101 $flag = "<font color=\"$color[2]\">";
102 $flag_end = '</font>';
107 if (!isset($msg['FLAG_SEEN']) ||
($msg['FLAG_SEEN'] == false)) {
114 if (handleAsSent($mailbox)) {
116 $italic_end = '</i>';
121 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
122 $fontstr = "<font color=\"$color[9]\">";
123 $fontstr_end = '</font>';
129 if ($where && $what) {
130 $searchstr = '&where='.$where.'&what='.$what;
135 if (is_array($message_highlight_list) && count($message_highlight_list)) {
136 $msg['TO'] = parseAddress($msg['TO']);
137 $msg['CC'] = parseAddress($msg['CC']);
138 foreach ($message_highlight_list as $message_highlight_list_part) {
139 if (trim($message_highlight_list_part['value']) != '') {
140 $high_val = strtolower($message_highlight_list_part['value']);
141 $match_type = strtoupper($message_highlight_list_part['match_type']);
142 if($match_type == 'TO_CC') {
143 $match = array('TO', 'CC');
145 $match = array($match_type);
147 foreach($match as $match_type) {
148 switch($match_type) {
152 foreach ($msg[$match_type] as $address) {
153 $address[0] = decodeHeader($address[0], true, false);
154 $address[1] = decodeHeader($address[1], true, false);
155 if (strstr('^^' . strtolower($address[0]), $high_val) ||
156 strstr('^^' . strtolower($address[1]), $high_val)) {
157 $hlt_color = $message_highlight_list_part['color'];
163 $headertest = strtolower(decodeHeader($msg[$match_type], true, false));
164 if (strstr('^^' . $headertest, $high_val)) {
165 $hlt_color = $message_highlight_list_part['color'];
175 if (!isset($hlt_color)) {
176 $hlt_color = $color_string;
178 $checked = ($checkall == 1) ?
' CHECKED' : '';
180 $msg['SUBJECT'] = decodeHeader($msg['SUBJECT']);
181 $subject = processSubject($msg['SUBJECT'], $indent_array[$msg['ID']]);
182 $subject = str_replace(' ',' ',$subject);
183 if (sizeof($index_order)) {
184 foreach ($index_order as $index_order_part) {
185 switch ($index_order_part) {
186 case 1: /* checkbox */
188 "<input type=checkbox name=\"msg[$t]\" value=\"".$msg['ID']."\"$checked>",
194 $italic . $bold . $flag . $fontstr . $senderName .
195 $fontstr_end . $flag_end . $bold_end . $italic_end,
200 $date_string = $msg['DATE_STRING'] . '';
201 if ($date_string == '') {
202 $date_string = _("Unknown date");
205 $bold . $flag . $fontstr . $date_string .
206 $fontstr_end . $flag_end . $bold_end,
211 case 4: /* subject */
213 if ($thread_sort_messages == 1) {
214 if (isset($indent_array[$msg['ID']])) {
215 $td_str .= str_repeat(" ",$indent_array[$msg['ID']]);
218 $td_str .= '<a href="read_body.php?mailbox='.$urlMailbox
219 . '&passed_id='. $msg["ID"]
220 . '&startMessage='.$start_msg.$searchstr.'"';
221 $td_str .= ' ' .concat_hook_function('subject_link', array($start_msg, $searchstr));
222 if ($subject != $msg['SUBJECT']) {
223 $title = get_html_translation_table(HTML_SPECIALCHARS
);
224 $title = array_flip($title);
225 $title = strtr($msg['SUBJECT'], $title);
226 $title = str_replace('"', "''", $title);
227 $td_str .= " title=\"$title\"";
229 $td_str .= ">$flag$subject$flag_end</a>$bold_end";
230 echo html_tag( 'td', $td_str, 'left', $hlt_color );
234 $td_str = "<b><small>";
236 if (isset($msg['FLAG_ANSWERED']) && $msg['FLAG_ANSWERED'] == true) {
240 if ($msg['TYPE0'] == 'multipart') {
244 if ($default_use_priority) {
245 if ( ($msg['PRIORITY'] == 1) ||
($msg['PRIORITY'] == 2) ) {
246 $td_str .= "<font color=\"$color[1]\">!</font>";
249 if ($msg['PRIORITY'] == 5) {
250 $td_str .= "<font color=\"$color[8]\">?</font>";
254 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'] == true) {
255 $td_str .= "<font color=\"$color[1]\">D</font>";
261 do_hook("msg_envelope");
262 $td_str .= '</small></b>';
271 $bold . $fontstr . show_readable_size($msg['SIZE']) .
272 $fontstr_end . $bold_end,
281 echo '</tr>' . "\n" . '<tr><td COLSPAN="' . $col . '" BGCOLOR="' .
282 $color[0] . '" HEIGHT="1"></td></tr>' . "\n";
288 function getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id) {
290 $id = array_slice($id, ($start_msg-1), $show_num);
291 $end = $start_msg +
$show_num - 1;
292 if ($num_msgs < $show_num) {
293 $end_loop = $num_msgs;
294 } else if ($end > $num_msgs) {
295 $end_loop = $num_msgs - $start_msg +
1;
297 $end_loop = $show_num;
298 } return fillMessageArray($imapConnection,$id,$end_loop,$show_num);
304 function getThreadMessages($imapConnection, $start_msg, $show_num, $num_msgs) {
305 $id = get_thread_sort($imapConnection);
306 return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
309 function getServerSortMessages($imapConnection, $start_msg, $show_num,
310 $num_msgs, $server_sort_order, $mbxresponse) {
311 $id = sqimap_get_sort_order($imapConnection, $server_sort_order,$mbxresponse);
312 return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
315 function getSelfSortMessages($imapConnection, $start_msg, $show_num,
316 $num_msgs, $sort, $mbxresponse) {
318 if ($num_msgs >= 1) {
319 $id = sqimap_get_php_sort_order ($imapConnection, $mbxresponse);
323 /* set shownum to 999999 to fool sqimap_get_small_header_list
324 and rebuild the msgs_str to 1:* */
327 /* if it's not sorted */
328 if ($start_msg +
($show_num - 1) < $num_msgs) {
329 $end_msg = $start_msg +
($show_num - 1);
331 $end_msg = $num_msgs;
333 if ($end_msg < $start_msg) {
334 $start_msg = $start_msg - $show_num;
335 if ($start_msg < 1) {
339 $id = array_slice(array_reverse($id), ($start_msg-1), $show_num);
340 $end = $start_msg +
$show_num - 1;
341 if ($num_msgs < $show_num) {
342 $end_loop = $num_msgs;
343 } else if ($end > $num_msgs) {
344 $end_loop = $num_msgs - $start_msg +
1;
346 $end_loop = $show_num;
348 } $msgs = fillMessageArray($imapConnection,$id,$end_loop, $show_num);
356 * This function loops through a group of messages in the mailbox
357 * and shows them to the user.
359 function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
360 $start_msg, $sort, $color, $show_num,
361 $use_cache, $mode='') {
362 global $msgs, $msort, $auto_expunge, $thread_sort_messages,
363 $allow_server_sort, $server_sort_order;
366 * For some reason, on PHP 4.3+, this being unset, and set in the session causes havoc
367 * so setting it to an empty array beforehand seems to clean up the issue, and stopping the
368 * "Your script possibly relies on a session side-effect which existed until PHP 4.2.3" error
371 if (!isset($msort)) {
379 //$start = microtime();
380 /* If autoexpunge is turned on, then do it now. */
381 $mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox);
383 /* If autoexpunge is turned on, then do it now. */
384 if ($auto_expunge == true) {
385 $exp_cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, false, '');
386 $mbxresponse['EXISTS'] = $mbxresponse['EXISTS'] - $exp_cnt;
387 $num_msgs = $mbxresponse['EXISTS'];
390 if ($mbxresponse['EXISTS'] > 0) {
391 /* if $start_msg is lower than $num_msgs, we probably deleted all messages
392 * in the last page. We need to re-adjust the start_msg
395 if($start_msg > $num_msgs) {
396 $start_msg -= $show_num;
402 /* This code and the next if() block check for
403 * server-side sorting methods. The $id array is
404 * formatted and $sort is set to 6 to disable
405 * SM internal sorting
408 if ($thread_sort_messages == 1) {
410 } elseif ($allow_server_sort == 1) {
411 $mode = 'serversort';
417 sqgetGlobalVar('msgs', $msgs, SQ_SESSION
);
418 sqgetGlobalVar('msort', $msort, SQ_SESSION
);
420 sqsession_unregister('msort');
421 sqsession_unregister('msgs'); }
424 $id = get_thread_sort($imapConnection);
425 $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
426 if ($msgs === false) {
427 echo '<b><small><center><font color=red>' .
428 _("Thread sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
429 '</center></small></b>';
430 $thread_sort_messages = 0;
431 $msort = $msgs = array();
438 $id = sqimap_get_sort_order($imapConnection, $sort, $mbxresponse);
439 $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
440 if ($msgs === false) {
441 echo '<b><small><center><font color=red>' .
442 _( "Server-side sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
443 '</center></small></b>';
444 $sort = $server_sort_order;
445 $allow_server_sort = FALSE;
446 $msort = $msgs = array();
455 $msgs = getSelfSortMessages($imapConnection, $start_msg, $show_num,
456 $num_msgs, $sort, $mbxresponse);
457 $msort = calc_msort($msgs, $sort);
461 sqsession_register($msort, 'msort');
462 sqsession_register($msgs, 'msgs');
464 } /* if exists > 0 */
466 $res = getEndMessage($start_msg, $show_num, $num_msgs);
467 $start_msg = $res[0];
470 $paginator_str = get_paginator_str($mailbox, $start_msg, $end_msg,
471 $num_msgs, $show_num, $sort);
473 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
475 do_hook('mailbox_index_before');
476 echo '<table border="0" width="100%" cellpadding="0" cellspacing="0">';
479 mail_message_listing_beginning($imapConnection, $mailbox, $sort,
480 $msg_cnt_str, $paginator_str, $start_msg);
482 /* line between the button area and the list */
483 echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>';
486 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
488 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[5].'">';
490 printHeader($mailbox, $srt, $color, !$thread_sort_messages);
492 displayMessageArray($imapConnection, $num_msgs, $start_msg,
493 $msort, $mailbox, $sort, $color, $show_num,0,0);
494 echo '</td></tr></table></td></tr></table>';
496 mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color);
497 echo '</td></tr></table>';
498 //$t = elapsed($start);
499 //echo("elapsed time = $t seconds\n");
502 function calc_msort($msgs, $sort) {
513 if (($sort == 0) ||
($sort == 1)) {
514 foreach ($msgs as $item) {
515 $msort[] = $item['TIME_STAMP'];
517 } elseif (($sort == 2) ||
($sort == 3)) {
518 foreach ($msgs as $item) {
519 $msort[] = $item['FROM-SORT'];
521 } elseif (($sort == 4) ||
($sort == 5)) {
522 foreach ($msgs as $item) {
523 $msort[] = $item['SUBJECT-SORT'];
538 function fillMessageArray($imapConnection, $id, $count, $show_num=false) {
539 return sqimap_get_small_header_list($imapConnection, $id, $show_num);
543 /* Generic function to convert the msgs array into an HTML table. */
544 function displayMessageArray($imapConnection, $num_msgs, $start_msg,
545 $msort, $mailbox, $sort, $color,
546 $show_num, $where=0, $what=0) {
547 global $imapServerAddress, $use_mailbox_cache, $index_order,
548 $indent_array, $thread_sort_messages, $allow_server_sort,
549 $server_sort_order, $PHP_SELF;
551 $res = getEndMessage($start_msg, $show_num, $num_msgs);
552 $start_msg = $res[0];
555 $urlMailbox = urlencode($mailbox);
557 /* get indent level for subject display */
558 if ($thread_sort_messages == 1 && $num_msgs) {
559 $indent_array = get_parent_level($imapConnection);
562 $real_startMessage = $start_msg;
564 if ($end_msg - $start_msg < $show_num - 1) {
565 $end_msg = $end_msg - $start_msg +
1;
567 } else if ($start_msg > $show_num) {
568 $end_msg = $show_num;
572 $endVar = $end_msg +
1;
575 * Loop through and display the info for each message.
576 * ($t is used for the checkbox number)
580 /* messages display */
583 /* if there's no messages in this folder */
586 "<BR><b>" . _("THIS FOLDER IS EMPTY") . "</b><BR> ",
589 'COLSPAN="' . count($index_order) . '"'
592 } elseif ($start_msg == $end_msg) {
593 /* if there's only one message in the box, handle it differently. */
605 } while (isset ($key) && ($k < $i));
606 printMessageInfo($imapConnection, $t, true, $key, $mailbox,
607 $real_startMessage, $where, $what);
616 } while (isset ($key) && ($k < $i));
619 if (!$i ||
$i == $endVar-1) $not_last = false;
620 printMessageInfo($imapConnection, $t, $not_last, $key, $mailbox,
621 $real_startMessage, $where, $what);
626 } while ($i && $i < $endVar);
631 * Displays the standard message list header. To finish the table,
632 * you need to do a "</table></table>";
634 * $moveURL is the URL to submit the delete/move form to
635 * $mailbox is the current mailbox
636 * $sort is the current sorting method (-1 for no sorting available [searches])
637 * $Message is a message that is centered on top of the list
638 * $More is a second line that is left aligned
641 function mail_message_listing_beginning ($imapConnection,
642 $mailbox = '', $sort = -1,
644 $paginator = ' ',
646 global $color, $auto_expunge, $base_uri, $thread_sort_messages,
647 $allow_thread_sort, $allow_server_sort, $server_sort_order,
650 $php_self = $PHP_SELF;
651 /* fix for incorrect $PHP_SELF */
652 if (strpos($php_self, 'move_messages.php')) {
653 $php_self = str_replace('move_messages.php', 'right_main.php', $php_self);
655 $urlMailbox = urlencode($mailbox);
657 if (preg_match('/^(.+)\?.+$/',$php_self,$regs)) {
658 $source_url = $regs[1];
660 $source_url = $php_self;
666 $moveFields = '<input type="hidden" name="msg" value="'.htmlspecialchars($msg).'">' .
667 '<input type="hidden" name="mailbox" value="'.htmlspecialchars($mailbox).'">' .
668 '<input type="hidden" name="startMessage" value="'.htmlspecialchars($start_msg).'">';
670 // $moveURL = "move_messages.php?msg=$msg&mailbox=$urlMailbox"
671 // . "&startMessage=$start_msg";
673 * This is the beginning of the message list table.
674 * It wraps around all messages
676 $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $mailbox);
677 $form_name = "FormMsgs" . $safe_name;
678 echo '<form name="' . $form_name . '" method="post" action="move_messages.php">' ."\n"
680 . html_tag( 'table' ,
685 html_tag( 'td', $paginator, 'left' ) .
686 html_tag( 'td', $msg_cnt_str, 'right' )
688 , '', $color[4], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
691 , '', '', 'border="0" width="100%" cellpadding="1" cellspacing="0"' );
692 /* line between header and button area */
693 echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>';
696 echo html_tag( 'tr' ) . "\n"
697 . html_tag( 'td' ,'' , 'left', '', '' )
698 . html_tag( 'table' ,'' , '', $color[9], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
700 . html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
702 getSmallStringCell(_("Move Selected To"), 'left', 'nowrap') .
703 getSmallStringCell(_("Transform Selected Messages"), 'right')
705 . html_tag( 'tr' ) ."\n"
706 . html_tag( 'td', '', 'left', '', 'valign="middle" nowrap' );
707 getMbxList($imapConnection);
708 echo getButton('SUBMIT', 'moveButton',_("Move")) . "\n";
709 echo getButton('SUBMIT', 'attache',_("Forward")) . "\n";
712 . html_tag( 'td', '', 'right', '', 'nowrap' );
716 if (!$auto_expunge) {
717 echo getButton('SUBMIT', 'expungeButton',_("Expunge"))
718 .' ' . _("mailbox") . "\n";
720 do_hook('mailbox_display_buttons');
721 echo getButton('SUBMIT', 'markRead',_("Read"));
722 echo getButton('SUBMIT', 'markUnread',_("Unread"));
723 echo getButton('SUBMIT', 'delete',_("Delete")) ." \n";
724 if (!strpos($php_self,'mailbox')) {
725 $location = $php_self.'?mailbox=INBOX&startMessage=1';
727 $location = $php_self;
729 echo '<INPUT TYPE="HIDDEN" NAME="location" VALUE="'.$location.'">';
733 /* draws thread sorting links */
734 if ($allow_thread_sort == TRUE) {
735 if ($thread_sort_messages == 1 ) {
737 $thread_name = _("Unthread View");
738 } elseif ($thread_sort_messages == 0) {
740 $thread_name = _("Thread View");
742 echo html_tag( 'tr' ,
744 ' <a href=' . $source_url . '?sort='
745 . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
746 . '&mailbox=' . urlencode($mailbox) . '><small>' . $thread_name
747 . '</a></small> '
752 echo "</TABLE></td></tr></table></td></tr>\n";
754 do_hook('mailbox_form_before');
756 /* if using server sort we highjack the
757 * the $sort var and use $server_sort_order
758 * instead. but here we reset sort for a bit
761 if ($allow_server_sort == TRUE) {
762 $sort = $server_sort_order;
766 function mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color) {
768 /* space between list and footer */
769 echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'" COLSPAN="1">';
771 echo '</td></tr><tr><td>';
772 echo html_tag( 'table',
777 html_tag( 'td', $paginator_str ) .
778 html_tag( 'td', $msg_cnt_str, 'right' )
780 , '', $color[4], 'width="100%" border="0" cellpadding="1" cellspacing="0"' )
783 , '', $color[9], 'width="100%" border="0" cellpadding="1" cellspacing="0"' );
786 /* End of message-list table */
788 do_hook('mailbox_index_after');
792 function printHeader($mailbox, $sort, $color, $showsort=true) {
794 echo html_tag( 'tr' ,'' , 'center', $color[5] );
796 /* calculate the width of the subject column based on the
797 * widths of the other columns */
798 $widths = array(1=>1,2=>25,3=>5,4=>0,5=>1,6=>5);
800 foreach($index_order as $item) {
801 $subjectwidth -= $widths[$item];
804 foreach ($index_order as $item) {
806 case 1: /* checkbox */
808 echo html_tag( 'td' ,' ' , '', '', 'width="1%"' );
811 if (handleAsSent($mailbox)) {
812 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
813 . '<b>' . _("To") . '</b>';
815 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
816 . '<b>' . _("From") . '</b>';
819 ShowSortButton($sort, $mailbox, 2, 3);
824 echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
825 . '<b>' . _("Date") . '</b>';
827 ShowSortButton($sort, $mailbox, 0, 1);
831 case 4: /* subject */
832 echo html_tag( 'td' ,'' , 'left', '', 'width="'.$subjectwidth.'%"' )
833 . '<b>' . _("Subject") . '</b>';
835 ShowSortButton($sort, $mailbox, 4, 5);
840 echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%" nowrap' );
849 * This function shows the sort button. Isn't this a good comment?
851 function ShowSortButton($sort, $mailbox, $Up, $Down ) {
853 /* Figure out which image we want to use. */
854 if ($sort != $Up && $sort != $Down) {
855 $img = 'sort_none.png';
857 } elseif ($sort == $Up) {
858 $img = 'up_pointer.png';
861 $img = 'down_pointer.png';
865 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
866 $source_url = $regs[1];
868 $source_url = $PHP_SELF;
871 /* Now that we have everything figured out, show the actual button. */
872 echo ' <a href="' . $source_url .'?newsort=' . $which
873 . '&startMessage=1&mailbox=' . urlencode($mailbox)
874 . '"><IMG SRC="../images/' . $img
875 . '" BORDER=0 WIDTH=12 HEIGHT=10 ALT="sort"></a>';
878 function get_selectall_link($start_msg, $sort) {
879 global $checkall, $what, $where, $mailbox, $javascript_on;
880 global $PHP_SELF, $PG_SHOWNUM;
883 if ($javascript_on) {
884 $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $mailbox);
885 $func_name = "CheckAll" . $safe_name;
886 $form_name = "FormMsgs" . $safe_name;
887 $result = '<script language="JavaScript" type="text/javascript">'
889 . "function " . $func_name . "() {\n"
890 . " for (var i = 0; i < document." . $form_name . ".elements.length; i++) {\n"
891 . " if(document." . $form_name . ".elements[i].type == 'checkbox'){\n"
892 . " document." . $form_name . ".elements[i].checked = "
893 . " !(document." . $form_name . ".elements[i].checked);\n"
898 . '</script><a href="javascript:void(0)" onClick="' . $func_name . '();">' . _("Toggle All")
899 /* . '</script><a href="javascript:' . $func_name . '()">' . _("Toggle All")*/
902 if (strpos($PHP_SELF, "?")) {
903 $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($mailbox)
904 . "&startMessage=$start_msg&sort=$sort&checkall=";
906 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
907 . "&startMessage=$start_msg&sort=$sort&checkall=";
909 if (isset($checkall) && $checkall == '1') {
915 if (isset($where) && isset($what)) {
916 $result .= '&where=' . urlencode($where)
917 . '&what=' . urlencode($what);
921 if (isset($checkall) && ($checkall == '1')) {
922 $result .= _("Unselect All");
924 $result .= _("Select All");
929 /* Return our final result. */
934 * This function computes the "Viewing Messages..." string.
936 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
937 /* Compute the $msg_cnt_str. */
939 if ($start_msg < $end_msg) {
940 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"),
941 $start_msg, $end_msg, $num_msgs);
942 } else if ($start_msg == $end_msg) {
943 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
947 /* Return our result string. */
952 * Generate a paginator link.
954 function get_paginator_link($box, $start_msg, $use, $text) {
957 $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
958 . "&startMessage=$start_msg&mailbox=$box\" "
959 . "TARGET=\"right\">$text</A>";
962 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
963 $source_url = $regs[1];
965 $source_url = $PHP_SELF;
968 $result = '<A HREF="'. $source_url . "?use_mailbox_cache=$use"
969 . "&startMessage=$start_msg&mailbox=$box\" "
970 . "TARGET=\"right\">$text</A>";
976 * This function computes the paginator string.
978 function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
980 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
982 /* Initialize paginator string chunks. */
989 $box = urlencode($box);
991 /* Create simple strings that will be creating the paginator. */
992 $spc = ' '; /* This will be used as a space. */
993 $sep = '|'; /* This will be used as a seperator. */
995 /* Get some paginator preference values. */
996 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON
);
997 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
);
999 /* Make sure that our start message number is not too big. */
1000 $start_msg = min($start_msg, $num_msgs);
1002 /* Decide whether or not we will use the mailbox cache. */
1003 /* Not sure why $use_mailbox_cache is even passed in. */
1010 /* Compute the starting message of the previous and next page group. */
1011 $next_grp = $start_msg +
$show_num;
1012 $prev_grp = $start_msg - $show_num;
1014 /* Compute the basic previous and next strings. */
1015 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
1016 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1017 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1018 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
1019 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1020 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
1021 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
1022 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
1023 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1026 /* Page selector block. Following code computes page links. */
1027 if ($pg_sel && ($num_msgs > $show_num)) {
1028 /* Most importantly, what is the current page!!! */
1029 $cur_pg = intval($start_msg / $show_num) +
1;
1031 /* Compute total # of pages and # of paginator page links. */
1032 $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
1033 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
1035 /* Compute the size of the four quarters of the page links. */
1037 /* If we can, just show all the pages. */
1038 if (($tot_pgs - 1) <= $pg_max) {
1039 $q1_pgs = $cur_pg - 1;
1040 $q2_pgs = $q3_pgs = 0;
1041 $q4_pgs = $tot_pgs - $cur_pg;
1043 /* Otherwise, compute some magic to choose the four quarters. */
1046 * Compute the magic base values. Added together,
1047 * these values will always equal to the $pag_pgs.
1048 * NOTE: These are DEFAULT values and do not take
1049 * the current page into account. That is below.
1051 $q1_pgs = floor($vis_pgs/4);
1052 $q2_pgs = round($vis_pgs/4, 0);
1053 $q3_pgs = ceil($vis_pgs/4);
1054 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
1056 /* Adjust if the first quarter contains the current page. */
1057 if (($cur_pg - $q1_pgs) < 1) {
1058 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) +
$q2_pgs;
1059 $q1_pgs = $cur_pg - 1;
1061 $q3_pgs +
= ceil($extra_pgs / 2);
1062 $q4_pgs +
= floor($extra_pgs / 2);
1064 /* Adjust if the first and second quarters intersect. */
1065 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
1066 $extra_pgs = $q2_pgs;
1067 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1068 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1069 $q3_pgs +
= ceil($extra_pgs / 2);
1070 $q4_pgs +
= floor($extra_pgs / 2);
1072 /* Adjust if the fourth quarter contains the current page. */
1073 } else if (($cur_pg +
$q4_pgs) >= $tot_pgs) {
1074 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) +
$q3_pgs;
1076 $q4_pgs = $tot_pgs - $cur_pg;
1077 $q1_pgs +
= floor($extra_pgs / 2);
1078 $q2_pgs +
= ceil($extra_pgs / 2);
1080 /* Adjust if the third and fourth quarter intersect. */
1081 } else if (($cur_pg +
$q3_pgs +
1) >= ($tot_pgs - $q4_pgs +
1)) {
1082 $extra_pgs = $q3_pgs;
1083 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1084 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1085 $q1_pgs +
= floor($extra_pgs / 2);
1086 $q2_pgs +
= ceil($extra_pgs / 2);
1091 * I am leaving this debug code here, commented out, because
1092 * it is a really nice way to see what the above code is doing.
1093 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
1094 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
1097 /* Print out the page links from the compute page quarters. */
1099 /* Start with the first quarter. */
1100 if (($q1_pgs == 0) && ($cur_pg > 1)) {
1101 $pg_str .= "...$spc";
1103 for ($pg = 1; $pg <= $q1_pgs; ++
$pg) {
1104 $start = (($pg-1) * $show_num) +
1;
1105 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1107 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
1108 $pg_str .= "...$spc";
1112 /* Continue with the second quarter. */
1113 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++
$pg) {
1114 $start = (($pg-1) * $show_num) +
1;
1115 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1118 /* Now print the current page. */
1119 $pg_str .= $cur_pg . $spc;
1121 /* Next comes the third quarter. */
1122 for ($pg = $cur_pg +
1; $pg <= $cur_pg +
$q3_pgs; ++
$pg) {
1123 $start = (($pg-1) * $show_num) +
1;
1124 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1127 /* And last, print the forth quarter page links. */
1128 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
1129 $pg_str .= "...$spc";
1131 if (($tot_pgs - $q4_pgs) > ($cur_pg +
$q3_pgs)) {
1132 $pg_str .= "...$spc";
1134 for ($pg = $tot_pgs - $q4_pgs +
1; $pg <= $tot_pgs; ++
$pg) {
1135 $start = (($pg-1) * $show_num) +
1;
1136 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1139 } else if ($PG_SHOWNUM == 999999) {
1140 $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
1141 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1142 . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc;
1145 /* If necessary, compute the 'show all' string. */
1146 if (($prv_str != '') ||
($nxt_str != '')) {
1147 $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
1148 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1149 . "TARGET=\"right\">" . _("Show All") . '</A>';
1152 /* Last but not least, get the value for the toggle all link. */
1153 $tgl_str = get_selectall_link($start_msg, $sort);
1155 /* Put all the pieces of the paginator string together. */
1157 * Hairy code... But let's leave it like it is since I am not certain
1158 * a different approach would be any easier to read. ;)
1161 $result .= ($prv_str != '' ?
$prv_str . $spc . $sep . $spc : '');
1162 $result .= ($nxt_str != '' ?
$nxt_str . $spc . $sep . $spc : '');
1163 $result .= ($pg_str != '' ?
$pg_str : '');
1164 $result .= ($all_str != '' ?
$sep . $spc . $all_str . $spc : '');
1165 $result .= ($result != '' ?
$sep . $spc . $tgl_str: $tgl_str);
1167 /* If the resulting string is blank, return a non-breaking space. */
1168 if ($result == '') {
1172 /* Return our final magical paginator string. */
1176 function processSubject($subject, $threadlevel = 0) {
1177 global $languages, $squirrelmail_language;
1178 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1180 return _("(no subject)");
1184 /* if this is threaded, subtract two chars per indentlevel */
1185 if($threadlevel > 0 && $threadlevel <= 10)
1186 $trim_at -= (2*$threadlevel);
1188 if (strlen($subject) <= $trim_at)
1191 $ent_strlen = $orig_len = strlen($subject);
1192 $trim_val = $trim_at - 5;
1195 * see if this is entities-encoded string
1196 * If so, Iterate through the whole string, find out
1197 * the real number of characters, and if more
1198 * than 55, substr with an updated trim value.
1200 $step = $ent_loc = 0;
1201 while ( $ent_loc < $trim_val && (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1202 (($ent_loc_end = strpos($subject, ';', $ent_loc+
3)) !== false) ) {
1203 $trim_val +
= ($ent_loc_end-$ent_loc);
1204 $ent_offset = $ent_loc_end+
1;
1208 if (($trim_val > 50) && (strlen($subject) > ($trim_val))&& (strpos($subject,';',$trim_val) < ($trim_val +
6))) {
1209 $i = strpos($subject,';',$trim_val);
1211 $trim_val = strpos($subject,';',$trim_val);
1214 if ($ent_strlen <= $trim_at){
1218 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
1219 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
1220 return $languages[$squirrelmail_language]['XTRA_CODE']('strimwidth', $subject, $trim_val);
1222 return substr($subject, 0, $trim_val) . '...';
1225 function getMbxList($imapConnection) {
1226 global $lastTargetMailbox;
1227 echo ' <small> <tt><select name="targetMailbox">';
1228 echo sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)) );
1229 echo ' </SELECT></TT> ';
1232 function getButton($type, $name, $value) {
1233 return '<INPUT TYPE="'.$type.'" NAME="'.$name.'" VALUE="'.$value . '">';
1236 function getSmallStringCell($string, $align) {
1237 return html_tag('td',
1238 '<small>' . $string . ': </small>',
1244 function getEndMessage($start_msg, $show_num, $num_msgs) {
1245 if ($start_msg +
($show_num - 1) < $num_msgs){
1246 $end_msg = $start_msg +
($show_num - 1);
1248 $end_msg = $num_msgs;
1251 if ($end_msg < $start_msg) {
1252 $start_msg = $start_msg - $show_num;
1253 if ($start_msg < 1) {
1257 return (array($start_msg,$end_msg));
1260 function handleAsSent($mailbox) {
1261 global $handleAsSent_result;
1263 /* First check if this is the sent or draft folder. */
1264 $handleAsSent_result = isSentMailbox($mailbox) ||
isDraftMailbox($mailbox);
1266 /* Then check the result of the handleAsSent hook. */
1267 do_hook('check_handleAsSent_result', $mailbox);
1269 /* And return the result. */
1270 return $handleAsSent_result;