6 * Copyright (c) 1999-2002 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('../functions/strings.php');
16 require_once('../functions/html.php');
17 require_once('../functions/imap_utf7_decode_local.php');
19 /* Default value for page_selector_max. */
20 define('PG_SEL_MAX', 10);
22 function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort,
23 $start_msg, $where, $what){
25 $color, $msgs, $msort,
26 $sent_folder, $draft_folder,
27 $default_use_priority,
28 $message_highlight_list,
30 $indent_array, /* indent subject by */
31 $pos, /* Search postion (if any) */
32 $thread_sort_messages, /* thread sorting on/off */
33 $server_sort_order, /* sort value when using server-sorting */
35 $allow_server_sort; /* enable/disable server-side sorting */
36 $color_string = $color[4];
38 if ($GLOBALS['alt_index_colors']) {
39 if (!isset($row_count)) {
44 if (!isset($color[12])) {
45 $color[12] = '#EAEAEA';
47 $color_string = $color[12];
53 * This is done in case you're looking into Sent folders,
54 * because you can have multiple receivers.
56 $senderNames = explode(',', $msg['FROM']);
58 if (sizeof($senderNames)){
59 foreach ($senderNames as $senderNames_part) {
60 if ($senderName != '') {
63 $senderName .= sqimap_find_displayable_name($senderNames_part);
67 if( $mailbox == 'None' ) {
68 $boxes = sqimap_mailbox_list($imapConnection);
69 $mailbox = $boxes[0]['unformatted'];
72 $urlMailbox = urlencode($mailbox);
73 $subject = processSubject($msg['SUBJECT']);
74 echo html_tag( 'tr' ) . "\n";
76 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
77 $flag = "<font color=\"$color[2]\">";
78 $flag_end = '</font>';
83 if (!isset($msg['FLAG_SEEN']) ||
($msg['FLAG_SEEN'] == false)) {
90 if (handleAsSent($mailbox)) {
97 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
98 $fontstr = "<font color=\"$color[9]\">";
99 $fontstr_end = '</font>';
106 * AAAAH! Make my eyes stop bleeding!
109 if (sizeof($message_highlight_list)){
110 foreach ($message_highlight_list as $message_highlight_list_part) {
111 if (trim($message_highlight_list_part['value']) != '') {
112 if ($message_highlight_list_part['match_type'] == 'to_cc') {
113 if (strstr('^^' . strtolower($msg['TO']),
114 strtolower($message_highlight_list_part['value']))
115 ||
strstr('^^'.strtolower($msg['CC']),
116 strtolower($message_highlight_list_part['value']))) {
117 $hlt_color = $message_highlight_list_part['color'];
121 if (strstr('^^' . strtolower($msg[strtoupper($message_highlight_list_part['match_type'])]),
122 strtolower($message_highlight_list_part['value']))) {
123 $hlt_color = $message_highlight_list_part['color'];
130 if (!isset($hlt_color)) {
131 $hlt_color = $color_string;
134 if ($where && $what) {
135 if(!isset($pos) ||
$pos == '') {
138 $search_stuff = "&pos=" . urlencode($pos)
139 . "&where=" . urlencode($where) . '&what=' . urlencode($what);
144 $checked = ($checkall == 1) ?
' checked' : '';
146 if (sizeof($index_order)){
147 foreach ($index_order as $index_order_part) {
148 switch ($index_order_part) {
149 case 1: /* checkbox */
151 "<input type=checkbox name=\"msg[$t]\" value=\"".$msg['ID']."\"$checked>",
157 $italic . $bold . $flag . $fontstr . $senderName .
158 $fontstr_end . $flag_end . $bold_end . $italic_end,
164 $bold . $flag . $fontstr . $msg['DATE_STRING'] .
165 $fontstr_end . $flag_end . $bold_end,
170 case 4: /* subject */
172 if ($thread_sort_messages == 1) {
173 if (isset($indent_array[$msg["ID"]])) {
174 $td_str .= str_repeat(" ",$indent_array[$msg['ID']]);
177 $td_str .= "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id="
179 . "&startMessage=$start_msg&show_more=0\"";
180 do_hook("subject_link");
181 if ($subject != $msg['SUBJECT']) {
182 $title = get_html_translation_table(HTML_SPECIALCHARS
);
183 $title = array_flip($title);
184 $title = strtr($msg['SUBJECT'], $title);
185 $title = str_replace('"', "''", $title);
186 $td_str .= " title=\"$title\"";
188 $td_str .= ">$flag$subject$flag_end</a>$bold_end";
189 echo html_tag( 'td', $td_str, 'left', $hlt_color );
193 $td_str = "<b><small>";
195 if (isset($msg['FLAG_ANSWERED']) && $msg['FLAG_ANSWERED'] == true) {
199 if ($msg['TYPE0'] == 'multipart') {
203 if ($default_use_priority) {
204 if ( ($msg['PRIORITY'] == 1) ||
($msg['PRIORITY'] == 2) ) {
205 $td_str .= "<font color=\"$color[1]\">!</font>";
208 if ($msg['PRIORITY'] == 5) {
209 $td_str .= "<font color=\"$color[8]\">?</font>";
213 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'] == true) {
214 $td_str .= "<font color=\"$color[1]\">D</font>";
220 $td_str .= '</small></b>';
230 $bold . $fontstr . show_readable_size($msg['SIZE']) .
231 $fontstr_end . $bold_end,
242 * This function loops through a group of messages in the mailbox
243 * and shows them to the user.
245 function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
246 $start_msg, $sort, $color, $show_num,
248 global $msgs, $msort,
249 $sent_folder, $draft_folder,
250 $message_highlight_list,
251 $auto_expunge, $thread_sort_messages, $allow_server_sort,
252 $data_dir, $username, $server_sort_order, $php_sort_order;
255 /* If autoexpunge is turned on, then do it now. */
257 $mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox);
258 $issent = handleAsSent($mailbox);
260 /* If autoexpunge is turned on, then do it now. */
261 if ($auto_expunge == true) {
262 $exp_cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, false, '');
263 $mbxresponse['EXISTS'] = $mbxresponse['EXISTS'] - $exp_cnt;
267 if ($mbxresponse['EXISTS']>0) {
269 /* if $start_msg is lower than $num_msgs, we probably deleted all messages
270 * in the last page. We need to re-adjust the start_msg
273 if($start_msg > $num_msgs) {
274 $start_msg -= $show_num;
280 /* This code and the next if() block check for
281 * server-side sorting methods. The $id array is
282 * formatted and $sort is set to 6 to disable
283 * SM internal sorting
285 if ($thread_sort_messages == 1) {
286 $id = get_thread_sort($imapConnection);
288 echo '<b><small><center><font color=red>' .
289 _("Thread sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
290 '</center></small></b>';
291 $thread_sort_messages = 0;
295 if ($start_msg +
($show_num - 1) < $num_msgs) {
296 $end_msg = $start_msg +
($show_num-1);
298 $end_msg = $num_msgs;
300 $id = array_slice($id, ($start_msg-1), ($end_msg));
304 if ($allow_server_sort == TRUE && $thread_sort_messages != 1) {
305 $server_sort_order = $sort;
306 $id = sqimap_get_sort_order($imapConnection, $server_sort_order,$mbxresponse);
308 echo '<b><small><center><font color=red>' .
309 _( "Server-side sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
310 '</center></small></b>';
311 $sort = $server_sort_order;
312 $allow_server_sort = FALSE;
316 if ($start_msg +
($show_num - 1) < $num_msgs) {
317 $end_msg = $start_msg +
($show_num-1);
319 $end_msg = $num_msgs;
321 $id = array_slice($id, ($start_msg-1), ($end_msg));
326 /* If it is sorted... */
327 if ($num_msgs >= 1) {
329 $id = sqimap_get_php_sort_order ($imapConnection, $mbxresponse);
330 } elseif ($thread_sort_messages != 1 && $allow_server_sort != TRUE && $sort == 6) {
331 /* if it's not sorted */
332 $id = sqimap_get_php_sort_order ($imapConnection, $mbxresponse);
333 if ($start_msg +
($show_num - 1) < $num_msgs) {
334 $end_msg = $start_msg +
($show_num - 1);
336 $end_msg = $num_msgs;
338 if ($end_msg < $start_msg) {
339 $start_msg = $start_msg - $show_num;
340 if ($start_msg < 1) {
345 $real_startMessage = $num_msgs - $start_msg +
1;
346 $real_endMessage = $num_msgs - $start_msg - $show_num +
2;
347 if ($real_endMessage <= 0) {
348 $real_endMessage = 1;
350 $id = array_slice(array_reverse($id), ($start_msg-1), ($end_msg));
354 $end = $start_msg +
$show_num - 1;
355 if ($num_msgs < $show_num) {
356 $end_loop = $num_msgs;
357 } else if ($end > $num_msgs) {
358 $end_loop = $num_msgs - $start_msg +
1;
360 $end_loop = $show_num;
367 $messages = fillMessageArray($imapConnection,$id,$issent,$end_loop);
368 if (!isset($messages)) {
375 $msort = calc_msort($msgs, $sort, $num_msgs, $use_cache);
378 /* There's gotta be messages in the array for it to sort them. */
379 } /* if exists > 0 */
380 displayMessageArray($imapConnection, $num_msgs, $start_msg, $msgs,
381 $msort, $mailbox, $sort, $color,$show_num);
383 * TODO: Switch to using $_SESSION[] whenever we ditch the 4.0.x series.
385 session_register('msgs');
388 function calc_msort($msgs, $sort, $num_msgs, $use_cache) {
389 global $thread_sort_messages, $allow_server_sort;
391 if (($num_msgs > 0) && (!$use_cache)) {
400 session_unregister('msgs');
401 if (($sort == 0) ||
($sort == 1)) {
402 $msort = array_cleave ($msgs, 'TIME_STAMP');
403 } elseif (($sort == 2) ||
($sort == 3)) {
404 $msort = array_cleave ($msgs, 'FROM-SORT');
405 } elseif (($sort == 4) ||
($sort == 5)) {
406 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
417 session_register('msort');
418 } elseif ($thread_sort_messages == 1 ||
$allow_server_sort == TRUE) {
420 session_unregister('msgs');
421 session_register('msort');
426 function fillMessageArray($imapConnection,$id,$issent,$count) {
427 $msgs_list = sqimap_get_small_header_list($imapConnection, $id, $issent);
428 if (sizeof($msgs_list)){
429 foreach ($msgs_list as $hdr) {
430 $unique_id[] = $hdr->uid
;
431 $from[] = $hdr->from
;
432 $date[] = $hdr->date
;
433 $subject[] = $hdr->subject
;
435 $priority[] = $hdr->priority
;
437 $size[] = $hdr->size
;
438 $type[] = $hdr->type0
;
439 $flag_deleted[] = $hdr->flag_deleted
;
440 $flag_answered[] = $hdr->flag_answered
;
441 $flag_seen[] = $hdr->flag_seen
;
442 $flag_flagged[] = $hdr->flag_flagged
;
447 while ($j < $count) {
449 if (isset($date[$j])) {
450 $date[$j] = str_replace(' ', ' ', $date[$j]);
451 $tmpdate = explode(' ', trim($date[$j]));
453 $tmpdate = $date = array('', '', '', '', '', '');
456 $messages[$i]['TIME_STAMP'] = getTimeStamp($tmpdate);
457 $messages[$i]['DATE_STRING'] =
458 getDateString($messages[$i]['TIME_STAMP']);
459 $messages[$i]['ID'] = $i;
460 $messages[$i]['FROM'] = decodeHeader($from[$j]);
461 $messages[$i]['FROM-SORT'] =
462 strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
463 $messages[$i]['SUBJECT'] = decodeHeader($subject[$j]);
464 $messages[$i]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
465 $messages[$i]['TO'] = decodeHeader($to[$j]);
466 $messages[$i]['PRIORITY'] = $priority[$j];
467 $messages[$i]['CC'] = $cc[$j];
468 $messages[$i]['SIZE'] = $size[$j];
469 $messages[$i]['TYPE0'] = $type[$j];
470 $messages[$i]['FLAG_DELETED'] = $flag_deleted[$j];
471 $messages[$i]['FLAG_ANSWERED'] = $flag_answered[$j];
472 $messages[$i]['FLAG_SEEN'] = $flag_seen[$j];
473 $messages[$i]['FLAG_FLAGGED'] = $flag_flagged[$j];
477 * fix SUBJECT-SORT to remove Re:
481 * TODO: i18n should be incorporated here. E.g. we catch the ones
482 * we know about, but also define in i18n what the localized
483 * "Re: " is for this or that locale.
485 if (preg_match("/^(vedr|sv|re|aw):\s*(.*)$/si",
486 $messages[$i]['SUBJECT-SORT'], $matches)){
487 $messages[$i]['SUBJECT-SORT'] = $matches[2];
494 /* Generic function to convert the msgs array into an HTML table. */
495 function displayMessageArray($imapConnection, $num_msgs, $start_msg,
496 &$msgs, $msort, $mailbox, $sort, $color,
497 $show_num, $search=false) {
498 global $folder_prefix, $sent_folder,
499 $imapServerAddress, $data_dir, $username, $use_mailbox_cache,
500 $index_order, $real_endMessage, $real_startMessage, $checkall,
501 $indent_array, $thread_sort_messages, $allow_server_sort, $server_sort_order;
503 /* If cache isn't already set, do it now. */
504 if (!session_is_registered('msgs')) {
505 session_register('msgs');
507 if (!session_is_registered('msort')) {
508 session_register('msort');
511 if ($start_msg +
($show_num - 1) < $num_msgs){
512 $end_msg = $start_msg +
($show_num - 1);
514 $end_msg = $num_msgs;
517 if ($end_msg < $start_msg) {
518 $start_msg = $start_msg - $show_num;
519 if ($start_msg < 1) {
524 $urlMailbox = urlencode($mailbox);
526 do_hook('mailbox_index_before');
528 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
529 $paginator_str = get_paginator_str($urlMailbox, $start_msg, $end_msg,
530 $num_msgs, $show_num, $sort);
536 /* get indent level for subject display */
537 if ($thread_sort_messages == 1 ) {
538 $indent_array = get_parent_level($imapConnection);
540 $fstring = "move_messages.php?msg=$msg&mailbox=$urlMailbox"
541 . "&startMessage=$start_msg";
542 mail_message_listing_beginning($imapConnection, $fstring,
543 $mailbox, $sort, $msg_cnt_str,
544 $paginator_str, $start_msg);
546 $groupNum = $start_msg %
($show_num - 1);
547 $real_startMessage = $start_msg;
549 if ($end_msg - $start_msg < $show_num - 1) {
550 $end_msg = $end_msg - $start_msg +
1;
552 } else if ($start_msg > $show_num) {
553 $end_msg = $show_num;
557 $endVar = $end_msg +
1;
560 * Loop through and display the info for each message.
561 * ($t is used for the checkbox number)
564 if ($num_msgs == 0) {
565 /* if there's no messages in this folder */
568 "<BR><b>" . _("THIS FOLDER IS EMPTY") . "</b><BR> ",
571 'COLSPAN="' . count($index_order) . '"'
574 } elseif ($start_msg == $end_msg) {
575 /* if there's only one message in the box, handle it differently. */
587 } while (isset ($key) && ($k < $i));
588 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort,
589 $real_startMessage, 0, 0);
598 } while (isset ($key) && ($k < $i));
600 printMessageInfo($imapConnection, $t, $i, $key, $mailbox,
601 $sort, $real_startMessage, 0, 0);
606 } while ($i && $i < $endVar);
611 echo html_tag( 'table',
616 html_tag( 'td', $paginator_str ) .
617 html_tag( 'td', $msg_cnt_str, 'right' )
619 , '', $color[4], 'width="100%" cellpadding="1" cellspacing="1"' )
622 , '', $color[9], 'width="100%" cellpadding="1" cellspacing="1"' );
625 /* End of message-list table */
627 do_hook('mailbox_index_after');
628 echo "</TABLE></FORM>\n";
632 * Displays the standard message list header. To finish the table,
633 * you need to do a "</table></table>";
635 * $moveURL is the URL to submit the delete/move form to
636 * $mailbox is the current mailbox
637 * $sort is the current sorting method (-1 for no sorting available [searches])
638 * $Message is a message that is centered on top of the list
639 * $More is a second line that is left aligned
642 function mail_message_listing_beginning ($imapConnection, $moveURL,
643 $mailbox = '', $sort = -1,
645 $paginator = ' ',
647 global $color, $index_order, $auto_expunge, $move_to_trash, $base_uri,
648 $checkall, $sent_folder, $draft_folder, $thread_sort_messages,
649 $allow_thread_sort, $allow_server_sort, $server_sort_order,
650 $lastTargetMailbox, $PHP_SELF;
652 $urlMailbox = urlencode($mailbox);
654 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
655 $source_url = $regs[1];
657 $source_url = $PHP_SELF;
662 * This is the beginning of the message list table.
663 * It wraps around all messages
666 echo "<FORM name=\"messageList\" method=post action=\"$moveURL\">\n"
667 . html_tag( 'table' ,'' , '', '', 'border="0" width="100%" cellpadding="1" cellspacing="0"' ) .
672 html_tag( 'td', $paginator, 'left' ) .
673 html_tag( 'td', $msg_cnt_str, 'right' )
675 , '', $color[4], 'border="0" width="100%" cellpadding="2" cellspacing="0"' )
678 . html_tag( 'tr' ) . "\n"
679 . html_tag( 'td' ,'' , 'left', $color[0], '' )
680 . html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="0" cellspacing="0"' )
683 '<small> ' . _("Move Selected To:") . '</small>',
686 'valign="middle" nowrap' ) .
688 '<small>' . _("Transform Selected Messages") . ': </small>',
693 . html_tag( 'tr' ) ."\n"
694 . html_tag( 'td', '', 'left', '', 'valign="middle" nowrap' )
695 . ' <small> <tt><select name="targetMailbox">';
697 $boxes = sqimap_mailbox_list($imapConnection);
698 foreach ($boxes as $boxes_part) {
699 if (!in_array('noselect', $boxes_part['flags'])) {
700 $box = $boxes_part['unformatted'];
701 $box2 = str_replace(' ', ' ', imap_utf7_decode_local($boxes_part['unformatted-disp']));
702 if( $box2 == 'INBOX' ) {
705 if ($lastTargetMailbox == $box) {
706 echo " <OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
709 echo " <OPTION VALUE=\"$box\">$box2</OPTION>\n";
713 echo ' </SELECT></TT> '
714 . '<INPUT TYPE="SUBMIT" NAME="moveButton" VALUE="' . _("Move") . '"> '
715 . '<INPUT TYPE="SUBMIT" NAME="attache" VALUE="' . _("Forward")
716 . "\"> \n" . "</SMALL>\n";
719 . html_tag( 'td', '', 'right', '', 'nowrap' );
721 if (!$auto_expunge) {
722 echo '<INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="' . _("Expunge")
723 . '"> ' . _("mailbox") . ' ';
725 echo '<INPUT TYPE="SUBMIT" NAME="markRead" VALUE="' . _("Read") . '">'
726 . '<INPUT TYPE="SUBMIT" NAME="markUnread" VALUE="' . _("Unread") . '">'
727 . '<INPUT TYPE="SUBMIT" VALUE="' . _("Delete") . '"> '
731 /* draws thread sorting links */
732 if ($allow_thread_sort == TRUE) {
733 if ($thread_sort_messages == 1 ) {
735 $thread_name = _("Unthread View");
737 elseif ($thread_sort_messages == 0) {
739 $thread_name = _("Thread View");
741 echo html_tag( 'tr' ,
743 ' <a href=' . $source_url . '?sort='
744 . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
745 . '&mailbox=' . urlencode($mailbox) . '><small>' . $thread_name
746 . '</a></small> '
754 do_hook('mailbox_form_before');
757 . html_tag( 'td' ,'' , '', $color[0], '' );
758 if ($GLOBALS['alt_index_colors']){
763 echo html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="2" cellspacing="'. $cellspacing .'"' )
764 . html_tag( 'tr' ,'' , 'center', $color[5] );
765 /* if using server sort we highjack the
766 * the $sort var and use $server_sort_order
767 * instead. but here we reset sort for a bit
770 if ($allow_server_sort == TRUE) {
771 $sort = $server_sort_order;
773 /* Print the headers. */
774 for ($i=1; $i <= count($index_order); $i++
) {
775 switch ($index_order[$i]) {
776 case 1: /* checkbox */
778 echo html_tag( 'td' ,' ' , '', '', 'width="1%"' );
781 if (handleAsSent($mailbox)) {
782 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
783 . '<b>' . _("To") . '</b>';
785 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
786 . '<b>' . _("From") . '</b>';
788 if ($allow_thread_sort != TRUE ||
$thread_sort_messages != 1) {
789 ShowSortButton($sort, $mailbox, 2, 3);
794 echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
795 . '<b>' . _("Date") . '</b>';
796 if ($allow_thread_sort != TRUE ||
$thread_sort_messages != 1) {
797 ShowSortButton($sort, $mailbox, 0, 1);
801 case 4: /* subject */
802 echo html_tag( 'td' ,'' , 'left', '', '' )
803 . '<b>' . _("Subject") . '</b>';
804 if ($allow_thread_sort != TRUE ||
$thread_sort_messages != 1) {
805 ShowSortButton($sort, $mailbox, 4, 5);
810 echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%"' );
814 /* if using server-sorting,
815 * send sort back to 6
817 if ($allow_server_sort == TRUE) {
825 * This function shows the sort button. Isn't this a good comment?
827 function ShowSortButton($sort, $mailbox, $Up, $Down ) {
829 /* Figure out which image we want to use. */
830 if ($sort != $Up && $sort != $Down) {
831 $img = 'sort_none.png';
833 } elseif ($sort == $Up) {
834 $img = 'up_pointer.png';
837 $img = 'down_pointer.png';
841 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
842 $source_url = $regs[1];
844 $source_url = $PHP_SELF;
847 /* Now that we have everything figured out, show the actual button. */
848 echo ' <a href="' . $source_url .'?newsort=' . $which
849 . '&startMessage=1&mailbox=' . urlencode($mailbox)
850 . '"><IMG SRC="../images/' . $img
851 . '" BORDER=0 WIDTH=12 HEIGHT=10 ALT="sort"></a>';
854 function get_selectall_link($start_msg, $sort) {
855 global $checkall, $what, $where, $mailbox, $javascript_on;
856 global $PHP_SELF, $PG_SHOWNUM;
859 if ($javascript_on) {
861 '<script language="JavaScript" type="text/javascript">'
863 . "function CheckAll() {\n"
864 . " for (var i = 0; i < document.messageList.elements.length; i++) {\n"
865 . " if(document.messageList.elements[i].type == 'checkbox'){\n"
866 . " document.messageList.elements[i].checked = "
867 . " !(document.messageList.elements[i].checked);\n"
872 . '</script><a href="#" onClick="CheckAll();">' . _("Toggle All")
875 if (strpos($PHP_SELF, "?")) {
876 $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($mailbox)
877 . "&startMessage=$start_msg&sort=$sort&checkall=";
879 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
880 . "&startMessage=$start_msg&sort=$sort&checkall=";
882 if (isset($checkall) && $checkall == '1') {
888 if (isset($where) && isset($what)) {
889 $result .= '&where=' . urlencode($where)
890 . '&what=' . urlencode($what);
895 if (isset($checkall) && ($checkall == '1')) {
896 $result .= _("Unselect All");
898 $result .= _("Select All");
904 /* Return our final result. */
909 * This function computes the "Viewing Messages..." string.
911 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
912 /* Compute the $msg_cnt_str. */
914 if ($start_msg < $end_msg) {
915 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"),
916 $start_msg, $end_msg, $num_msgs);
917 } else if ($start_msg == $end_msg) {
918 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
923 /* Return our result string. */
928 * Generate a paginator link.
930 function get_paginator_link($box, $start_msg, $use, $text) {
933 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
934 $source_url = $regs[1];
936 $source_url = $PHP_SELF;
939 $result = '<A HREF="'. $source_url . "?use_mailbox_cache=$use"
940 . "&startMessage=$start_msg&mailbox=$box\" "
941 . "TARGET=\"right\">$text</A>";
946 * This function computes the paginator string.
948 function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
950 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
952 /* Initialize paginator string chunks. */
959 /* Create simple strings that will be creating the paginator. */
960 $spc = ' '; /* This will be used as a space. */
961 $sep = '|'; /* This will be used as a seperator. */
963 /* Get some paginator preference values. */
964 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON
);
965 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
);
967 /* Make sure that our start message number is not too big. */
968 $start_msg = min($start_msg, $num_msgs);
970 /* Decide whether or not we will use the mailbox cache. */
971 /* Not sure why $use_mailbox_cache is even passed in. */
978 /* Compute the starting message of the previous and next page group. */
979 $next_grp = $start_msg +
$show_num;
980 $prev_grp = $start_msg - $show_num;
982 /* Compute the basic previous and next strings. */
983 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
984 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
985 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
986 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
987 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
988 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
989 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
990 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
991 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
994 /* Page selector block. Following code computes page links. */
995 if ($pg_sel && ($num_msgs > $show_num)) {
996 /* Most importantly, what is the current page!!! */
997 $cur_pg = intval($start_msg / $show_num) +
1;
999 /* Compute total # of pages and # of paginator page links. */
1000 $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
1001 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
1003 /* Compute the size of the four quarters of the page links. */
1005 /* If we can, just show all the pages. */
1006 if (($tot_pgs - 1) <= $pg_max) {
1007 $q1_pgs = $cur_pg - 1;
1008 $q2_pgs = $q3_pgs = 0;
1009 $q4_pgs = $tot_pgs - $cur_pg;
1011 /* Otherwise, compute some magic to choose the four quarters. */
1014 * Compute the magic base values. Added together,
1015 * these values will always equal to the $pag_pgs.
1016 * NOTE: These are DEFAULT values and do not take
1017 * the current page into account. That is below.
1019 $q1_pgs = floor($vis_pgs/4);
1020 $q2_pgs = round($vis_pgs/4, 0);
1021 $q3_pgs = ceil($vis_pgs/4);
1022 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
1024 /* Adjust if the first quarter contains the current page. */
1025 if (($cur_pg - $q1_pgs) < 1) {
1026 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) +
$q2_pgs;
1027 $q1_pgs = $cur_pg - 1;
1029 $q3_pgs +
= ceil($extra_pgs / 2);
1030 $q4_pgs +
= floor($extra_pgs / 2);
1032 /* Adjust if the first and second quarters intersect. */
1033 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
1034 $extra_pgs = $q2_pgs;
1035 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1036 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1037 $q3_pgs +
= ceil($extra_pgs / 2);
1038 $q4_pgs +
= floor($extra_pgs / 2);
1040 /* Adjust if the fourth quarter contains the current page. */
1041 } else if (($cur_pg +
$q4_pgs) >= $tot_pgs) {
1042 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) +
$q3_pgs;
1044 $q4_pgs = $tot_pgs - $cur_pg;
1045 $q1_pgs +
= floor($extra_pgs / 2);
1046 $q2_pgs +
= ceil($extra_pgs / 2);
1048 /* Adjust if the third and fourth quarter intersect. */
1049 } else if (($cur_pg +
$q3_pgs +
1) >= ($tot_pgs - $q4_pgs +
1)) {
1050 $extra_pgs = $q3_pgs;
1051 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1052 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1053 $q1_pgs +
= floor($extra_pgs / 2);
1054 $q2_pgs +
= ceil($extra_pgs / 2);
1059 * I am leaving this debug code here, commented out, because
1060 * it is a really nice way to see what the above code is doing.
1061 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
1062 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
1065 /* Print out the page links from the compute page quarters. */
1067 /* Start with the first quarter. */
1068 if (($q1_pgs == 0) && ($cur_pg > 1)) {
1069 $pg_str .= "...$spc";
1071 for ($pg = 1; $pg <= $q1_pgs; ++
$pg) {
1072 $start = (($pg-1) * $show_num) +
1;
1073 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1075 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
1076 $pg_str .= "...$spc";
1080 /* Continue with the second quarter. */
1081 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++
$pg) {
1082 $start = (($pg-1) * $show_num) +
1;
1083 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1086 /* Now print the current page. */
1087 $pg_str .= $cur_pg . $spc;
1089 /* Next comes the third quarter. */
1090 for ($pg = $cur_pg +
1; $pg <= $cur_pg +
$q3_pgs; ++
$pg) {
1091 $start = (($pg-1) * $show_num) +
1;
1092 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1095 /* And last, print the forth quarter page links. */
1096 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
1097 $pg_str .= "...$spc";
1099 if (($tot_pgs - $q4_pgs) > ($cur_pg +
$q3_pgs)) {
1100 $pg_str .= "...$spc";
1102 for ($pg = $tot_pgs - $q4_pgs +
1; $pg <= $tot_pgs; ++
$pg) {
1103 $start = (($pg-1) * $show_num) +
1;
1104 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1107 } else if ($PG_SHOWNUM == 999999) {
1108 $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
1109 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1110 . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc;
1113 /* If necessary, compute the 'show all' string. */
1114 if (($prv_str != '') ||
($nxt_str != '')) {
1115 $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
1116 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1117 . "TARGET=\"right\">" . _("Show All") . '</A>';
1120 /* Last but not least, get the value for the toggle all link. */
1121 $tgl_str = get_selectall_link($start_msg, $sort);
1123 /* Put all the pieces of the paginator string together. */
1125 * Hairy code... But let's leave it like it is since I am not certain
1126 * a different approach would be any easier to read. ;)
1129 $result .= ($prv_str != '' ?
$prv_str . $spc . $sep . $spc : '');
1130 $result .= ($nxt_str != '' ?
$nxt_str . $spc . $sep . $spc : '');
1131 $result .= ($pg_str != '' ?
$pg_str : '');
1132 $result .= ($all_str != '' ?
$sep . $spc . $all_str . $spc : '');
1133 $result .= ($result != '' ?
$sep . $spc . $tgl_str: $tgl_str);
1135 /* If the resulting string is blank, return a non-breaking space. */
1136 if ($result == '') {
1140 /* Return our final magical paginator string. */
1144 function processSubject($subject) {
1145 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1147 return _("(no subject)");
1149 if (strlen($subject) <= 55)
1152 $ent_strlen=strlen($subject);
1156 * see if this is entities-encoded string
1157 * If so, Iterate through the whole string, find out
1158 * the real number of characters, and if more
1159 * than 55, substr with an updated trim value.
1161 while ( (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1162 (($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false) ) {
1163 $trim_val +
= ($ent_loc_end-$ent_loc)+
1;
1164 $ent_strlen -= $ent_loc_end-$ent_loc;
1165 $ent_offset = $ent_loc_end+
1;
1168 if ($ent_strlen <= 55){
1172 return substr($subject, 0, $trim_val) . '...';
1175 function handleAsSent($mailbox) {
1176 global $sent_folder, $draft_folder, $handleAsSent_result;
1178 /* First check if this is the sent or draft folder. */
1179 $handleAsSent_result = (($mailbox == $sent_folder)
1180 ||
($mailbox == $draft_folder));
1182 /* Then check the result of the handleAsSent hook. */
1183 do_hook('check_handleAsSent_result', $mailbox);
1185 /* And return the result. */
1186 return ($handleAsSent_result);