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 define('PG_SEL_MAX', 10); /* Default value for page_selector_max. */
17 function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $start_msg, $where, $what) {
19 global $color, $msgs, $msort;
20 global $sent_folder, $draft_folder;
21 global $default_use_priority;
22 global $message_highlight_list;
24 global $pos; /* Search postion (if any) */
26 $color_string = $color[4];
27 if ($GLOBALS['alt_index_colors']) {
28 if (!isset($GLOBALS["row_count"])) {
29 $GLOBALS["row_count"] = 0;
31 $GLOBALS["row_count"]++
;
32 if ($GLOBALS["row_count"] %
2) {
33 if (!isset($color[12])) $color[12] = '#EAEAEA';
34 $color_string = $color[12];
40 * This is done in case you're looking into Sent folders,
41 * because you can have multi receiver.
43 $sendersName = split(',', $msg['FROM']);
45 for ($index = 0 ; $index < count($sendersName) ; $index++
) {
46 if ($senderName != '') {
49 $senderName .= sqimap_find_displayable_name($sendersName[$index]);
52 if( $mailbox == 'None' ) {
53 // $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
54 $boxes = sqimap_mailbox_list($imapConnection);
55 // sqimap_logout($imapConnection);
56 $mailbox = $boxes[0]['unformatted'];
59 $urlMailbox = urlencode($mailbox);
60 $subject = processSubject($msg['SUBJECT']);
63 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
64 $flag = "<font color=\"$color[2]\">";
65 $flag_end = '</font>';
70 if (!isset($msg['FLAG_SEEN']) ||
($msg['FLAG_SEEN'] == false)) {
78 if (handleAsSent($mailbox)) {
86 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
87 $fontstr = "<font color=\"$color[9]\">";
88 $fontstr_end = '</font>';
94 for ($i=0; $i < count($message_highlight_list); $i++
) {
95 if (trim($message_highlight_list[$i]['value']) != '') {
96 if ($message_highlight_list[$i]['match_type'] == 'to_cc') {
97 if (strpos('^^'.strtolower($msg['TO']), strtolower($message_highlight_list[$i]['value'])) ||
strpos('^^'.strtolower($msg['CC']), strtolower($message_highlight_list[$i]['value']))) {
98 $hlt_color = $message_highlight_list[$i]['color'];
101 } else if (strpos('^^'.strtolower($msg[strtoupper($message_highlight_list[$i]['match_type'])]),strtolower($message_highlight_list[$i]['value']))) {
102 $hlt_color = $message_highlight_list[$i]['color'];
108 if (!isset($hlt_color)) {
109 $hlt_color = $color_string;
112 if ($where && $what) {
113 if( !isset( $pos ) ||
$pos == '' ) {
116 $search_stuff = "&pos=" . urlencode( $pos ) . "&where=".urlencode($where).'&what='.urlencode($what);
119 $checked = ($checkall == 1 ?
' checked' : '');
121 for ($i=1; $i <= count($index_order); $i++
) {
122 switch ($index_order[$i]) {
123 case 1: /* checkbox */
124 echo " <td bgcolor=\"$hlt_color\" align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."$checked></TD>\n";
127 echo " <td bgcolor=\"$hlt_color\">$italic$bold$flag$fontstr$senderName$fontstr_end$flag_end$bold_end$italic_end</td>\n";
130 echo " <td nowrap bgcolor=\"$hlt_color\"><center>$bold$flag$fontstr".$msg["DATE_STRING"]."$fontstr_end$flag_end$bold_end</center></td>\n";
132 case 4: /* subject */
133 echo " <td bgcolor=\"$hlt_color\">$bold";
134 if (! isset($search_stuff)) { $search_stuff = ''; }
135 echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=".$msg["ID"]."&startMessage=$start_msg&show_more=0$search_stuff\"";
136 do_hook("subject_link");
138 if ($subject != $msg['SUBJECT']) {
139 $title = get_html_translation_table(HTML_SPECIALCHARS
);
140 $title = array_flip($title);
141 $title = strtr($msg['SUBJECT'], $title);
142 $title = str_replace('"', "''", $title);
143 echo " title=\"$title\"";
145 echo ">$flag$subject$flag_end</a>$bold_end</td>\n";
149 echo " <td bgcolor=\"$hlt_color\" align=center nowrap><b><small>\n";
150 if (isset($msg['FLAG_ANSWERED']) &&
151 $msg['FLAG_ANSWERED'] == true) {
155 if ($msg['TYPE0'] == 'multipart') {
159 if ($default_use_priority) {
160 if (ereg('(1|2)',substr($msg['PRIORITY'],0,1))) {
161 echo "<font color=\"$color[1]\">!</font>\n";
164 if (ereg('(5)',substr($msg['PRIORITY'],0,1))) {
165 echo "<font color=\"$color[8]\">?</font>\n";
169 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
170 echo "<font color=\"$color[1]\">D</font>\n";
177 echo "</small></b></td>\n";
180 echo " <td bgcolor=\"$hlt_color\">$bold$fontstr" .
181 show_readable_size($msg['SIZE']) .
182 "$fontstr_end$bold_end</td>\n";
190 * This function loops through a group of messages in the mailbox
191 * and shows them to the user.
193 function showMessagesForMailbox
194 ($imapConnection, $mailbox, $num_msgs, $start_msg, $sort,
195 $color, $show_num, $use_cache) {
196 global $msgs, $msort;
197 global $sent_folder, $draft_folder;
198 global $message_highlight_list;
199 global $auto_expunge;
201 /* If autoexpunge is turned on, then do it now. */
202 if ($auto_expunge == true) {
203 sqimap_mailbox_expunge($imapConnection, $mailbox, false);
205 sqimap_mailbox_select($imapConnection, $mailbox);
207 $issent = handleAsSent($mailbox);
209 /* If it is sorted... */
210 if ($num_msgs >= 1) {
212 $id = range(1, $num_msgs);
214 // if it's not sorted
215 if ($start_msg +
($show_num - 1) < $num_msgs) {
216 $end_msg = $start_msg +
($show_num-1);
218 $end_msg = $num_msgs;
221 if ($end_msg < $start_msg) {
222 $start_msg = $start_msg - $show_num;
223 if ($start_msg < 1) {
228 $real_startMessage = $num_msgs - $start_msg +
1;
229 $real_endMessage = $num_msgs - $start_msg - $show_num +
2;
230 if ($real_endMessage <= 0) {
231 $real_endMessage = 1;
233 $id = array_reverse(range($real_endMessage, $real_startMessage));
236 $msgs_list = sqimap_get_small_header_list($imapConnection, $id, $issent);
237 $flags = sqimap_get_flags_list($imapConnection, $id, $issent);
238 foreach ($msgs_list as $hdr) {
239 $from[] = $hdr->from
;
240 $date[] = $hdr->date
;
241 $subject[] = $hdr->subject
;
243 $priority[] = $hdr->priority
;
245 $size[] = $hdr->size
;
246 $type[] = $hdr->type0
;
252 $end = $start_msg +
$show_num - 1;
253 if ($num_msgs < $show_num) {
254 $end_loop = $num_msgs;
255 } else if ($end > $num_msgs) {
256 $end_loop = $num_msgs - $start_msg +
1;
258 $end_loop = $show_num;
265 while ($j < $end_loop) {
266 if (isset($date[$j])) {
267 $date[$j] = ereg_replace(' ', ' ', $date[$j]);
268 $tmpdate = explode(' ', trim($date[$j]));
270 $tmpdate = $date = array('', '', '', '', '', '');
273 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
274 $messages[$j]['DATE_STRING'] = getDateString($messages[$j]['TIME_STAMP']);
275 $messages[$j]['ID'] = $id[$j];
276 $messages[$j]['FROM'] = decodeHeader($from[$j]);
277 $messages[$j]['FROM-SORT'] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
278 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
279 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
280 $messages[$j]['TO'] = decodeHeader($to[$j]);
281 $messages[$j]['PRIORITY'] = $priority[$j];
282 $messages[$j]['CC'] = $cc[$j];
283 $messages[$j]['SIZE'] = $size[$j];
284 $messages[$j]['TYPE0'] = $type[$j];
286 # fix SUBJECT-SORT to remove Re:
287 $re_abbr = /* Add more here! */
288 'vedr|sv|' . /* Danish */
289 're|aw'; /* English */
291 if (eregi( "^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs)) {
292 $messages[$j]['SUBJECT-SORT'] = $regs[2];
296 while ($num < count($flags[$j])) {
297 if ($flags[$j][$num] == 'Deleted') {
298 $messages[$j]['FLAG_DELETED'] = true;
299 } else if ($flags[$j][$num] == 'Answered') {
300 $messages[$j]['FLAG_ANSWERED'] = true;
301 } else if ($flags[$j][$num] == 'Seen') {
302 $messages[$j]['FLAG_SEEN'] = true;
303 } else if ($flags[$j][$num] == 'Flagged') {
304 $messages[$j]['FLAG_FLAGGED'] = true;
311 /* Only ignore messages flagged as deleted if we are using a
312 * trash folder or auto_expunge */
313 if (((isset($move_to_trash) && $move_to_trash)
314 ||
(isset($auto_expunge) && $auto_expunge)) && $sort != 6) {
316 /** Find and remove the ones that are deleted */
320 while ($j < $num_msgs) {
321 if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED'] == true) {
325 $msgs[$i] = $messages[$j];
332 if (!isset($messages)) {
339 // There's gotta be messages in the array for it to sort them.
340 if ($num_msgs > 0 && ! $use_cache) {
341 /** 0 = Date (up) 4 = Subject (up)
342 ** 1 = Date (dn) 5 = Subject (dn)
346 session_unregister("msgs");
347 if (($sort == 0) ||
($sort == 1))
348 $msort = array_cleave ($msgs, 'TIME_STAMP');
349 elseif (($sort == 2) ||
($sort == 3))
350 $msort = array_cleave ($msgs, 'FROM-SORT');
351 elseif (($sort == 4) ||
($sort == 5))
352 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
363 session_register('msort');
365 displayMessageArray($imapConnection, $num_msgs, $start_msg, $msgs, $msort, $mailbox, $sort, $color,$show_num);
366 session_register('msgs');
370 * Generic function to convert the msgs array into an HTML table.
372 function displayMessageArray($imapConnection, $num_msgs, $start_msg, &$msgs, $msort, $mailbox, $sort, $color, $show_num) {
373 global $folder_prefix, $sent_folder;
374 global $imapServerAddress, $data_dir, $username, $use_mailbox_cache;
375 global $index_order, $real_endMessage, $real_startMessage, $checkall;
377 /* If cache isn't already set, do it now. */
378 if (!session_is_registered('msgs')) { session_register('msgs'); }
379 if (!session_is_registered('msort')) { session_register('msort'); }
381 if ($start_msg +
($show_num - 1) < $num_msgs) {
382 $end_msg = $start_msg +
($show_num-1);
384 $end_msg = $num_msgs;
387 if ($end_msg < $start_msg) {
388 $start_msg = $start_msg - $show_num;
389 if ($start_msg < 1) { $start_msg = 1; }
392 $urlMailbox = urlencode($mailbox);
394 do_hook('mailbox_index_before');
396 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
397 $paginator_str = get_paginator_str
398 ($urlMailbox, $start_msg, $end_msg, $num_msgs, $show_num, $sort);
404 mail_message_listing_beginning( $imapConnection,
405 "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$start_msg",
406 $mailbox, $sort, $msg_cnt_str, $paginator_str, $start_msg);
408 $groupNum = $start_msg %
($show_num - 1);
409 $real_startMessage = $start_msg;
411 if ($end_msg - $start_msg < $show_num - 1) {
412 $end_msg = $end_msg - $start_msg +
1;
414 } else if ($start_msg > $show_num) {
415 $end_msg = $show_num;
419 $endVar = $end_msg +
1;
421 /* Loop through and display the info for each message. */
422 $t = 0; // $t is used for the checkbox number
423 if ($num_msgs == 0) { // if there's no messages in this folder
424 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=" . count($index_order) . ">\n".
425 " <CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR> </CENTER>\n".
427 } elseif ($start_msg == $end_msg) {
428 /* If there's only one message in the box, handle it differently. */
441 } while (isset ($key) && ($k < $i));
442 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
452 } while (isset ($key) && ($k < $i));
455 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
460 } while ($i && $i < $endVar);
464 "<table bgcolor=\"$color[9]\" width=\"100%\" border=0 cellpadding=1 cellspacing=1>" .
465 "<tr BGCOLOR=\"$color[4]\"><td>" .
466 "<table width=\"100%\" BGCOLOR=\"$color[4]\" border=0 cellpadding=1 cellspacing=0><tr><td>$paginator_str</td>".
467 "<td align=right>$msg_cnt_str</td></tr></table>".
470 /** End of message-list table */
472 do_hook('mailbox_index_after');
473 echo "</TABLE></FORM>\n";
477 * Displays the standard message list header. To finish the table,
478 * you need to do a "</table></table>";
480 * $moveURL is the URL to submit the delete/move form to
481 * $mailbox is the current mailbox
482 * $sort is the current sorting method (-1 for no sorting available [searches])
483 * $Message is a message that is centered on top of the list
484 * $More is a second line that is left aligned
486 function mail_message_listing_beginning
487 ($imapConnection, $moveURL, $mailbox = '', $sort = -1,
488 $msg_cnt_str = '', $paginator = ' ', $start_msg = 1) {
489 global $color, $index_order, $auto_expunge, $move_to_trash;
490 global $checkall, $sent_folder, $draft_folder;
491 $urlMailbox = urlencode($mailbox);
494 * This is the beginning of the message list table.
495 * It wraps around all messages
497 echo "<FORM name=messageList method=post action=\"$moveURL\">\n"
498 . "<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLPADDING=\"1\" CELLSPACING=\"0\">\n"
499 . "<TR BGCOLOR=\"$color[0]\"><TD>"
500 . " <TABLE BGCOLOR=\"$color[4]\" width=\"100%\" CELLPADDING=\"2\" CELLSPACING=\"0\" BORDER=\"0\"><TR>\n"
501 . " <TD ALIGN=LEFT>$paginator</TD>\n"
502 . " <TD ALIGN=RIGHT>$msg_cnt_str</TD>\n"
505 . "<TR><TD BGCOLOR=\"$color[0]\">\n"
506 . "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=\"100%\">\n"
508 . " <TD ALIGN=LEFT VALIGN=MIDDLE NOWRAP>\n"
509 . ' <SMALL> ' . _("Move Selected To:") . "</SMALL>\n"
511 . " <TD ALIGN=RIGHT NOWRAP>\n"
512 . ' <SMALL> ' . _("Transform Selected Messages") . ": </SMALL><BR>\n"
516 . " <TD ALIGN=LEFT VALIGN=MIDDLE NOWRAP>\n"
517 . ' <SMALL> <TT><SELECT NAME="targetMailbox">';
519 $boxes = sqimap_mailbox_list($imapConnection);
520 for ($i = 0; $i < count($boxes); $i++
) {
521 if (!in_array("noselect", $boxes[$i]['flags'])) {
522 $box = $boxes[$i]['unformatted'];
523 $box2 = str_replace(' ', ' ', $boxes[$i]['unformatted-disp']);
524 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
527 echo ' </SELECT></TT> '.
528 "<INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"" . _("Move") . "\"></SMALL>\n".
530 " <TD ALIGN=RIGHT NOWRAP> \n";
531 if (!$auto_expunge) {
532 echo ' <INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'"> '. _("mailbox") ." \n";
534 echo " <INPUT TYPE=SUBMIT NAME=\"markRead\" VALUE=\"". _("Read")."\">\n".
535 " <INPUT TYPE=SUBMIT NAME=\"markUnread\" VALUE=\"". _("Unread")."\">\n".
536 " <INPUT TYPE=SUBMIT VALUE=\"". _("Delete") . "\"> \n".
540 do_hook('mailbox_form_before');
543 "<TR><TD BGCOLOR=\"$color[0]\">".
544 "<TABLE WIDTH=\"100%\" BORDER=0 CELLPADDING=2 CELLSPACING=";
545 if ($GLOBALS['alt_index_colors']) {
550 echo " BGCOLOR=\"$color[0]\">".
551 "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
553 /* Print the headers. */
554 for ($i=1; $i <= count($index_order); $i++
) {
555 switch ($index_order[$i]) {
556 case 1: /* checkbox */
558 echo ' <TD WIDTH="1%"><B> </B></TD>';
562 if (handleAsSent($mailbox)) {
563 echo ' <TD WIDTH="25%"><B>'. _("To") .'</B>';
565 echo ' <TD WIDTH="25%"><B>'. _("From") .'</B>';
568 ShowSortButton($sort, $mailbox, 2, 3);
573 echo ' <TD NOWRAP WIDTH="5%"><B>'. _("Date") .'</B>';
574 ShowSortButton($sort, $mailbox, 0, 1);
578 case 4: /* subject */
579 echo ' <TD><B>'. _("Subject") .'</B> ';
580 ShowSortButton($sort, $mailbox, 4, 5);
585 echo ' <TD WIDTH="5%"><b>' . _("Size")."</b></TD>\n";
593 * This function shows the sort button. Isn't this a good comment?
595 function ShowSortButton($sort, $mailbox, $Up, $Down) {
596 /* Figure out which image we want to use. */
597 if ($sort != $Up && $sort != $Down) {
598 $img = 'sort_none.png';
600 } elseif ($sort == $Up) {
601 $img = 'up_pointer.png';
604 $img = 'down_pointer.png';
608 /* Now that we have everything figured out, show the actual button. */
609 echo ' <a href="right_main.php?newsort=' . $which .
610 '&startMessage=1&mailbox=' . urlencode($mailbox) .
611 '"><IMG SRC="../images/' . $img .
612 '" BORDER=0 WIDTH=12 HEIGHT=10></a>';
615 function get_selectall_link($start_msg, $sort) {
616 global $checkall, $what, $where, $mailbox, $javascript_on;
617 global $PHP_SELF, $PG_SHOWNUM;
619 if ($javascript_on) {
621 '<script language="JavaScript">' .
623 "function CheckAll() {\n" .
624 " for (var i = 0; i < document.messageList.elements.length; i++) {\n" .
625 " if( document.messageList.elements[i].type == 'checkbox' ) {\n" .
626 " document.messageList.elements[i].checked = !(document.messageList.elements[i].checked);\n".
631 '</script><a href="#" onClick="CheckAll();">' . _("Toggle All") . "</a>\n";
633 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
634 . "&startMessage=$start_msg&sort=$sort&checkall=";
635 if (isset($checkall) && $checkall == '1') {
641 if (isset($where) && isset($what)) {
642 $result .= '&where=' . urlencode($where)
643 . '&what=' . urlencode($what);
646 if ($PG_SHOWNUM == 999999) {
647 $result .= '&PG_SHOWNUM=999999';
652 if (isset($checkall) && ($checkall == '1')) {
653 $result .= _("Unselect All");
655 $result .= _("Select All");
661 /* Return our final result. */
666 * This function computes the "Viewing Messages..." string.
668 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
669 /* Compute the $msg_cnt_str. */
671 if ($start_msg < $end_msg) {
672 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"), $start_msg, $end_msg, $num_msgs);
673 } else if ($start_msg == $end_msg) {
674 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
679 /* Return our result string. */
684 * Generate a paginator link.
686 function get_paginator_link
687 ($box, $start_msg, $use, $text) {
688 $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
689 . "&startMessage=$start_msg&mailbox=$box\" "
690 . "TARGET=\"right\">$text</A>";
695 * This function computes the paginator string.
697 function get_paginator_str
698 ($box, $start_msg, $end_msg, $num_msgs, $show_num, $sort) {
699 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
701 /* Initialize paginator string chunks. */
708 /* Create simple strings that will be creating the paginator. */
709 $spc = ' '; /* This will be used as a space. */
710 $sep = '|'; /* This will be used as a seperator. */
712 /* Get some paginator preference values. */
713 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON
);
714 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
);
716 /* Make sure that our start message number is not too big. */
717 $start_msg = min($start_msg, $num_msgs);
719 /* Decide whether or not we will use the mailbox cache. */
720 /* Not sure why $use_mailbox_cache is even passed in. */
727 /* Compute the starting message of the previous and next page group. */
728 $next_grp = $start_msg +
$show_num;
729 $prev_grp = $start_msg - $show_num;
731 /* Compute the basic previous and next strings. */
732 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
733 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
734 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
735 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
736 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
737 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
738 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
739 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
740 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
743 /* Page selector block. Following code computes page links. */
744 if ($pg_sel && ($num_msgs > $show_num)) {
745 /* Most importantly, what is the current page!!! */
746 $cur_pg = intval($start_msg / $show_num) +
1;
748 /* Compute total # of pages and # of paginator page links. */
749 $tot_pgs = ceil($num_msgs / $show_num); /* Total # of Pages */
750 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
752 /************************************************************/
753 /* Compute the size of the four quarters of the page links. */
754 /************************************************************/
756 /* If we can, just show all the pages. */
757 if (($tot_pgs - 1) <= $pg_max) {
758 $q1_pgs = $cur_pg - 1;
759 $q2_pgs = $q3_pgs = 0;
760 $q4_pgs = $tot_pgs - $cur_pg;
762 /* Otherwise, compute some magic to choose the four quarters. */
764 /* Compute the magic base values. Added together, */
765 /* these values will always equal to the $pag_pgs. */
766 /* NOTE: These are DEFAULT values and do not take */
767 /* the current page into account. That is below. */
768 $q1_pgs = floor($vis_pgs/4);
769 $q2_pgs = round($vis_pgs/4, 0);
770 $q3_pgs = ceil($vis_pgs/4);
771 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
773 /* Adjust if the first quarter contains the current page. */
774 if (($cur_pg - $q1_pgs) < 1) {
775 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) +
$q2_pgs;
776 $q1_pgs = $cur_pg - 1;
778 $q3_pgs +
= ceil($extra_pgs / 2);
779 $q4_pgs +
= floor($extra_pgs / 2);
781 /* Adjust if the first and second quarters intersect. */
782 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
783 $extra_pgs = $q2_pgs;
784 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
785 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
786 $q3_pgs +
= ceil($extra_pgs / 2);
787 $q4_pgs +
= floor($extra_pgs / 2);
789 /* Adjust if the fourth quarter contains the current page. */
790 } else if (($cur_pg +
$q4_pgs) >= $tot_pgs) {
791 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) +
$q3_pgs;
793 $q4_pgs = $tot_pgs - $cur_pg;
794 $q1_pgs +
= floor($extra_pgs / 2);
795 $q2_pgs +
= ceil($extra_pgs / 2);
797 /* Adjust if the third and fourth quarter intersect. */
798 } else if (($cur_pg +
$q3_pgs +
1) >= ($tot_pgs - $q4_pgs +
1)) {
799 $extra_pgs = $q3_pgs;
800 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
801 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
802 $q1_pgs +
= floor($extra_pgs / 2);
803 $q2_pgs +
= ceil($extra_pgs / 2);
807 /* I am leaving this debug code here, commented out, because */
808 /* it is a really nice way to see what the above code is doing. */
809 /* echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = " */
810 /* . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>'; */
812 /************************************************************/
813 /* Print out the page links from the compute page quarters. */
814 /************************************************************/
816 /* Start with the first quarter. */
817 if (($q1_pgs == 0) && ($cur_pg > 1)) {
818 $pg_str .= "...$spc";
820 for ($pg = 1; $pg <= $q1_pgs; ++
$pg) {
821 $start = (($pg-1) * $show_num) +
1;
822 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
824 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
825 $pg_str .= "...$spc";
829 /* Continue with the second quarter. */
830 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++
$pg) {
831 $start = (($pg-1) * $show_num) +
1;
832 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
835 /* Now print the current page. */
836 $pg_str .= $cur_pg . $spc;
838 /* Next comes the third quarter. */
839 for ($pg = $cur_pg +
1; $pg <= $cur_pg +
$q3_pgs; ++
$pg) {
840 $start = (($pg-1) * $show_num) +
1;
841 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
844 /* And last, print the forth quarter page links. */
845 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
846 $pg_str .= "...$spc";
848 if (($tot_pgs - $q4_pgs) > ($cur_pg +
$q3_pgs)) {
849 $pg_str .= "...$spc";
851 for ($pg = $tot_pgs - $q4_pgs +
1; $pg <= $tot_pgs; ++
$pg) {
852 $start = (($pg-1) * $show_num) +
1;
853 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
856 } else if ($PG_SHOWNUM == 999999) {
857 $pg_str = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
858 . "&startMessage=1&mailbox=$box\" TARGET=\"right\">"
859 . _("Paginate") . '</A>' . $spc;
862 /* If necessary, compute the 'show all' string. */
863 if (($prv_str != '') ||
($nxt_str != '')) {
864 $all_str = "<A HREF=\"right_main.php?PG_SHOWNUM=999999"
865 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
866 . "TARGET=\"right\">" . _("Show All") . '</A>';
869 /* Last but not least, get the value for the toggle all link. */
870 $tgl_str = get_selectall_link($start_msg, $sort);
872 /* Put all the pieces of the paginator string together. */
874 $result .= ($prv_str != '' ?
$prv_str . $spc . $sep . $spc : '');
875 $result .= ($nxt_str != '' ?
$nxt_str . $spc . $sep . $spc : '');
876 $result .= ($pg_str != '' ?
$pg_str : '');
877 $result .= ($all_str != '' ?
$sep . $spc . $all_str . $spc : '');
878 $result .= ($result != '' ?
$sep . $spc . $tgl_str: $tgl_str);
880 /* If the resulting string is blank, return a non-breaking space. */
885 /* Return our final magical paginator string. */
889 function processSubject($subject) {
890 // Shouldn't ever happen -- caught too many times in the IMAP functions
892 return _("(no subject)");
894 if (strlen($subject) <= 55)
897 $ent_strlen=strlen($subject);
900 // see if this is entities-encoded string
901 // If so, Iterate through the whole string, find out
902 // the real number of characters, and if more
903 // than 55, substr with an updated trim value.
904 while (($ent_loc = strpos($subject, '&', $ent_offset)) !== false &&
905 ($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false)
907 $trim_val +
= ($ent_loc_end-$ent_loc)+
1;
908 $ent_strlen -= $ent_loc_end-$ent_loc;
909 $ent_offset = $ent_loc_end+
1;
912 if ($ent_strlen <= 55)
915 return substr($subject, 0, $trim_val) . '...';
918 function handleAsSent($mailbox) {
919 global $sent_folder, $draft_folder;
920 global $handleAsSent_result;
922 /* First check if this is the sent or draft folder. */
923 $handleAsSent_result = (($mailbox == $sent_folder)
924 ||
($mailbox == $draft_folder));
926 /* Then check the result of the handleAsSent hook. */
927 do_hook('check_handleAsSent_result', $mailbox);
929 /* And return the result. */
930 return ($handleAsSent_result);