0f7e74f736e0a5fa322eed879d4b30784d5da685
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/imap_utf7_decode_local.php');
17 require_once('../functions/html.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']);
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$search_stuff\"";
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, '', $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;
254 /* if $start_msg is lower than $num_msgs, we probably deleted all messages
255 * in the last page. We need to re-adjust the start_msg
258 if($start_msg > $num_msgs) {
259 $start_msg -= $show_num;
265 /* This code and the next if() block check for
266 * server-side sorting methods. The $id array is
267 * formatted and $sort is set to 6 to disable
268 * SM internal sorting
270 if ($thread_sort_messages == 1) {
271 $id = get_thread_sort($imapConnection);
273 echo '<b><small><center><font color=red>' .
274 _("Thread sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
275 '</center></small></b>';
276 $thread_sort_messages = 0;
281 if ($start_msg +
($show_num - 1) < $num_msgs) {
282 $end_msg = $start_msg +
($show_num-1);
285 $end_msg = $num_msgs;
287 $id = array_slice($id, ($start_msg-1), ($end_msg));
291 if ($allow_server_sort == TRUE && $thread_sort_messages != 1) {
292 $server_sort_order = $sort;
293 $id = sqimap_get_sort_order($imapConnection, $server_sort_order);
295 echo '<b><small><center><font color=red>' .
296 _( "Server-side sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
297 '</center></small></b>';
298 $sort = $server_sort_order;
299 $allow_server_sort = FALSE;
304 if ($start_msg +
($show_num - 1) < $num_msgs) {
305 $end_msg = $start_msg +
($show_num-1);
308 $end_msg = $num_msgs;
310 $id = array_slice($id, ($start_msg-1), ($end_msg));
314 /* If autoexpunge is turned on, then do it now. */
315 if ($auto_expunge == true) {
316 sqimap_mailbox_expunge($imapConnection, $mailbox, false);
318 sqimap_mailbox_select($imapConnection, $mailbox);
319 $issent = handleAsSent($mailbox);
321 /* If it is sorted... */
322 if ($num_msgs >= 1) {
324 $id = range(1, $num_msgs);
326 elseif ($thread_sort_messages != 1 && $allow_server_sort != TRUE && $sort == 6) {
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) {
340 $real_startMessage = $num_msgs - $start_msg +
1;
341 $real_endMessage = $num_msgs - $start_msg - $show_num +
2;
342 if ($real_endMessage <= 0) {
343 $real_endMessage = 1;
345 $id = array_reverse(range($real_endMessage, $real_startMessage));
347 $msgs_list = sqimap_get_small_header_list($imapConnection, $id, $issent);
348 // $flags = sqimap_get_flags_list($imapConnection, $id, $issent);
349 if (sizeof($msgs_list)){
350 foreach ($msgs_list as $hdr) {
351 $from[] = $hdr->from
;
352 $date[] = $hdr->date
;
353 $subject[] = $hdr->subject
;
355 $priority[] = $hdr->priority
;
357 $size[] = $hdr->size
;
358 $type[] = $hdr->type0
;
359 $flag_deleted[] = $hdr->flag_deleted
;
360 $flag_answered[] = $hdr->flag_answered
;
361 $flag_seen[] = $hdr->flag_seen
;
362 $flag_flagged[] = $hdr->flag_flagged
;
368 $end = $start_msg +
$show_num - 1;
369 if ($num_msgs < $show_num) {
370 $end_loop = $num_msgs;
371 } else if ($end > $num_msgs) {
372 $end_loop = $num_msgs - $start_msg +
1;
374 $end_loop = $show_num;
380 while ($j < $end_loop) {
381 if (isset($date[$j])) {
382 $date[$j] = str_replace(' ', ' ', $date[$j]);
383 $tmpdate = explode(' ', trim($date[$j]));
385 $tmpdate = $date = array('', '', '', '', '', '');
388 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
389 $messages[$j]['DATE_STRING'] =
390 getDateString($messages[$j]['TIME_STAMP']);
391 $messages[$j]['ID'] = $id[$j];
392 $messages[$j]['FROM'] = decodeHeader($from[$j]);
393 $messages[$j]['FROM-SORT'] =
394 strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
395 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
396 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
397 $messages[$j]['TO'] = decodeHeader($to[$j]);
398 $messages[$j]['PRIORITY'] = $priority[$j];
399 $messages[$j]['CC'] = $cc[$j];
400 $messages[$j]['SIZE'] = $size[$j];
401 $messages[$j]['TYPE0'] = $type[$j];
402 $messages[$j]['FLAG_DELETED'] = $flag_deleted[$j];
403 $messages[$j]['FLAG_ANSWERED'] = $flag_answered[$j];
404 $messages[$j]['FLAG_SEEN'] = $flag_seen[$j];
405 $messages[$j]['FLAG_FLAGGED'] = $flag_flagged[$j];
409 * fix SUBJECT-SORT to remove Re:
413 * TODO: i18n should be incorporated here. E.g. we catch the ones
414 * we know about, but also define in i18n what the localized
415 * "Re: " is for this or that locale.
417 if (preg_match("/^(vedr|sv|re|aw):\s*(.*)$/si",
418 $messages[$j]['SUBJECT-SORT'], $matches)){
419 $messages[$j]['SUBJECT-SORT'] = $matches[2];
423 while ($num < count($flags[$j])) {
424 if ($flags[$j][$num] == 'Deleted') {
425 $messages[$j]['FLAG_DELETED'] = true;
426 } else if ($flags[$j][$num] == 'Answered') {
427 $messages[$j]['FLAG_ANSWERED'] = true;
428 } else if ($flags[$j][$num] == 'Seen') {
429 $messages[$j]['FLAG_SEEN'] = true;
430 } else if ($flags[$j][$num] == 'Flagged') {
431 $messages[$j]['FLAG_FLAGGED'] = true;
441 * Only ignore messages flagged as deleted if we are
442 * using a trash folder or auto_expunge
444 if (((isset($move_to_trash) && $move_to_trash)
445 ||
(isset($auto_expunge) && $auto_expunge))
448 /* Find and remove the ones that are deleted */
452 while ($j < $num_msgs) {
453 if (isset($messages[$j]['FLAG_DELETED'])
454 && $messages[$j]['FLAG_DELETED'] == true) {
458 $msgs[$i] = $messages[$j];
465 if (!isset($messages)) {
472 /* There's gotta be messages in the array for it to sort them. */
473 if (($num_msgs > 0) && (!$use_cache)) {
482 session_unregister('msgs');
483 if (($sort == 0) ||
($sort == 1)) {
484 $msort = array_cleave ($msgs, 'TIME_STAMP');
485 } elseif (($sort == 2) ||
($sort == 3)) {
486 $msort = array_cleave ($msgs, 'FROM-SORT');
487 } elseif (($sort == 4) ||
($sort == 5)) {
488 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
500 session_register('msort');
501 } elseif ($thread_sort_messages == 1 ||
$allow_server_sort == TRUE) {
503 session_unregister('msgs');
504 session_register('msort');
506 displayMessageArray($imapConnection, $num_msgs, $start_msg, $msgs,
507 $msort, $mailbox, $sort, $color,$show_num);
509 * TODO: Switch to using $_SESSION[] whenever we ditch the 4.0.x series.
511 session_register('msgs');
514 /* Generic function to convert the msgs array into an HTML table. */
515 function displayMessageArray($imapConnection, $num_msgs, $start_msg,
516 &$msgs, $msort, $mailbox, $sort, $color,
519 global $folder_prefix, $sent_folder,
520 $imapServerAddress, $data_dir, $username, $use_mailbox_cache,
521 $index_order, $real_endMessage, $real_startMessage, $checkall,
522 $indent_array, $thread_sort_messages, $allow_server_sort,
525 /* If cache isn't already set, do it now. */
526 if (!session_is_registered('msgs')) {
527 session_register('msgs');
529 if (!session_is_registered('msort')) {
530 session_register('msort');
533 if ($start_msg +
($show_num - 1) < $num_msgs){
534 $end_msg = $start_msg +
($show_num - 1);
536 $end_msg = $num_msgs;
539 if ($end_msg < $start_msg) {
540 $start_msg = $start_msg - $show_num;
541 if ($start_msg < 1) {
546 $urlMailbox = urlencode($mailbox);
548 do_hook('mailbox_index_before');
550 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
551 $paginator_str = get_paginator_str($urlMailbox, $start_msg, $end_msg,
552 $num_msgs, $show_num, $sort);
558 /* get indent level for subject display */
559 if ($thread_sort_messages == 1 ) {
560 $indent_array = get_parent_level($imapConnection);
562 $fstring = "move_messages.php?msg=$msg&mailbox=$urlMailbox"
563 . "&startMessage=$start_msg";
564 mail_message_listing_beginning($imapConnection, $fstring,
565 $mailbox, $sort, $msg_cnt_str,
566 $paginator_str, $start_msg);
568 $groupNum = $start_msg %
($show_num - 1);
569 $real_startMessage = $start_msg;
571 if ($end_msg - $start_msg < $show_num - 1) {
572 $end_msg = $end_msg - $start_msg +
1;
574 } else if ($start_msg > $show_num) {
575 $end_msg = $show_num;
579 $endVar = $end_msg +
1;
582 * Loop through and display the info for each message.
583 * ($t is used for the checkbox number)
586 if ($num_msgs == 0) {
587 /* if there's no messages in this folder */
591 _("THIS FOLDER IS EMPTY") .
595 'COLSPAN="' . count($index_order) . '"'
599 } elseif ($start_msg == $end_msg) {
600 /* if there's only one message in the box, handle it differently. */
612 } while (isset ($key) && ($k < $i));
613 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort,
614 $real_startMessage, 0, 0);
623 } while (isset ($key) && ($k < $i));
625 printMessageInfo($imapConnection, $t, $i, $key, $mailbox,
626 $sort, $real_startMessage, 0, 0);
631 } while ($i && $i < $endVar);
636 echo html_tag( 'table',
641 html_tag( 'td', $paginator_str ) .
642 html_tag( 'td', $msg_cnt_str, 'right' )
644 , '', $color[4], 'width="100%" cellpadding="1" cellspacing="1"' )
647 , '', $color[9], 'width="100%" cellpadding="1" cellspacing="1"' );
649 /* End of message-list table */
651 do_hook('mailbox_index_after');
652 echo "</TABLE></FORM>\n";
656 * Displays the standard message list header. To finish the table,
657 * you need to do a "</table></table>";
659 * $moveURL is the URL to submit the delete/move form to
660 * $mailbox is the current mailbox
661 * $sort is the current sorting method (-1 for no sorting available [searches])
662 * $Message is a message that is centered on top of the list
663 * $More is a second line that is left aligned
666 function mail_message_listing_beginning ($imapConnection, $moveURL,
667 $mailbox = '', $sort = -1,
669 $paginator = ' ',
671 global $color, $index_order, $auto_expunge, $move_to_trash, $base_uri,
672 $checkall, $sent_folder, $draft_folder, $thread_sort_messages,
673 $allow_thread_sort, $allow_server_sort, $server_sort_order,
676 $urlMailbox = urlencode($mailbox);
679 * This is the beginning of the message list table.
680 * It wraps around all messages
682 echo "<FORM name=\"messageList\" method=post action=\"$moveURL\">\n"
683 . "<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLPADDING=\"1\" "
684 . "CELLSPACING=\"0\">\n<TR BGCOLOR=\"$color[0]\"><TD>"
685 . " <TABLE BGCOLOR=\"$color[4]\" width=\"100%\" CELLPADDING=\"2\" "
686 . "CELLSPACING=\"0\" BORDER=\"0\"><TR>\n"
687 . html_tag( 'td', $paginator, 'left' )
688 . html_tag( 'td', $msg_cnt_str, 'right' )
691 . "<TR><TD BGCOLOR=\"$color[0]\">\n"
692 . "<TABLE BGCOLOR=\"$color[0]\" BORDER=0 cellpadding=0 "
693 . "cellspacing=0 width=\"100%\">\n"
696 '<SMALL> ' . _("Move Selected To:") . '</SMALL>',
699 'valign="middle" nowrap' )
701 '<SMALL>' . _("Transform Selected Messages") . ': </SMALL><BR>',
707 . html_tag( 'td', '', 'left', '', 'valign="middle" nowrap' )
708 . ' <SMALL> <TT><SELECT NAME="targetMailbox">';
710 $boxes = sqimap_mailbox_list($imapConnection);
711 foreach ($boxes as $boxes_part) {
712 if (!in_array('noselect', $boxes_part['flags'])) {
713 $box = $boxes_part['unformatted'];
714 $box2 = str_replace(' ', ' ', imap_utf7_decode_local($boxes_part['unformatted-disp']));
715 if( $box2 == 'INBOX' ) {
718 if ($lastTargetMailbox == $box) {
719 echo " <OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
722 echo " <OPTION VALUE=\"$box\">$box2</OPTION>\n";
726 echo ' </SELECT></TT> '
727 . '<INPUT TYPE="SUBMIT" NAME="moveButton" VALUE="' . _("Move") . '"> '
728 . '<INPUT TYPE="SUBMIT" NAME="attache" VALUE="' . _("Forward")
729 . "\"> \n" . "</SMALL>\n";
732 . " <TD ALIGN=\"RIGHT\" NOWRAP>";
733 if (!$auto_expunge) {
734 echo '<INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="' . _("Expunge")
735 . '"> ' . _("mailbox") . ' ';
737 echo '<INPUT TYPE="SUBMIT" NAME="markRead" VALUE="' . _("Read") . '">'
738 . '<INPUT TYPE="SUBMIT" NAME="markUnread" VALUE="' . _("Unread") . '">'
739 . '<INPUT TYPE="SUBMIT" VALUE="' . _("Delete") . '"> '
743 /* draws thread sorting links */
744 if ($allow_thread_sort == TRUE) {
745 if ($thread_sort_messages == 1 ) {
747 $thread_name = _("Unthread View");
749 elseif ($thread_sort_messages == 0) {
751 $thread_name = _("Thread View");
753 echo '<tr><td> <a href=' . "$base_uri" . 'src/right_main.php?sort='
754 . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
755 . '&mailbox=' . urlencode($mailbox) . '><small>' . $thread_name
756 . '</a></small> </td></tr>';
760 do_hook('mailbox_form_before');
762 . "<TR><TD BGCOLOR=\"$color[0]\">"
763 . '<TABLE WIDTH="100%" BORDER=0 CELLPADDING=2 CELLSPACING=';
764 if ($GLOBALS['alt_index_colors']){
769 echo " BGCOLOR=\"$color[0]\">"
770 . "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
771 /* if using server sort we highjack the
772 * the $sort var and use $server_sort_order
773 * instead. but here we reset sort for a bit
776 if ($allow_server_sort == TRUE) {
777 $sort = $server_sort_order;
779 /* Print the headers. */
780 for ($i=1; $i <= count($index_order); $i++
) {
781 switch ($index_order[$i]) {
782 case 1: /* checkbox */
784 echo ' <TD WIDTH="1%"></TD>';
787 if (handleAsSent($mailbox)) {
788 echo ' <TD WIDTH="25%"><B>' . _("To") . '</B>';
790 echo ' <TD WIDTH="25%"><B>' . _("From") . '</B>';
792 if ($allow_thread_sort != TRUE ||
$thread_sort_messages != 1) {
793 ShowSortButton($sort, $mailbox, 2, 3);
798 echo ' <TD NOWRAP WIDTH="5%"><B>' . _("Date") . '</B>';
799 if ($allow_thread_sort != TRUE ||
$thread_sort_messages != 1) {
800 ShowSortButton($sort, $mailbox, 0, 1);
804 case 4: /* subject */
805 echo ' <TD><B>' . _("Subject") . '</B> ';
806 if ($allow_thread_sort != TRUE ||
$thread_sort_messages != 1) {
807 ShowSortButton($sort, $mailbox, 4, 5);
812 echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%"' );
816 /* if using server-sorting,
817 * send sort back to 6
819 if ($allow_server_sort == TRUE) {
826 * This function shows the sort button. Isn't this a good comment?
828 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 /* Now that we have everything figured out, show the actual button. */
842 echo ' <a href="right_main.php?newsort=' . $which
843 . '&startMessage=1&mailbox=' . urlencode($mailbox)
844 . '"><IMG SRC="../images/' . $img
845 . '" BORDER=0 WIDTH=12 HEIGHT=10 ALT="sort"></a>';
848 function get_selectall_link($start_msg, $sort) {
849 global $checkall, $what, $where, $mailbox, $javascript_on;
850 global $PHP_SELF, $PG_SHOWNUM;
853 if ($javascript_on) {
855 '<script language="JavaScript" type="text/javascript">'
857 . "function CheckAll() {\n"
858 . " for (var i = 0; i < document.messageList.elements.length; i++) {\n"
859 . " if(document.messageList.elements[i].type == 'checkbox'){\n"
860 . " document.messageList.elements[i].checked = "
861 . " !(document.messageList.elements[i].checked);\n"
866 . '</script><a href="#" onClick="CheckAll();">' . _("Toggle All")
869 if (strpos($PHP_SELF, "?")) {
870 $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($mailbox)
871 . "&startMessage=$start_msg&sort=$sort&checkall=";
873 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
874 . "&startMessage=$start_msg&sort=$sort&checkall=";
876 if (isset($checkall) && $checkall == '1') {
882 if (isset($where) && isset($what)) {
883 $result .= '&where=' . urlencode($where)
884 . '&what=' . urlencode($what);
889 if (isset($checkall) && ($checkall == '1')) {
890 $result .= _("Unselect All");
892 $result .= _("Select All");
898 /* Return our final result. */
903 * This function computes the "Viewing Messages..." string.
905 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
906 /* Compute the $msg_cnt_str. */
908 if ($start_msg < $end_msg) {
909 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"),
910 $start_msg, $end_msg, $num_msgs);
911 } else if ($start_msg == $end_msg) {
912 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
917 /* Return our result string. */
922 * Generate a paginator link.
924 function get_paginator_link($box, $start_msg, $use, $text) {
925 $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
926 . "&startMessage=$start_msg&mailbox=$box\" "
927 . "TARGET=\"right\">$text</A>";
932 * This function computes the paginator string.
934 function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
936 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
938 /* Initialize paginator string chunks. */
945 /* Create simple strings that will be creating the paginator. */
946 $spc = ' '; /* This will be used as a space. */
947 $sep = '|'; /* This will be used as a seperator. */
949 /* Get some paginator preference values. */
950 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON
);
951 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
);
953 /* Make sure that our start message number is not too big. */
954 $start_msg = min($start_msg, $num_msgs);
956 /* Decide whether or not we will use the mailbox cache. */
957 /* Not sure why $use_mailbox_cache is even passed in. */
964 /* Compute the starting message of the previous and next page group. */
965 $next_grp = $start_msg +
$show_num;
966 $prev_grp = $start_msg - $show_num;
968 /* Compute the basic previous and next strings. */
969 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
970 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
971 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
972 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
973 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
974 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
975 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
976 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
977 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
980 /* Page selector block. Following code computes page links. */
981 if ($pg_sel && ($num_msgs > $show_num)) {
982 /* Most importantly, what is the current page!!! */
983 $cur_pg = intval($start_msg / $show_num) +
1;
985 /* Compute total # of pages and # of paginator page links. */
986 $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
987 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
989 /* Compute the size of the four quarters of the page links. */
991 /* If we can, just show all the pages. */
992 if (($tot_pgs - 1) <= $pg_max) {
993 $q1_pgs = $cur_pg - 1;
994 $q2_pgs = $q3_pgs = 0;
995 $q4_pgs = $tot_pgs - $cur_pg;
997 /* Otherwise, compute some magic to choose the four quarters. */
1000 * Compute the magic base values. Added together,
1001 * these values will always equal to the $pag_pgs.
1002 * NOTE: These are DEFAULT values and do not take
1003 * the current page into account. That is below.
1005 $q1_pgs = floor($vis_pgs/4);
1006 $q2_pgs = round($vis_pgs/4, 0);
1007 $q3_pgs = ceil($vis_pgs/4);
1008 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
1010 /* Adjust if the first quarter contains the current page. */
1011 if (($cur_pg - $q1_pgs) < 1) {
1012 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) +
$q2_pgs;
1013 $q1_pgs = $cur_pg - 1;
1015 $q3_pgs +
= ceil($extra_pgs / 2);
1016 $q4_pgs +
= floor($extra_pgs / 2);
1018 /* Adjust if the first and second quarters intersect. */
1019 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
1020 $extra_pgs = $q2_pgs;
1021 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1022 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1023 $q3_pgs +
= ceil($extra_pgs / 2);
1024 $q4_pgs +
= floor($extra_pgs / 2);
1026 /* Adjust if the fourth quarter contains the current page. */
1027 } else if (($cur_pg +
$q4_pgs) >= $tot_pgs) {
1028 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) +
$q3_pgs;
1030 $q4_pgs = $tot_pgs - $cur_pg;
1031 $q1_pgs +
= floor($extra_pgs / 2);
1032 $q2_pgs +
= ceil($extra_pgs / 2);
1034 /* Adjust if the third and fourth quarter intersect. */
1035 } else if (($cur_pg +
$q3_pgs +
1) >= ($tot_pgs - $q4_pgs +
1)) {
1036 $extra_pgs = $q3_pgs;
1037 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1038 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1039 $q1_pgs +
= floor($extra_pgs / 2);
1040 $q2_pgs +
= ceil($extra_pgs / 2);
1045 * I am leaving this debug code here, commented out, because
1046 * it is a really nice way to see what the above code is doing.
1047 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
1048 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
1051 /* Print out the page links from the compute page quarters. */
1053 /* Start with the first quarter. */
1054 if (($q1_pgs == 0) && ($cur_pg > 1)) {
1055 $pg_str .= "...$spc";
1057 for ($pg = 1; $pg <= $q1_pgs; ++
$pg) {
1058 $start = (($pg-1) * $show_num) +
1;
1059 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1061 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
1062 $pg_str .= "...$spc";
1066 /* Continue with the second quarter. */
1067 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++
$pg) {
1068 $start = (($pg-1) * $show_num) +
1;
1069 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1072 /* Now print the current page. */
1073 $pg_str .= $cur_pg . $spc;
1075 /* Next comes the third quarter. */
1076 for ($pg = $cur_pg +
1; $pg <= $cur_pg +
$q3_pgs; ++
$pg) {
1077 $start = (($pg-1) * $show_num) +
1;
1078 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1081 /* And last, print the forth quarter page links. */
1082 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
1083 $pg_str .= "...$spc";
1085 if (($tot_pgs - $q4_pgs) > ($cur_pg +
$q3_pgs)) {
1086 $pg_str .= "...$spc";
1088 for ($pg = $tot_pgs - $q4_pgs +
1; $pg <= $tot_pgs; ++
$pg) {
1089 $start = (($pg-1) * $show_num) +
1;
1090 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1093 } else if ($PG_SHOWNUM == 999999) {
1094 $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
1095 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1096 . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc;
1099 /* If necessary, compute the 'show all' string. */
1100 if (($prv_str != '') ||
($nxt_str != '')) {
1101 $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
1102 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1103 . "TARGET=\"right\">" . _("Show All") . '</A>';
1106 /* Last but not least, get the value for the toggle all link. */
1107 $tgl_str = get_selectall_link($start_msg, $sort);
1109 /* Put all the pieces of the paginator string together. */
1111 * Hairy code... But let's leave it like it is since I am not certain
1112 * a different approach would be any easier to read. ;)
1115 $result .= ($prv_str != '' ?
$prv_str . $spc . $sep . $spc : '');
1116 $result .= ($nxt_str != '' ?
$nxt_str . $spc . $sep . $spc : '');
1117 $result .= ($pg_str != '' ?
$pg_str : '');
1118 $result .= ($all_str != '' ?
$sep . $spc . $all_str . $spc : '');
1119 $result .= ($result != '' ?
$sep . $spc . $tgl_str: $tgl_str);
1121 /* If the resulting string is blank, return a non-breaking space. */
1122 if ($result == '') {
1126 /* Return our final magical paginator string. */
1130 function processSubject($subject) {
1131 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1133 return _("(no subject)");
1135 if (strlen($subject) <= 55)
1138 $ent_strlen=strlen($subject);
1142 * see if this is entities-encoded string
1143 * If so, Iterate through the whole string, find out
1144 * the real number of characters, and if more
1145 * than 55, substr with an updated trim value.
1147 while ( (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1148 (($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false) ) {
1149 $trim_val +
= ($ent_loc_end-$ent_loc)+
1;
1150 $ent_strlen -= $ent_loc_end-$ent_loc;
1151 $ent_offset = $ent_loc_end+
1;
1154 if ($ent_strlen <= 55){
1158 return substr($subject, 0, $trim_val) . '...';
1161 function handleAsSent($mailbox) {
1162 global $sent_folder, $draft_folder, $handleAsSent_result;
1164 /* First check if this is the sent or draft folder. */
1165 $handleAsSent_result = (($mailbox == $sent_folder)
1166 ||
($mailbox == $draft_folder));
1168 /* Then check the result of the handleAsSent hook. */
1169 do_hook('check_handleAsSent_result', $mailbox);
1171 /* And return the result. */
1172 return ($handleAsSent_result);