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('../class/html.class');
18 require_once('../functions/imap_utf7_decode_local.php');
20 /* Default value for page_selector_max. */
21 define('PG_SEL_MAX', 10);
23 function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort,
24 $start_msg, $where, $what){
26 $color, $msgs, $msort,
27 $sent_folder, $draft_folder,
28 $default_use_priority,
29 $message_highlight_list,
31 $indent_array, /* indent subject by */
32 $pos, /* Search postion (if any) */
33 $thread_sort_messages, /* thread sorting on/off */
34 $server_sort_order, /* sort value when using server-sorting */
36 $allow_server_sort; /* enable/disable server-side sorting */
37 $color_string = $color[4];
39 if ($GLOBALS['alt_index_colors']) {
40 if (!isset($row_count)) {
45 if (!isset($color[12])) {
46 $color[12] = '#EAEAEA';
48 $color_string = $color[12];
54 * This is done in case you're looking into Sent folders,
55 * because you can have multiple receivers.
57 $senderNames = explode(',', $msg['FROM']);
59 if (sizeof($senderNames)){
60 foreach ($senderNames as $senderNames_part) {
61 if ($senderName != '') {
64 $senderName .= sqimap_find_displayable_name($senderNames_part);
68 if( $mailbox == 'None' ) {
69 $boxes = sqimap_mailbox_list($imapConnection);
70 $mailbox = $boxes[0]['unformatted'];
73 $urlMailbox = urlencode($mailbox);
74 $subject = processSubject($msg['SUBJECT']);
76 echo html_tag( 'tr' ) . "\n";
78 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
79 $flag = "<font color=\"$color[2]\">";
80 $flag_end = '</font>';
85 if (!isset($msg['FLAG_SEEN']) ||
($msg['FLAG_SEEN'] == false)) {
92 if (handleAsSent($mailbox)) {
99 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
100 $fontstr = "<font color=\"$color[9]\">";
101 $fontstr_end = '</font>';
108 * AAAAH! Make my eyes stop bleeding!
111 if (sizeof($message_highlight_list)){
112 foreach ($message_highlight_list as $message_highlight_list_part) {
113 if (trim($message_highlight_list_part['value']) != '') {
114 if ($message_highlight_list_part['match_type'] == 'to_cc') {
115 if (strstr('^^' . strtolower($msg['TO']),
116 strtolower($message_highlight_list_part['value']))
117 ||
strstr('^^'.strtolower($msg['CC']),
118 strtolower($message_highlight_list_part['value']))) {
119 $hlt_color = $message_highlight_list_part['color'];
123 if (strstr('^^' . strtolower($msg[strtoupper($message_highlight_list_part['match_type'])]),
124 strtolower($message_highlight_list_part['value']))) {
125 $hlt_color = $message_highlight_list_part['color'];
132 if (!isset($hlt_color)) {
133 $hlt_color = $color_string;
136 if ($where && $what) {
137 if(!isset($pos) ||
$pos == '') {
140 $search_stuff = "&pos=" . urlencode($pos)
141 . "&where=" . urlencode($where) . '&what=' . urlencode($what);
146 $checked = ($checkall == 1) ?
' checked' : '';
148 if (sizeof($index_order)){
149 foreach ($index_order as $index_order_part) {
150 switch ($index_order_part) {
151 case 1: /* checkbox */
153 "<input type=checkbox name=\"msg[$t]\" value=\"".$msg['ID']."\"$checked>",
159 $italic . $bold . $flag . $fontstr . $senderName .
160 $fontstr_end . $flag_end . $bold_end . $italic_end,
166 $bold . $flag . $fontstr . $msg['DATE_STRING'] .
167 $fontstr_end . $flag_end . $bold_end,
172 case 4: /* subject */
174 if ($thread_sort_messages == 1) {
175 if (isset($indent_array[$msg["ID"]])) {
176 $td_str .= str_repeat(" ",$indent_array[$msg['ID']]);
179 $td_str .= "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id="
181 . "&startMessage=$start_msg&show_more=0\"";
182 do_hook("subject_link");
183 if ($subject != $msg['SUBJECT']) {
184 $title = get_html_translation_table(HTML_SPECIALCHARS
);
185 $title = array_flip($title);
186 $title = strtr($msg['SUBJECT'], $title);
187 $title = str_replace('"', "''", $title);
188 $td_str .= " title=\"$title\"";
190 $td_str .= ">$flag$subject$flag_end</a>$bold_end";
191 echo html_tag( 'td', $td_str, 'left', $hlt_color );
195 $td_str = "<b><small>";
197 if (isset($msg['FLAG_ANSWERED']) && $msg['FLAG_ANSWERED'] == true) {
201 if ($msg['TYPE0'] == 'multipart') {
205 if ($default_use_priority) {
206 if ( ($msg['PRIORITY'] == 1) ||
($msg['PRIORITY'] == 2) ) {
207 $td_str .= "<font color=\"$color[1]\">!</font>";
210 if ($msg['PRIORITY'] == 5) {
211 $td_str .= "<font color=\"$color[8]\">?</font>";
215 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'] == true) {
216 $td_str .= "<font color=\"$color[1]\">D</font>";
222 $td_str .= '</small></b>';
232 $bold . $fontstr . show_readable_size($msg['SIZE']) .
233 $fontstr_end . $bold_end,
244 * This function loops through a group of messages in the mailbox
245 * and shows them to the user.
247 function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
248 $start_msg, $sort, $color, $show_num,
250 global $msgs, $msort,
251 $sent_folder, $draft_folder,
252 $message_highlight_list,
253 $auto_expunge, $thread_sort_messages, $allow_server_sort,
254 $data_dir, $username, $server_sort_order, $php_sort_order;
257 /* If autoexpunge is turned on, then do it now. */
259 $mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox);
260 $issent = handleAsSent($mailbox);
262 /* If autoexpunge is turned on, then do it now. */
263 if ($auto_expunge == true) {
264 $exp_cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, false, '');
265 $mbxresponse['EXISTS'] = $mbxresponse['EXISTS'] - $exp_cnt;
269 if ($mbxresponse['EXISTS']>0) {
271 /* if $start_msg is lower than $num_msgs, we probably deleted all messages
272 * in the last page. We need to re-adjust the start_msg
275 if($start_msg > $num_msgs) {
276 $start_msg -= $show_num;
282 /* This code and the next if() block check for
283 * server-side sorting methods. The $id array is
284 * formatted and $sort is set to 6 to disable
285 * SM internal sorting
287 if ($thread_sort_messages == 1) {
288 $id = get_thread_sort($imapConnection);
290 echo '<b><small><center><font color=red>' .
291 _("Thread sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
292 '</center></small></b>';
293 $thread_sort_messages = 0;
297 if ($start_msg +
($show_num - 1) < $num_msgs) {
298 $end_msg = $start_msg +
($show_num-1);
300 $end_msg = $num_msgs;
302 $id = array_slice($id, ($start_msg-1), ($end_msg));
306 if ($allow_server_sort == TRUE && $thread_sort_messages != 1) {
307 $server_sort_order = $sort;
308 $id = sqimap_get_sort_order($imapConnection, $server_sort_order,$mbxresponse);
310 echo '<b><small><center><font color=red>' .
311 _( "Server-side sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
312 '</center></small></b>';
313 $sort = $server_sort_order;
314 $allow_server_sort = FALSE;
318 if ($start_msg +
($show_num - 1) < $num_msgs) {
319 $end_msg = $start_msg +
($show_num-1);
321 $end_msg = $num_msgs;
323 $id = array_slice($id, ($start_msg-1), ($end_msg));
328 /* If it is sorted... */
329 if ($num_msgs >= 1) {
331 $id = sqimap_get_php_sort_order ($imapConnection, $mbxresponse);
332 } elseif ($thread_sort_messages != 1 && $allow_server_sort != TRUE && $sort == 6) {
333 /* if it's not sorted */
334 $id = sqimap_get_php_sort_order ($imapConnection, $mbxresponse);
335 if ($start_msg +
($show_num - 1) < $num_msgs) {
336 $end_msg = $start_msg +
($show_num - 1);
338 $end_msg = $num_msgs;
340 if ($end_msg < $start_msg) {
341 $start_msg = $start_msg - $show_num;
342 if ($start_msg < 1) {
347 $real_startMessage = $num_msgs - $start_msg +
1;
348 $real_endMessage = $num_msgs - $start_msg - $show_num +
2;
349 if ($real_endMessage <= 0) {
350 $real_endMessage = 1;
352 $id = array_slice(array_reverse($id), ($start_msg-1), ($end_msg));
356 $end = $start_msg +
$show_num - 1;
357 if ($num_msgs < $show_num) {
358 $end_loop = $num_msgs;
359 } else if ($end > $num_msgs) {
360 $end_loop = $num_msgs - $start_msg +
1;
362 $end_loop = $show_num;
369 $messages = fillMessageArray($imapConnection,$id,$issent,$end_loop);
370 if (!isset($messages)) {
377 $msort = calc_msort($msgs, $sort, $num_msgs, $use_cache);
380 /* There's gotta be messages in the array for it to sort them. */
381 } /* if exists > 0 */
382 displayMessageArray($imapConnection, $num_msgs, $start_msg, $msgs,
383 $msort, $mailbox, $sort, $color,$show_num);
385 * TODO: Switch to using $_SESSION[] whenever we ditch the 4.0.x series.
387 session_register('msgs');
390 function calc_msort($msgs, $sort, $num_msgs, $use_cache) {
391 global $thread_sort_messages, $allow_server_sort;
393 if (($num_msgs > 0) && (!$use_cache)) {
402 session_unregister('msgs');
403 if (($sort == 0) ||
($sort == 1)) {
404 $msort = array_cleave ($msgs, 'TIME_STAMP');
405 } elseif (($sort == 2) ||
($sort == 3)) {
406 $msort = array_cleave ($msgs, 'FROM-SORT');
407 } elseif (($sort == 4) ||
($sort == 5)) {
408 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
419 session_register('msort');
420 } elseif ($thread_sort_messages == 1 ||
$allow_server_sort == TRUE) {
422 session_unregister('msgs');
423 session_register('msort');
428 function fillMessageArray($imapConnection,$id,$issent,$count) {
429 $msgs_list = sqimap_get_small_header_list($imapConnection, $id, $issent);
431 if (sizeof($msgs_list)){
432 foreach ($msgs_list as $hdr) {
433 $unique_id[] = $hdr->uid
;
434 $from[] = $hdr->from
;
435 $date[] = $hdr->date
;
436 $subject[] = $hdr->subject
;
438 $priority[] = $hdr->priority
;
440 $size[] = $hdr->size
;
441 $type[] = $hdr->type0
;
442 $flag_deleted[] = $hdr->flag_deleted
;
443 $flag_answered[] = $hdr->flag_answered
;
444 $flag_seen[] = $hdr->flag_seen
;
445 $flag_flagged[] = $hdr->flag_flagged
;
450 while ($j < $count) {
452 if (isset($date[$j])) {
453 $date[$j] = str_replace(' ', ' ', $date[$j]);
454 $tmpdate = explode(' ', trim($date[$j]));
456 $tmpdate = $date = array('', '', '', '', '', '');
458 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
459 $messages[$j]['DATE_STRING'] =
460 getDateString($messages[$j]['TIME_STAMP']);
461 $messages[$j]['ID'] = $unique_id[$j];
462 $messages[$j]['FROM'] = decodeHeader($from[$j]);
463 $messages[$j]['FROM-SORT'] =
464 strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
465 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
466 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
467 $messages[$j]['TO'] = decodeHeader($to[$j]);
468 $messages[$j]['PRIORITY'] = $priority[$j];
469 $messages[$j]['CC'] = $cc[$j];
470 $messages[$j]['SIZE'] = $size[$j];
471 $messages[$j]['TYPE0'] = $type[$j];
472 $messages[$j]['FLAG_DELETED'] = $flag_deleted[$j];
473 $messages[$j]['FLAG_ANSWERED'] = $flag_answered[$j];
474 $messages[$j]['FLAG_SEEN'] = $flag_seen[$j];
475 $messages[$j]['FLAG_FLAGGED'] = $flag_flagged[$j];
479 * fix SUBJECT-SORT to remove Re:
483 * TODO: i18n should be incorporated here. E.g. we catch the ones
484 * we know about, but also define in i18n what the localized
485 * "Re: " is for this or that locale.
487 if (preg_match("/^(vedr|sv|re|aw):\s*(.*)$/si",
488 $messages[$j]['SUBJECT-SORT'], $matches)){
489 $messages[$j]['SUBJECT-SORT'] = $matches[2];
496 /* Generic function to convert the msgs array into an HTML table. */
497 function displayMessageArray($imapConnection, $num_msgs, $start_msg,
498 &$msgs, $msort, $mailbox, $sort, $color,
499 $show_num, $search=false) {
500 global $folder_prefix, $sent_folder,
501 $imapServerAddress, $data_dir, $username, $use_mailbox_cache,
502 $index_order, $real_endMessage, $real_startMessage, $checkall,
503 $indent_array, $thread_sort_messages, $allow_server_sort,
504 $server_sort_order, $PHP_SELF;
506 /* If cache isn't already set, do it now. */
507 if (!session_is_registered('msgs')) {
508 session_register('msgs');
510 if (!session_is_registered('msort')) {
511 session_register('msort');
514 if ($start_msg +
($show_num - 1) < $num_msgs){
515 $end_msg = $start_msg +
($show_num - 1);
517 $end_msg = $num_msgs;
520 if ($end_msg < $start_msg) {
521 $start_msg = $start_msg - $show_num;
522 if ($start_msg < 1) {
527 $urlMailbox = urlencode($mailbox);
529 do_hook('mailbox_index_before');
531 if (preg_match('/.+search\.php.*/',$PHP_SELF,$regs)) {
532 $paginator_str = get_selectall_link($start_msg, $sort);
534 $paginator_str = get_paginator_str($urlMailbox, $start_msg, $end_msg,
535 $num_msgs, $show_num, $sort);
539 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
545 /* get indent level for subject display */
546 if ($thread_sort_messages == 1 ) {
547 $indent_array = get_parent_level($imapConnection);
549 $fstring = "move_messages.php?msg=$msg&mailbox=$urlMailbox"
550 . "&startMessage=$start_msg";
552 /* messages display header */
554 mail_message_listing_beginning($imapConnection, $fstring,
555 $mailbox, $sort, $msg_cnt_str,
556 $paginator_str, $start_msg);
558 $groupNum = $start_msg %
($show_num - 1);
559 $real_startMessage = $start_msg;
561 if ($end_msg - $start_msg < $show_num - 1) {
562 $end_msg = $end_msg - $start_msg +
1;
564 } else if ($start_msg > $show_num) {
565 $end_msg = $show_num;
569 $endVar = $end_msg +
1;
572 * Loop through and display the info for each message.
573 * ($t is used for the checkbox number)
577 /* messages display */
578 echo html_tag( 'table' ,'' , '', '', 'border="0" width="100%" cellpadding="1" cellspacing="0"' );
579 if ($num_msgs == 0) {
580 /* if there's no messages in this folder */
583 "<BR><b>" . _("THIS FOLDER IS EMPTY") . "</b><BR> ",
586 'COLSPAN="' . count($index_order) . '"'
589 } elseif ($start_msg == $end_msg) {
590 /* if there's only one message in the box, handle it differently. */
602 } while (isset ($key) && ($k < $i));
603 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort,
604 $real_startMessage, 0, 0);
613 } while (isset ($key) && ($k < $i));
615 printMessageInfo($imapConnection, $t, $i, $key, $mailbox,
616 $sort, $real_startMessage, 0, 0);
621 } while ($i && $i < $endVar);
626 /* messages display footer */
628 echo html_tag( 'table',
633 html_tag( 'td', $paginator_str ) .
634 html_tag( 'td', $msg_cnt_str, 'right' )
636 , '', $color[4], 'width="100%" cellpadding="1" cellspacing="1"' )
639 , '', $color[9], 'width="100%" cellpadding="1" cellspacing="1"' );
642 /* End of message-list table */
644 do_hook('mailbox_index_after');
649 * Displays the standard message list header. To finish the table,
650 * you need to do a "</table></table>";
652 * $moveURL is the URL to submit the delete/move form to
653 * $mailbox is the current mailbox
654 * $sort is the current sorting method (-1 for no sorting available [searches])
655 * $Message is a message that is centered on top of the list
656 * $More is a second line that is left aligned
659 function mail_message_listing_beginning ($imapConnection, $moveURL,
660 $mailbox = '', $sort = -1,
662 $paginator = ' ',
664 global $color, $index_order, $auto_expunge, $move_to_trash, $base_uri,
665 $checkall, $sent_folder, $draft_folder, $thread_sort_messages,
666 $allow_thread_sort, $allow_server_sort, $server_sort_order,
667 $lastTargetMailbox, $PHP_SELF;
669 $urlMailbox = urlencode($mailbox);
671 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
672 $source_url = $regs[1];
674 $source_url = $PHP_SELF;
679 * This is the beginning of the message list table.
680 * It wraps around all messages
683 echo "<FORM name=\"messageList\" method=post action=\"$moveURL\">\n"
684 . html_tag( 'table' ,'' , '', '', 'border="0" width="100%" cellpadding="1" cellspacing="0"' ) .
689 html_tag( 'td', $paginator, 'left' ) .
690 html_tag( 'td', $msg_cnt_str, 'right' )
692 , '', $color[4], 'border="0" width="100%" cellpadding="2" cellspacing="0"' )
695 . html_tag( 'tr' ) . "\n"
696 . html_tag( 'td' ,'' , 'left', $color[0], '' )
697 . html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="0" cellspacing="0"' )
700 '<small> ' . _("Move Selected To:") . '</small>',
703 'valign="middle" nowrap' ) .
705 '<small>' . _("Transform Selected Messages") . ': </small>',
710 . html_tag( 'tr' ) ."\n"
711 . html_tag( 'td', '', 'left', '', 'valign="middle" nowrap' )
712 . ' <small> <tt><select name="targetMailbox">';
714 $boxes = sqimap_mailbox_list($imapConnection);
715 foreach ($boxes as $boxes_part) {
716 if (!in_array('noselect', $boxes_part['flags'])) {
717 $box = $boxes_part['unformatted'];
718 $box2 = str_replace(' ', ' ', imap_utf7_decode_local($boxes_part['unformatted-disp']));
719 if( $box2 == 'INBOX' ) {
722 if ($lastTargetMailbox == $box) {
723 echo " <OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
726 echo " <OPTION VALUE=\"$box\">$box2</OPTION>\n";
730 echo ' </SELECT></TT> '
731 . '<INPUT TYPE="SUBMIT" NAME="moveButton" VALUE="' . _("Move") . '"> '
732 . '<INPUT TYPE="SUBMIT" NAME="attache" VALUE="' . _("Forward")
733 . "\"> \n" . "</SMALL>\n";
736 . html_tag( 'td', '', 'right', '', 'nowrap' );
738 if (!$auto_expunge) {
739 echo '<INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="' . _("Expunge")
740 . '"> ' . _("mailbox") . ' ';
742 echo '<INPUT TYPE="SUBMIT" NAME="markRead" VALUE="' . _("Read") . '">'
743 . '<INPUT TYPE="SUBMIT" NAME="markUnread" VALUE="' . _("Unread") . '">'
744 . '<INPUT TYPE="SUBMIT" VALUE="' . _("Delete") . '"> '
748 /* draws thread sorting links */
749 if ($allow_thread_sort == TRUE) {
750 if ($thread_sort_messages == 1 ) {
752 $thread_name = _("Unthread View");
754 elseif ($thread_sort_messages == 0) {
756 $thread_name = _("Thread View");
758 echo html_tag( 'tr' ,
760 ' <a href=' . $source_url . '?sort='
761 . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
762 . '&mailbox=' . urlencode($mailbox) . '><small>' . $thread_name
763 . '</a></small> '
772 do_hook('mailbox_form_before');
776 . html_tag( 'td' ,'' , '', $color[0], '' );
777 if ($GLOBALS['alt_index_colors']){
782 echo html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="2" cellspacing="'. $cellspacing .'"' )
783 . html_tag( 'tr' ,'' , 'center', $color[5] );
784 /* if using server sort we highjack the
785 * the $sort var and use $server_sort_order
786 * instead. but here we reset sort for a bit
789 if ($allow_server_sort == TRUE) {
790 $sort = $server_sort_order;
794 if ($allow_thread_sort != TRUE ||
$thread_sort_messages != 1) {
797 /* quick hack to support search.php */
798 if (preg_match('/.+search\.php.*/',$source_url, $regs)) {
802 /* Print the headers. */
803 printHeader($mailbox, $sort, $showsort);
805 /* if using server-sorting,
806 * send sort back to 6
808 if ($allow_server_sort == TRUE) {
815 function printHeader($mailbox,$sort, $showsort=true) {
818 for ($i=1; $i <= count($index_order); $i++
) {
819 switch ($index_order[$i]) {
820 case 1: /* checkbox */
822 echo html_tag( 'td' ,' ' , '', '', 'width="1%"' );
825 if (handleAsSent($mailbox)) {
826 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
827 . '<b>' . _("To") . '</b>';
829 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
830 . '<b>' . _("From") . '</b>';
833 ShowSortButton($sort, $mailbox, 2, 3);
838 echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
839 . '<b>' . _("Date") . '</b>';
841 ShowSortButton($sort, $mailbox, 0, 1);
845 case 4: /* subject */
846 echo html_tag( 'td' ,'' , 'left', '', '' )
847 . '<b>' . _("Subject") . '</b>';
849 ShowSortButton($sort, $mailbox, 4, 5);
854 echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%"' );
862 * This function shows the sort button. Isn't this a good comment?
864 function ShowSortButton($sort, $mailbox, $Up, $Down ) {
866 /* Figure out which image we want to use. */
867 if ($sort != $Up && $sort != $Down) {
868 $img = 'sort_none.png';
870 } elseif ($sort == $Up) {
871 $img = 'up_pointer.png';
874 $img = 'down_pointer.png';
878 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
879 $source_url = $regs[1];
881 $source_url = $PHP_SELF;
884 /* Now that we have everything figured out, show the actual button. */
885 echo ' <a href="' . $source_url .'?newsort=' . $which
886 . '&startMessage=1&mailbox=' . urlencode($mailbox)
887 . '"><IMG SRC="../images/' . $img
888 . '" BORDER=0 WIDTH=12 HEIGHT=10 ALT="sort"></a>';
891 function get_selectall_link($start_msg, $sort) {
892 global $checkall, $what, $where, $mailbox, $javascript_on;
893 global $PHP_SELF, $PG_SHOWNUM;
896 if ($javascript_on) {
898 '<script language="JavaScript" type="text/javascript">'
900 . "function CheckAll() {\n"
901 . " for (var i = 0; i < document.messageList.elements.length; i++) {\n"
902 . " if(document.messageList.elements[i].type == 'checkbox'){\n"
903 . " document.messageList.elements[i].checked = "
904 . " !(document.messageList.elements[i].checked);\n"
909 . '</script><a href="#" onClick="CheckAll();">' . _("Toggle All")
912 if (strpos($PHP_SELF, "?")) {
913 $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($mailbox)
914 . "&startMessage=$start_msg&sort=$sort&checkall=";
916 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
917 . "&startMessage=$start_msg&sort=$sort&checkall=";
919 if (isset($checkall) && $checkall == '1') {
925 if (isset($where) && isset($what)) {
926 $result .= '&where=' . urlencode($where)
927 . '&what=' . urlencode($what);
932 if (isset($checkall) && ($checkall == '1')) {
933 $result .= _("Unselect All");
935 $result .= _("Select All");
941 /* Return our final result. */
946 * This function computes the "Viewing Messages..." string.
948 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
949 /* Compute the $msg_cnt_str. */
951 if ($start_msg < $end_msg) {
952 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"),
953 $start_msg, $end_msg, $num_msgs);
954 } else if ($start_msg == $end_msg) {
955 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
960 /* Return our result string. */
965 * Generate a paginator link.
967 function get_paginator_link($box, $start_msg, $use, $text) {
970 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
971 $source_url = $regs[1];
973 $source_url = $PHP_SELF;
976 $result = '<A HREF="'. $source_url . "?use_mailbox_cache=$use"
977 . "&startMessage=$start_msg&mailbox=$box\" "
978 . "TARGET=\"right\">$text</A>";
983 * This function computes the paginator string.
985 function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
987 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
989 /* Initialize paginator string chunks. */
996 /* Create simple strings that will be creating the paginator. */
997 $spc = ' '; /* This will be used as a space. */
998 $sep = '|'; /* This will be used as a seperator. */
1000 /* Get some paginator preference values. */
1001 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON
);
1002 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
);
1004 /* Make sure that our start message number is not too big. */
1005 $start_msg = min($start_msg, $num_msgs);
1007 /* Decide whether or not we will use the mailbox cache. */
1008 /* Not sure why $use_mailbox_cache is even passed in. */
1015 /* Compute the starting message of the previous and next page group. */
1016 $next_grp = $start_msg +
$show_num;
1017 $prev_grp = $start_msg - $show_num;
1019 /* Compute the basic previous and next strings. */
1020 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
1021 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1022 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1023 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
1024 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1025 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
1026 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
1027 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
1028 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1031 /* Page selector block. Following code computes page links. */
1032 if ($pg_sel && ($num_msgs > $show_num)) {
1033 /* Most importantly, what is the current page!!! */
1034 $cur_pg = intval($start_msg / $show_num) +
1;
1036 /* Compute total # of pages and # of paginator page links. */
1037 $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
1038 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
1040 /* Compute the size of the four quarters of the page links. */
1042 /* If we can, just show all the pages. */
1043 if (($tot_pgs - 1) <= $pg_max) {
1044 $q1_pgs = $cur_pg - 1;
1045 $q2_pgs = $q3_pgs = 0;
1046 $q4_pgs = $tot_pgs - $cur_pg;
1048 /* Otherwise, compute some magic to choose the four quarters. */
1051 * Compute the magic base values. Added together,
1052 * these values will always equal to the $pag_pgs.
1053 * NOTE: These are DEFAULT values and do not take
1054 * the current page into account. That is below.
1056 $q1_pgs = floor($vis_pgs/4);
1057 $q2_pgs = round($vis_pgs/4, 0);
1058 $q3_pgs = ceil($vis_pgs/4);
1059 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
1061 /* Adjust if the first quarter contains the current page. */
1062 if (($cur_pg - $q1_pgs) < 1) {
1063 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) +
$q2_pgs;
1064 $q1_pgs = $cur_pg - 1;
1066 $q3_pgs +
= ceil($extra_pgs / 2);
1067 $q4_pgs +
= floor($extra_pgs / 2);
1069 /* Adjust if the first and second quarters intersect. */
1070 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
1071 $extra_pgs = $q2_pgs;
1072 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1073 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1074 $q3_pgs +
= ceil($extra_pgs / 2);
1075 $q4_pgs +
= floor($extra_pgs / 2);
1077 /* Adjust if the fourth quarter contains the current page. */
1078 } else if (($cur_pg +
$q4_pgs) >= $tot_pgs) {
1079 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) +
$q3_pgs;
1081 $q4_pgs = $tot_pgs - $cur_pg;
1082 $q1_pgs +
= floor($extra_pgs / 2);
1083 $q2_pgs +
= ceil($extra_pgs / 2);
1085 /* Adjust if the third and fourth quarter intersect. */
1086 } else if (($cur_pg +
$q3_pgs +
1) >= ($tot_pgs - $q4_pgs +
1)) {
1087 $extra_pgs = $q3_pgs;
1088 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1089 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1090 $q1_pgs +
= floor($extra_pgs / 2);
1091 $q2_pgs +
= ceil($extra_pgs / 2);
1096 * I am leaving this debug code here, commented out, because
1097 * it is a really nice way to see what the above code is doing.
1098 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
1099 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
1102 /* Print out the page links from the compute page quarters. */
1104 /* Start with the first quarter. */
1105 if (($q1_pgs == 0) && ($cur_pg > 1)) {
1106 $pg_str .= "...$spc";
1108 for ($pg = 1; $pg <= $q1_pgs; ++
$pg) {
1109 $start = (($pg-1) * $show_num) +
1;
1110 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1112 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
1113 $pg_str .= "...$spc";
1117 /* Continue with the second quarter. */
1118 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++
$pg) {
1119 $start = (($pg-1) * $show_num) +
1;
1120 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1123 /* Now print the current page. */
1124 $pg_str .= $cur_pg . $spc;
1126 /* Next comes the third quarter. */
1127 for ($pg = $cur_pg +
1; $pg <= $cur_pg +
$q3_pgs; ++
$pg) {
1128 $start = (($pg-1) * $show_num) +
1;
1129 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1132 /* And last, print the forth quarter page links. */
1133 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
1134 $pg_str .= "...$spc";
1136 if (($tot_pgs - $q4_pgs) > ($cur_pg +
$q3_pgs)) {
1137 $pg_str .= "...$spc";
1139 for ($pg = $tot_pgs - $q4_pgs +
1; $pg <= $tot_pgs; ++
$pg) {
1140 $start = (($pg-1) * $show_num) +
1;
1141 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1144 } else if ($PG_SHOWNUM == 999999) {
1145 $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
1146 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1147 . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc;
1150 /* If necessary, compute the 'show all' string. */
1151 if (($prv_str != '') ||
($nxt_str != '')) {
1152 $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
1153 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1154 . "TARGET=\"right\">" . _("Show All") . '</A>';
1157 /* Last but not least, get the value for the toggle all link. */
1158 $tgl_str = get_selectall_link($start_msg, $sort);
1160 /* Put all the pieces of the paginator string together. */
1162 * Hairy code... But let's leave it like it is since I am not certain
1163 * a different approach would be any easier to read. ;)
1166 $result .= ($prv_str != '' ?
$prv_str . $spc . $sep . $spc : '');
1167 $result .= ($nxt_str != '' ?
$nxt_str . $spc . $sep . $spc : '');
1168 $result .= ($pg_str != '' ?
$pg_str : '');
1169 $result .= ($all_str != '' ?
$sep . $spc . $all_str . $spc : '');
1170 $result .= ($result != '' ?
$sep . $spc . $tgl_str: $tgl_str);
1172 /* If the resulting string is blank, return a non-breaking space. */
1173 if ($result == '') {
1177 /* Return our final magical paginator string. */
1181 function processSubject($subject) {
1182 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1184 return _("(no subject)");
1186 if (strlen($subject) <= 55)
1189 $ent_strlen=strlen($subject);
1193 * see if this is entities-encoded string
1194 * If so, Iterate through the whole string, find out
1195 * the real number of characters, and if more
1196 * than 55, substr with an updated trim value.
1198 while ( (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1199 (($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false) ) {
1200 $trim_val +
= ($ent_loc_end-$ent_loc)+
1;
1201 $ent_strlen -= $ent_loc_end-$ent_loc;
1202 $ent_offset = $ent_loc_end+
1;
1205 if ($ent_strlen <= 55){
1209 return substr($subject, 0, $trim_val) . '...';
1212 function handleAsSent($mailbox) {
1213 global $sent_folder, $draft_folder, $handleAsSent_result;
1215 /* First check if this is the sent or draft folder. */
1216 $handleAsSent_result = (($mailbox == $sent_folder)
1217 ||
($mailbox == $draft_folder));
1219 /* Then check the result of the handleAsSent hook. */
1220 do_hook('check_handleAsSent_result', $mailbox);
1222 /* And return the result. */
1223 return ($handleAsSent_result);