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');
17 /* Default value for page_selector_max. */
18 define('PG_SEL_MAX', 10);
20 function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort,
21 $start_msg, $where, $what){
23 $color, $msgs, $msort,
24 $sent_folder, $draft_folder,
25 $default_use_priority,
26 $message_highlight_list,
28 $indent_array, /* indent subject by */
29 $pos, /* Search postion (if any) */
30 $thread_sort_messages, /* thread sorting on/off */
32 $color_string = $color[4];
34 if ($GLOBALS['alt_index_colors']) {
35 if (!isset($row_count)) {
40 if (!isset($color[12])) {
41 $color[12] = '#EAEAEA';
43 $color_string = $color[12];
49 * This is done in case you're looking into Sent folders,
50 * because you can have multiple receivers.
52 $senderNames = explode(',', $msg['FROM']);
54 if (sizeof($senderNames)){
55 foreach ($senderNames as $senderNames_part) {
56 if ($senderName != '') {
59 $senderName .= sqimap_find_displayable_name($senderNames_part);
63 if( $mailbox == 'None' ) {
64 $boxes = sqimap_mailbox_list($imapConnection);
65 $mailbox = $boxes[0]['unformatted'];
68 $urlMailbox = urlencode($mailbox);
69 $subject = processSubject($msg['SUBJECT']);
72 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
73 $flag = "<font color=\"$color[2]\">";
74 $flag_end = '</font>';
79 if (!isset($msg['FLAG_SEEN']) ||
($msg['FLAG_SEEN'] == false)) {
86 if (handleAsSent($mailbox)) {
93 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
94 $fontstr = "<font color=\"$color[9]\">";
95 $fontstr_end = '</font>';
102 * AAAAH! Make my eyes stop bleeding!
105 if (sizeof($message_highlight_list)){
106 foreach ($message_highlight_list as $message_highlight_list_part) {
107 if (trim($message_highlight_list_part['value']) != '') {
108 if ($message_highlight_list_part['match_type'] == 'to_cc') {
109 if (strstr('^^' . strtolower($msg['TO']),
110 strtolower($message_highlight_list_part['value']))
111 ||
strstr('^^'.strtolower($msg['CC']),
112 strtolower($message_highlight_list_part['value']))) {
113 $hlt_color = $message_highlight_list_part['color'];
117 if (strstr('^^' . strtolower($msg[strtoupper($message_highlight_list_part['match_type'])]),
118 strtolower($message_highlight_list_part['value']))) {
119 $hlt_color = $message_highlight_list_part['color'];
126 if (!isset($hlt_color)) {
127 $hlt_color = $color_string;
130 if ($where && $what) {
131 if(!isset($pos) ||
$pos == '') {
134 $search_stuff = "&pos=" . urlencode($pos)
135 . "&where=" . urlencode($where) . '&what=' . urlencode($what);
140 $checked = ($checkall == 1) ?
' checked' : '';
142 if (sizeof($index_order)){
143 foreach ($index_order as $index_order_part) {
144 switch ($index_order_part) {
145 case 1: /* checkbox */
146 echo " <td bgcolor=\"$hlt_color\" align=center>"
147 . "<input type=checkbox name=\"msg[$t]\" value="
148 . $msg["ID"]."$checked></TD>\n";
151 echo " <td bgcolor=\"$hlt_color\">$italic$bold$flag$fontstr"
152 . "$senderName$fontstr_end$flag_end$bold_end$italic_end</td>\n";
155 echo " <td nowrap bgcolor=\"$hlt_color\"><center>$bold$flag$fontstr"
156 . $msg["DATE_STRING"]
157 . "$fontstr_end$flag_end$bold_end</center></td>\n";
159 case 4: /* subject */
160 echo " <td bgcolor=\"$hlt_color\">$bold";
161 if ($thread_sort_messages == 1) {
162 echo str_repeat(" ",$indent_array[$msg["ID"]]);
164 echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id="
166 . "&startMessage=$start_msg&show_more=0$search_stuff\"";
167 do_hook("subject_link");
168 if ($subject != $msg['SUBJECT']) {
169 $title = get_html_translation_table(HTML_SPECIALCHARS
);
170 $title = array_flip($title);
171 $title = strtr($msg['SUBJECT'], $title);
172 $title = str_replace('"', "''", $title);
173 echo " title=\"$title\"";
175 echo ">$flag$subject$flag_end</a>$bold_end</td>\n";
179 echo " <td bgcolor=\"$hlt_color\" align=center nowrap><b><small>\n";
180 if (isset($msg['FLAG_ANSWERED']) && $msg['FLAG_ANSWERED'] == true) {
184 if ($msg['TYPE0'] == 'multipart') {
188 if ($default_use_priority) {
189 if ( ($msg['PRIORITY'][0] == 1) ||
($msg['PRIORITY'][0] == 2) ) {
190 echo "<font color=\"$color[1]\">!</font>\n";
193 if ($msg['PRIORITY'][0] == 5) {
194 echo "<font color=\"$color[8]\">?</font>\n";
198 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'] == true) {
199 echo "<font color=\"$color[1]\">D</font>\n";
205 echo "</small></b></td>\n";
208 echo " <td bgcolor=\"$hlt_color\">$bold$fontstr"
209 . show_readable_size($msg['SIZE']) . "$fontstr_end$bold_end</td>\n";
218 * This function loops through a group of messages in the mailbox
219 * and shows them to the user.
221 function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
222 $start_msg, $sort, $color, $show_num,
224 global $msgs, $msort,
225 $sent_folder, $draft_folder,
226 $message_highlight_list,
227 $auto_expunge, $thread_sort_messages,
228 $data_dir, $username;
229 /* If autoexpunge is turned on, then do it now. */
231 if ($thread_sort_messages == 1) {
232 $id = get_thread_sort($imapConnection);
234 if ($start_msg +
($show_num - 1) < $num_msgs) {
235 $end_msg = $start_msg +
($show_num-1);
237 $end_msg = $num_msgs;
239 $id = array_slice($id, ($start_msg-1), ($end_msg));
241 if ($auto_expunge == true) {
242 sqimap_mailbox_expunge($imapConnection, $mailbox, false);
244 sqimap_mailbox_select($imapConnection, $mailbox);
245 $issent = handleAsSent($mailbox);
247 /* If it is sorted... */
248 if ($num_msgs >= 1) {
250 $id = range(1, $num_msgs);
252 elseif ($thread_sort_messages != 1) {
253 /* if it's not sorted */
254 if ($start_msg +
($show_num - 1) < $num_msgs){
255 $end_msg = $start_msg +
($show_num - 1);
257 $end_msg = $num_msgs;
259 if ($end_msg < $start_msg) {
260 $start_msg = $start_msg - $show_num;
261 if ($start_msg < 1) {
266 $real_startMessage = $num_msgs - $start_msg +
1;
267 $real_endMessage = $num_msgs - $start_msg - $show_num +
2;
268 if ($real_endMessage <= 0) {
269 $real_endMessage = 1;
271 $id = array_reverse(range($real_endMessage, $real_startMessage));
273 $msgs_list = sqimap_get_small_header_list($imapConnection, $id, $issent);
274 $flags = sqimap_get_flags_list($imapConnection, $id, $issent);
275 if (sizeof($msgs_list)){
276 foreach ($msgs_list as $hdr) {
277 $from[] = $hdr->from
;
278 $date[] = $hdr->date
;
279 $subject[] = $hdr->subject
;
281 $priority[] = $hdr->priority
;
283 $size[] = $hdr->size
;
284 $type[] = $hdr->type0
;
290 $end = $start_msg +
$show_num - 1;
291 if ($num_msgs < $show_num) {
292 $end_loop = $num_msgs;
293 } else if ($end > $num_msgs) {
294 $end_loop = $num_msgs - $start_msg +
1;
296 $end_loop = $show_num;
302 while ($j < $end_loop) {
303 if (isset($date[$j])) {
304 $date[$j] = str_replace(' ', ' ', $date[$j]);
305 $tmpdate = explode(' ', trim($date[$j]));
307 $tmpdate = $date = array('', '', '', '', '', '');
310 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
311 $messages[$j]['DATE_STRING'] =
312 getDateString($messages[$j]['TIME_STAMP']);
313 $messages[$j]['ID'] = $id[$j];
314 $messages[$j]['FROM'] = decodeHeader($from[$j]);
315 $messages[$j]['FROM-SORT'] =
316 strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
317 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
318 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
319 $messages[$j]['TO'] = decodeHeader($to[$j]);
320 $messages[$j]['PRIORITY'] = $priority[$j];
321 $messages[$j]['CC'] = $cc[$j];
322 $messages[$j]['SIZE'] = $size[$j];
323 $messages[$j]['TYPE0'] = $type[$j];
326 * fix SUBJECT-SORT to remove Re:
330 * TODO: i18n should be incorporated here. E.g. we catch the ones
331 * we know about, but also define in i18n what the localized
332 * "Re: " is for this or that locale.
334 if (preg_match("/^(vedr|sv|re|aw):\s*(.*)$/si",
335 $messages[$j]['SUBJECT-SORT'], $matches)){
336 $messages[$j]['SUBJECT-SORT'] = $matches[2];
340 while ($num < count($flags[$j])) {
341 if ($flags[$j][$num] == 'Deleted') {
342 $messages[$j]['FLAG_DELETED'] = true;
343 } else if ($flags[$j][$num] == 'Answered') {
344 $messages[$j]['FLAG_ANSWERED'] = true;
345 } else if ($flags[$j][$num] == 'Seen') {
346 $messages[$j]['FLAG_SEEN'] = true;
347 } else if ($flags[$j][$num] == 'Flagged') {
348 $messages[$j]['FLAG_FLAGGED'] = true;
356 * Only ignore messages flagged as deleted if we are
357 * using a trash folder or auto_expunge
359 if (((isset($move_to_trash) && $move_to_trash)
360 ||
(isset($auto_expunge) && $auto_expunge))
363 /* Find and remove the ones that are deleted */
367 while ($j < $num_msgs) {
368 if (isset($messages[$j]['FLAG_DELETED'])
369 && $messages[$j]['FLAG_DELETED'] == true) {
373 $msgs[$i] = $messages[$j];
380 if (!isset($messages)) {
387 /* There's gotta be messages in the array for it to sort them. */
388 if (($num_msgs > 0) && (!$use_cache)) {
397 session_unregister('msgs');
398 if (($sort == 0) ||
($sort == 1)) {
399 $msort = array_cleave ($msgs, 'TIME_STAMP');
400 } elseif (($sort == 2) ||
($sort == 3)) {
401 $msort = array_cleave ($msgs, 'FROM-SORT');
402 } elseif (($sort == 4) ||
($sort == 5)) {
403 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
415 session_register('msort');
416 } elseif ($thread_sort_messages == 1 ) {
418 session_unregister('msgs');
419 session_register('msort');
421 displayMessageArray($imapConnection, $num_msgs, $start_msg, $msgs,
422 $msort, $mailbox, $sort, $color,$show_num);
424 * TODO: Switch to using $_SESSION[] whenever we ditch the 4.0.x series.
426 session_register('msgs');
429 /* Generic function to convert the msgs array into an HTML table. */
430 function displayMessageArray($imapConnection, $num_msgs, $start_msg,
431 &$msgs, $msort, $mailbox, $sort, $color,
433 global $folder_prefix, $sent_folder,
434 $imapServerAddress, $data_dir, $username, $use_mailbox_cache,
435 $index_order, $real_endMessage, $real_startMessage, $checkall,
436 $indent_array, $thread_sort_messages;
438 /* If cache isn't already set, do it now. */
439 if (!session_is_registered('msgs')) {
440 session_register('msgs');
442 if (!session_is_registered('msort')) {
443 session_register('msort');
446 if ($start_msg +
($show_num - 1) < $num_msgs){
447 $end_msg = $start_msg +
($show_num - 1);
449 $end_msg = $num_msgs;
452 if ($end_msg < $start_msg) {
453 $start_msg = $start_msg - $show_num;
454 if ($start_msg < 1) {
459 $urlMailbox = urlencode($mailbox);
461 do_hook('mailbox_index_before');
463 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
464 $paginator_str = get_paginator_str($urlMailbox, $start_msg, $end_msg,
465 $num_msgs, $show_num, $sort);
471 /* get indent level for subject display */
472 if ($thread_sort_messages == 1 ) {
473 $indent_array = get_parent_level($imapConnection);
475 $fstring = "move_messages.php?msg=$msg&mailbox=$urlMailbox"
476 . "&startMessage=$start_msg";
477 mail_message_listing_beginning($imapConnection, $fstring,
478 $mailbox, $sort, $msg_cnt_str,
479 $paginator_str, $start_msg);
481 $groupNum = $start_msg %
($show_num - 1);
482 $real_startMessage = $start_msg;
484 if ($end_msg - $start_msg < $show_num - 1) {
485 $end_msg = $end_msg - $start_msg +
1;
487 } else if ($start_msg > $show_num) {
488 $end_msg = $show_num;
492 $endVar = $end_msg +
1;
495 * Loop through and display the info for each message.
496 * ($t is used for the checkbox number)
499 if ($num_msgs == 0) {
500 /* if there's no messages in this folder */
501 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN="
502 . count($index_order) . ">\n"
503 . " <CENTER><BR><B>". _("THIS FOLDER IS EMPTY")
504 . "</B><BR> </CENTER>\n"
506 } elseif ($start_msg == $end_msg) {
507 /* if there's only one message in the box, handle it differently. */
519 } while (isset ($key) && ($k < $i));
520 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort,
521 $real_startMessage, 0, 0);
530 } while (isset ($key) && ($k < $i));
532 printMessageInfo($imapConnection, $t, $i, $key, $mailbox,
533 $sort, $real_startMessage, 0, 0);
538 } while ($i && $i < $endVar);
542 . "<table bgcolor=\"$color[9]\" width=\"100%\" border=0 cellpadding=1 "
543 . "cellspacing=1><tr BGCOLOR=\"$color[4]\"><td>"
544 . "<table width=\"100%\" BGCOLOR=\"$color[4]\" border=0 cellpadding=1 "
545 . "cellspacing=0><tr><td>$paginator_str</td>"
546 . "<td align=right>$msg_cnt_str</td></tr></table>"
547 . "</td></tr></table>";
548 /* End of message-list table */
550 do_hook('mailbox_index_after');
551 echo "</TABLE></FORM>\n";
555 * Displays the standard message list header. To finish the table,
556 * you need to do a "</table></table>";
558 * $moveURL is the URL to submit the delete/move form to
559 * $mailbox is the current mailbox
560 * $sort is the current sorting method (-1 for no sorting available [searches])
561 * $Message is a message that is centered on top of the list
562 * $More is a second line that is left aligned
564 function mail_message_listing_beginning ($imapConnection, $moveURL,
565 $mailbox = '', $sort = -1,
567 $paginator = ' ',
569 global $color, $index_order, $auto_expunge, $move_to_trash, $base_uri,
570 $checkall, $sent_folder, $draft_folder, $thread_sort_messages,
572 $urlMailbox = urlencode($mailbox);
575 * This is the beginning of the message list table.
576 * It wraps around all messages
578 echo "<FORM name=messageList method=post action=\"$moveURL\">\n"
579 . "<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLPADDING=\"1\" "
580 . "CELLSPACING=\"0\">\n<TR BGCOLOR=\"$color[0]\"><TD>"
581 . " <TABLE BGCOLOR=\"$color[4]\" width=\"100%\" CELLPADDING=\"2\" "
582 . "CELLSPACING=\"0\" BORDER=\"0\"><TR>\n"
583 . " <TD ALIGN=LEFT>$paginator\n";
585 if ($allow_thread_sort == TRUE) {
586 if ($thread_sort_messages == 1 ) {
588 $thread_name = 'Unthread View';
589 } elseif ($thread_sort_messages == 0) {
591 $thread_name = 'Thread View';
593 echo '| <a href=' . "$base_uri" . 'src/right_main.php?sort='
594 . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
595 . '&mailbox=' . urlencode($mailbox) . '>' . _("$thread_name")
599 echo " <TD ALIGN=RIGHT>$msg_cnt_str</TD>\n"
602 . "<TR><TD BGCOLOR=\"$color[0]\">\n"
603 . "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0"
604 . "cellspacing=0 width=\"100%\">\n"
606 . " <TD ALIGN=LEFT VALIGN=MIDDLE NOWRAP>\n"
607 . ' <SMALL> ' . _("Move Selected To:") . "</SMALL>\n"
609 . " <TD ALIGN=RIGHT NOWRAP>\n"
610 . ' <SMALL> ' . _("Transform Selected Messages")
611 . ": </SMALL><BR>\n"
615 . " <TD ALIGN=\"LEFT\" VALIGN=\"MIDDLE\" NOWRAP>\n"
616 . ' <SMALL> <TT><SELECT NAME="targetMailbox">';
618 $boxes = sqimap_mailbox_list($imapConnection);
619 foreach ($boxes as $boxes_part) {
620 if (!in_array('noselect', $boxes_part['flags'])) {
621 $box = $boxes_part['unformatted'];
622 $box2 = str_replace(' ', ' ', $boxes_part['unformatted-disp']);
623 if( $box2 == 'INBOX' ) {
626 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
629 echo ' </SELECT></TT> '
630 . '<INPUT TYPE="SUBMIT" NAME="moveButton" VALUE="' . _("Move") . '"> '
631 . '<INPUT TYPE="SUBMIT" NAME="attache" VALUE="' . _("Forward")
632 . "\"> \n" . "</SMALL>\n";
635 . " <TD ALIGN=\"RIGHT\" NOWRAP>";
636 if (!$auto_expunge) {
637 echo '<INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="' . _("Expunge")
638 . '"> ' . _("mailbox") . ' ';
640 echo '<INPUT TYPE="SUBMIT" NAME="markRead" VALUE="' . _("Read") . '">'
641 . '<INPUT TYPE="SUBMIT" NAME="markUnread" VALUE="' . _("Unread") . '">'
642 . '<INPUT TYPE="SUBMIT" VALUE="' . _("Delete") . '"> '
646 do_hook('mailbox_form_before');
648 . "<TR><TD BGCOLOR=\"$color[0]\">"
649 . '<TABLE WIDTH="100%" BORDER=0 CELLPADDING=2 CELLSPACING=';
650 if ($GLOBALS['alt_index_colors']){
655 echo " BGCOLOR=\"$color[0]\">"
656 . "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
658 /* Print the headers. */
659 for ($i=1; $i <= count($index_order); $i++
) {
660 switch ($index_order[$i]) {
661 case 1: /* checkbox */
663 echo ' <TD WIDTH="1%"><B> </B></TD>';
666 if (handleAsSent($mailbox)) {
667 echo ' <TD WIDTH="25%"><B>' . _("To") . '</B>';
669 echo ' <TD WIDTH="25%"><B>' . _("From") . '</B>';
671 if ($thread_sort_messages != 1) {
672 ShowSortButton($sort, $mailbox, 2, 3);
677 echo ' <TD NOWRAP WIDTH="5%"><B>' . _("Date") . '</B>';
678 if ($thread_sort_messages != 1) {
679 ShowSortButton($sort, $mailbox, 0, 1);
683 case 4: /* subject */
684 echo ' <TD><B>' . _("Subject") . '</B> ';
685 if ($thread_sort_messages != 1) {
686 ShowSortButton($sort, $mailbox, 4, 5);
691 echo ' <TD WIDTH="5%"><b>' . _("Size") . "</b></TD>\n";
699 * This function shows the sort button. Isn't this a good comment?
701 function ShowSortButton($sort, $mailbox, $Up, $Down) {
702 /* Figure out which image we want to use. */
703 if ($sort != $Up && $sort != $Down) {
704 $img = 'sort_none.png';
706 } elseif ($sort == $Up) {
707 $img = 'up_pointer.png';
710 $img = 'down_pointer.png';
714 /* Now that we have everything figured out, show the actual button. */
715 echo ' <a href="right_main.php?newsort=' . $which
716 . '&startMessage=1&mailbox=' . urlencode($mailbox)
717 . '"><IMG SRC="../images/' . $img
718 . '" BORDER=0 WIDTH=12 HEIGHT=10></a>';
721 function get_selectall_link($start_msg, $sort) {
722 global $checkall, $what, $where, $mailbox, $javascript_on;
723 global $PHP_SELF, $PG_SHOWNUM;
726 if ($javascript_on) {
728 '<script language="JavaScript" type="text/javascript">'
730 . "function CheckAll() {\n"
731 . " for (var i = 0; i < document.messageList.elements.length; i++) {\n"
732 . " if(document.messageList.elements[i].type == 'checkbox'){\n"
733 . " document.messageList.elements[i].checked = "
734 . " !(document.messageList.elements[i].checked);\n"
739 . '</script><a href="#" onClick="CheckAll();">' . _("Toggle All")
742 if (strpos($PHP_SELF, "?")) {
743 $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($mailbox)
744 . "&startMessage=$start_msg&sort=$sort&checkall=";
746 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
747 . "&startMessage=$start_msg&sort=$sort&checkall=";
749 if (isset($checkall) && $checkall == '1') {
755 if (isset($where) && isset($what)) {
756 $result .= '&where=' . urlencode($where)
757 . '&what=' . urlencode($what);
760 if ($PG_SHOWNUM == 999999) {
761 $result .= '&PG_SHOWNUM=999999';
766 if (isset($checkall) && ($checkall == '1')) {
767 $result .= _("Unselect All");
769 $result .= _("Select All");
775 /* Return our final result. */
780 * This function computes the "Viewing Messages..." string.
782 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
783 /* Compute the $msg_cnt_str. */
785 if ($start_msg < $end_msg) {
786 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"),
787 $start_msg, $end_msg, $num_msgs);
788 } else if ($start_msg == $end_msg) {
789 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
794 /* Return our result string. */
799 * Generate a paginator link.
801 function get_paginator_link($box, $start_msg, $use, $text) {
802 $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
803 . "&startMessage=$start_msg&mailbox=$box\" "
804 . "TARGET=\"right\">$text</A>";
809 * This function computes the paginator string.
811 function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
813 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
815 /* Initialize paginator string chunks. */
822 /* Create simple strings that will be creating the paginator. */
823 $spc = ' '; /* This will be used as a space. */
824 $sep = '|'; /* This will be used as a seperator. */
826 /* Get some paginator preference values. */
827 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON
);
828 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
);
830 /* Make sure that our start message number is not too big. */
831 $start_msg = min($start_msg, $num_msgs);
833 /* Decide whether or not we will use the mailbox cache. */
834 /* Not sure why $use_mailbox_cache is even passed in. */
841 /* Compute the starting message of the previous and next page group. */
842 $next_grp = $start_msg +
$show_num;
843 $prev_grp = $start_msg - $show_num;
845 /* Compute the basic previous and next strings. */
846 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
847 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
848 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
849 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
850 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
851 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
852 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
853 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
854 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
857 /* Page selector block. Following code computes page links. */
858 if ($pg_sel && ($num_msgs > $show_num)) {
859 /* Most importantly, what is the current page!!! */
860 $cur_pg = intval($start_msg / $show_num) +
1;
862 /* Compute total # of pages and # of paginator page links. */
863 $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
864 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
866 /* Compute the size of the four quarters of the page links. */
868 /* If we can, just show all the pages. */
869 if (($tot_pgs - 1) <= $pg_max) {
870 $q1_pgs = $cur_pg - 1;
871 $q2_pgs = $q3_pgs = 0;
872 $q4_pgs = $tot_pgs - $cur_pg;
874 /* Otherwise, compute some magic to choose the four quarters. */
877 * Compute the magic base values. Added together,
878 * these values will always equal to the $pag_pgs.
879 * NOTE: These are DEFAULT values and do not take
880 * the current page into account. That is below.
882 $q1_pgs = floor($vis_pgs/4);
883 $q2_pgs = round($vis_pgs/4, 0);
884 $q3_pgs = ceil($vis_pgs/4);
885 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
887 /* Adjust if the first quarter contains the current page. */
888 if (($cur_pg - $q1_pgs) < 1) {
889 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) +
$q2_pgs;
890 $q1_pgs = $cur_pg - 1;
892 $q3_pgs +
= ceil($extra_pgs / 2);
893 $q4_pgs +
= floor($extra_pgs / 2);
895 /* Adjust if the first and second quarters intersect. */
896 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
897 $extra_pgs = $q2_pgs;
898 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
899 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
900 $q3_pgs +
= ceil($extra_pgs / 2);
901 $q4_pgs +
= floor($extra_pgs / 2);
903 /* Adjust if the fourth quarter contains the current page. */
904 } else if (($cur_pg +
$q4_pgs) >= $tot_pgs) {
905 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) +
$q3_pgs;
907 $q4_pgs = $tot_pgs - $cur_pg;
908 $q1_pgs +
= floor($extra_pgs / 2);
909 $q2_pgs +
= ceil($extra_pgs / 2);
911 /* Adjust if the third and fourth quarter intersect. */
912 } else if (($cur_pg +
$q3_pgs +
1) >= ($tot_pgs - $q4_pgs +
1)) {
913 $extra_pgs = $q3_pgs;
914 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
915 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
916 $q1_pgs +
= floor($extra_pgs / 2);
917 $q2_pgs +
= ceil($extra_pgs / 2);
922 * I am leaving this debug code here, commented out, because
923 * it is a really nice way to see what the above code is doing.
924 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
925 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
928 /* Print out the page links from the compute page quarters. */
930 /* Start with the first quarter. */
931 if (($q1_pgs == 0) && ($cur_pg > 1)) {
932 $pg_str .= "...$spc";
934 for ($pg = 1; $pg <= $q1_pgs; ++
$pg) {
935 $start = (($pg-1) * $show_num) +
1;
936 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
938 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
939 $pg_str .= "...$spc";
943 /* Continue with the second quarter. */
944 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++
$pg) {
945 $start = (($pg-1) * $show_num) +
1;
946 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
949 /* Now print the current page. */
950 $pg_str .= $cur_pg . $spc;
952 /* Next comes the third quarter. */
953 for ($pg = $cur_pg +
1; $pg <= $cur_pg +
$q3_pgs; ++
$pg) {
954 $start = (($pg-1) * $show_num) +
1;
955 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
958 /* And last, print the forth quarter page links. */
959 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
960 $pg_str .= "...$spc";
962 if (($tot_pgs - $q4_pgs) > ($cur_pg +
$q3_pgs)) {
963 $pg_str .= "...$spc";
965 for ($pg = $tot_pgs - $q4_pgs +
1; $pg <= $tot_pgs; ++
$pg) {
966 $start = (($pg-1) * $show_num) +
1;
967 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
970 } else if ($PG_SHOWNUM == 999999) {
971 $pg_str = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
972 . "&startMessage=1&mailbox=$box\" TARGET=\"right\">"
973 . _("Paginate") . '</A>' . $spc;
976 /* If necessary, compute the 'show all' string. */
977 if (($prv_str != '') ||
($nxt_str != '')) {
978 $all_str = "<A HREF=\"right_main.php?PG_SHOWNUM=999999"
979 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
980 . "TARGET=\"right\">" . _("Show All") . '</A>';
983 /* Last but not least, get the value for the toggle all link. */
984 $tgl_str = get_selectall_link($start_msg, $sort);
986 /* Put all the pieces of the paginator string together. */
988 * Hairy code... But let's leave it like it is since I am not certain
989 * a different approach would be any easier to read. ;)
992 $result .= ($prv_str != '' ?
$prv_str . $spc . $sep . $spc : '');
993 $result .= ($nxt_str != '' ?
$nxt_str . $spc . $sep . $spc : '');
994 $result .= ($pg_str != '' ?
$pg_str : '');
995 $result .= ($all_str != '' ?
$sep . $spc . $all_str . $spc : '');
996 $result .= ($result != '' ?
$sep . $spc . $tgl_str: $tgl_str);
998 /* If the resulting string is blank, return a non-breaking space. */
1003 /* Return our final magical paginator string. */
1007 function processSubject($subject) {
1008 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1010 return _("(no subject)");
1012 if (strlen($subject) <= 55)
1015 $ent_strlen=strlen($subject);
1019 * see if this is entities-encoded string
1020 * If so, Iterate through the whole string, find out
1021 * the real number of characters, and if more
1022 * than 55, substr with an updated trim value.
1024 while ( (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1025 (($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false) ) {
1026 $trim_val +
= ($ent_loc_end-$ent_loc)+
1;
1027 $ent_strlen -= $ent_loc_end-$ent_loc;
1028 $ent_offset = $ent_loc_end+
1;
1031 if ($ent_strlen <= 55){
1035 return substr($subject, 0, $trim_val) . '...';
1038 function handleAsSent($mailbox) {
1039 global $sent_folder, $draft_folder, $handleAsSent_result;
1041 /* First check if this is the sent or draft folder. */
1042 $handleAsSent_result = (($mailbox == $sent_folder)
1043 ||
($mailbox == $draft_folder));
1045 /* Then check the result of the handleAsSent hook. */
1046 do_hook('check_handleAsSent_result', $mailbox);
1048 /* And return the result. */
1049 return ($handleAsSent_result);