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']);
44 for( $index = 0 ; $index < count($sendersName) ; $index++
) {
45 if( strlen($senderName) > 0 )
47 $senderName .= sqimap_find_displayable_name($sendersName[$index]);
50 if( $mailbox == 'None' ) {
51 // $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
52 $boxes = sqimap_mailbox_list($imapConnection);
53 // sqimap_logout($imapConnection);
54 $mailbox = $boxes[0]['unformatted'];
57 $urlMailbox = urlencode($mailbox);
58 $subject = processSubject($msg['SUBJECT']);
61 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
62 $flag = "<font color=\"$color[2]\">";
63 $flag_end = '</font>';
68 if (!isset($msg['FLAG_SEEN']) ||
($msg['FLAG_SEEN'] == false)) {
76 if (handleAsSent($mailbox)) {
84 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
85 $fontstr = "<font color=\"$color[9]\">";
86 $fontstr_end = '</font>';
92 for ($i=0; $i < count($message_highlight_list); $i++
) {
93 if (trim($message_highlight_list[$i]['value']) != '') {
94 if ($message_highlight_list[$i]['match_type'] == 'to_cc') {
95 if (strpos('^^'.strtolower($msg['TO']), strtolower($message_highlight_list[$i]['value'])) ||
strpos('^^'.strtolower($msg['CC']), strtolower($message_highlight_list[$i]['value']))) {
96 $hlt_color = $message_highlight_list[$i]['color'];
99 } else if (strpos('^^'.strtolower($msg[strtoupper($message_highlight_list[$i]['match_type'])]),strtolower($message_highlight_list[$i]['value']))) {
100 $hlt_color = $message_highlight_list[$i]['color'];
106 if (!isset($hlt_color)) {
107 $hlt_color = $color_string;
110 if ($where && $what) {
111 if( !isset( $pos ) ||
$pos == '' ) {
114 $search_stuff = "&pos=" . urlencode( $pos ) . "&where=".urlencode($where).'&what='.urlencode($what);
117 $checked = ($checkall == 1 ?
' checked' : '');
119 for ($i=1; $i <= count($index_order); $i++
) {
120 switch ($index_order[$i]) {
121 case 1: /* checkbox */
122 echo " <td bgcolor=\"$hlt_color\" align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."$checked></TD>\n";
125 echo " <td bgcolor=\"$hlt_color\">$italic$bold$flag$fontstr$senderName$fontstr_end$flag_end$bold_end$italic_end</td>\n";
128 echo " <td nowrap bgcolor=\"$hlt_color\"><center>$bold$flag$fontstr".$msg["DATE_STRING"]."$fontstr_end$flag_end$bold_end</center></td>\n";
130 case 4: /* subject */
131 echo " <td bgcolor=\"$hlt_color\">$bold";
132 if (! isset($search_stuff)) { $search_stuff = ''; }
133 echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=".$msg["ID"]."&startMessage=$start_msg&show_more=0$search_stuff\"";
134 do_hook("subject_link");
136 if ($subject != $msg['SUBJECT']) {
137 $title = get_html_translation_table(HTML_SPECIALCHARS
);
138 $title = array_flip($title);
139 $title = strtr($msg['SUBJECT'], $title);
140 $title = str_replace('"', "''", $title);
141 echo " title=\"$title\"";
143 echo ">$flag$subject$flag_end</a>$bold_end</td>\n";
147 echo " <td bgcolor=\"$hlt_color\" align=center nowrap><b><small>\n";
148 if (isset($msg['FLAG_ANSWERED']) &&
149 $msg['FLAG_ANSWERED'] == true) {
153 if ($msg['TYPE0'] == 'multipart') {
157 if ($default_use_priority) {
158 if (ereg('(1|2)',substr($msg['PRIORITY'],0,1))) {
159 echo "<font color=\"$color[1]\">!</font>\n";
162 if (ereg('(5)',substr($msg['PRIORITY'],0,1))) {
163 echo "<font color=\"$color[8]\">?</font>\n";
167 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
168 echo "<font color=\"$color[1]\">D</font>\n";
175 echo "</small></b></td>\n";
178 echo " <td bgcolor=\"$hlt_color\">$bold$fontstr" .
179 show_readable_size($msg['SIZE']) .
180 "$fontstr_end$bold_end</td>\n";
188 * This function loops through a group of messages in the mailbox
189 * and shows them to the user.
191 function showMessagesForMailbox
192 ($imapConnection, $mailbox, $num_msgs, $start_msg, $sort,
193 $color, $show_num, $use_cache) {
194 global $msgs, $msort;
195 global $sent_folder, $draft_folder;
196 global $message_highlight_list;
197 global $auto_expunge;
199 /* If autoexpunge is turned on, then do it now. */
200 if ($auto_expunge == true) {
201 sqimap_mailbox_expunge($imapConnection, $mailbox, false);
203 sqimap_mailbox_select($imapConnection, $mailbox);
205 $issent = handleAsSent($mailbox);
207 /* If it is sorted... */
208 if ($num_msgs >= 1) {
210 $id = range(1, $num_msgs);
212 // if it's not sorted
213 if ($start_msg +
($show_num - 1) < $num_msgs) {
214 $end_msg = $start_msg +
($show_num-1);
216 $end_msg = $num_msgs;
219 if ($end_msg < $start_msg) {
220 $start_msg = $start_msg - $show_num;
221 if ($start_msg < 1) {
226 $real_startMessage = $num_msgs - $start_msg +
1;
227 $real_endMessage = $num_msgs - $start_msg - $show_num +
2;
228 if ($real_endMessage <= 0) {
229 $real_endMessage = 1;
231 $id = array_reverse(range($real_endMessage, $real_startMessage));
234 $msgs_list = sqimap_get_small_header_list($imapConnection, $id, $issent);
235 $flags = sqimap_get_flags_list($imapConnection, $id, $issent);
236 foreach ($msgs_list as $hdr) {
237 $from[] = $hdr->from
;
238 $date[] = $hdr->date
;
239 $subject[] = $hdr->subject
;
241 $priority[] = $hdr->priority
;
243 $size[] = $hdr->size
;
244 $type[] = $hdr->type0
;
250 $end = $start_msg +
$show_num - 1;
251 if ($num_msgs < $show_num) {
252 $end_loop = $num_msgs;
253 } else if ($end > $num_msgs) {
254 $end_loop = $num_msgs - $start_msg +
1;
256 $end_loop = $show_num;
263 while ($j < $end_loop) {
264 if (isset($date[$j])) {
265 $date[$j] = ereg_replace(' ', ' ', $date[$j]);
266 $tmpdate = explode(' ', trim($date[$j]));
268 $tmpdate = $date = array('', '', '', '', '', '');
271 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
272 $messages[$j]['DATE_STRING'] = getDateString($messages[$j]['TIME_STAMP']);
273 $messages[$j]['ID'] = $id[$j];
274 $messages[$j]['FROM'] = decodeHeader($from[$j]);
275 $messages[$j]['FROM-SORT'] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
276 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
277 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
278 $messages[$j]['TO'] = decodeHeader($to[$j]);
279 $messages[$j]['PRIORITY'] = $priority[$j];
280 $messages[$j]['CC'] = $cc[$j];
281 $messages[$j]['SIZE'] = $size[$j];
282 $messages[$j]['TYPE0'] = $type[$j];
284 # fix SUBJECT-SORT to remove Re:
285 $re_abbr = /* Add more here! */
286 'vedr|sv|' . /* Danish */
287 're|aw'; /* English */
289 if (eregi( "^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs)) {
290 $messages[$j]['SUBJECT-SORT'] = $regs[2];
294 while ($num < count($flags[$j])) {
295 if ($flags[$j][$num] == 'Deleted') {
296 $messages[$j]['FLAG_DELETED'] = true;
297 } else if ($flags[$j][$num] == 'Answered') {
298 $messages[$j]['FLAG_ANSWERED'] = true;
299 } else if ($flags[$j][$num] == 'Seen') {
300 $messages[$j]['FLAG_SEEN'] = true;
301 } else if ($flags[$j][$num] == 'Flagged') {
302 $messages[$j]['FLAG_FLAGGED'] = true;
309 /* Only ignore messages flagged as deleted if we are using a
310 * trash folder or auto_expunge */
311 if (((isset($move_to_trash) && $move_to_trash)
312 ||
(isset($auto_expunge) && $auto_expunge)) && $sort != 6) {
314 /** Find and remove the ones that are deleted */
318 while ($j < $num_msgs) {
319 if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED'] == true) {
323 $msgs[$i] = $messages[$j];
330 if (!isset($messages)) {
337 // There's gotta be messages in the array for it to sort them.
338 if ($num_msgs > 0 && ! $use_cache) {
339 /** 0 = Date (up) 4 = Subject (up)
340 ** 1 = Date (dn) 5 = Subject (dn)
344 session_unregister("msgs");
345 if (($sort == 0) ||
($sort == 1))
346 $msort = array_cleave ($msgs, 'TIME_STAMP');
347 elseif (($sort == 2) ||
($sort == 3))
348 $msort = array_cleave ($msgs, 'FROM-SORT');
349 elseif (($sort == 4) ||
($sort == 5))
350 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
361 session_register('msort');
363 displayMessageArray($imapConnection, $num_msgs, $start_msg, $msgs, $msort, $mailbox, $sort, $color,$show_num);
364 session_register('msgs');
368 * Generic function to convert the msgs array into an HTML table.
370 function displayMessageArray($imapConnection, $num_msgs, $start_msg, &$msgs, $msort, $mailbox, $sort, $color, $show_num) {
371 global $folder_prefix, $sent_folder;
372 global $imapServerAddress, $data_dir, $username, $use_mailbox_cache;
373 global $index_order, $real_endMessage, $real_startMessage, $checkall;
375 /* If cache isn't already set, do it now. */
376 if (!session_is_registered('msgs')) { session_register('msgs'); }
377 if (!session_is_registered('msort')) { session_register('msort'); }
379 if ($start_msg +
($show_num - 1) < $num_msgs) {
380 $end_msg = $start_msg +
($show_num-1);
382 $end_msg = $num_msgs;
385 if ($end_msg < $start_msg) {
386 $start_msg = $start_msg - $show_num;
387 if ($start_msg < 1) { $start_msg = 1; }
390 $urlMailbox = urlencode($mailbox);
392 do_hook('mailbox_index_before');
394 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
395 $paginator_str = get_paginator_str
396 ($urlMailbox, $start_msg, $end_msg, $num_msgs, $show_num, $sort);
402 mail_message_listing_beginning( $imapConnection,
403 "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$start_msg",
404 $mailbox, $sort, $msg_cnt_str, $paginator_str, $start_msg);
406 $groupNum = $start_msg %
($show_num - 1);
407 $real_startMessage = $start_msg;
409 if ($end_msg - $start_msg < $show_num - 1) {
410 $end_msg = $end_msg - $start_msg +
1;
412 } else if ($start_msg > $show_num) {
413 $end_msg = $show_num;
417 $endVar = $end_msg +
1;
419 /* Loop through and display the info for each message. */
420 $t = 0; // $t is used for the checkbox number
421 if ($num_msgs == 0) { // if there's no messages in this folder
422 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=" . count($index_order) . ">\n".
423 " <CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR> </CENTER>\n".
425 } elseif ($start_msg == $end_msg) {
426 /* If there's only one message in the box, handle it differently. */
439 } while (isset ($key) && ($k < $i));
440 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
450 } while (isset ($key) && ($k < $i));
453 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
458 } while ($i && $i < $endVar);
462 "<table bgcolor=\"$color[9]\" width=\"100%\" border=0 cellpadding=1 cellspacing=1>" .
463 "<tr BGCOLOR=\"$color[4]\"><td>" .
464 "<table width=\"100%\" BGCOLOR=\"$color[4]\" border=0 cellpadding=1 cellspacing=0><tr><td>$paginator_str</td>".
465 "<td align=right>$msg_cnt_str</td></tr></table>".
468 /** End of message-list table */
470 do_hook('mailbox_index_after');
471 echo "</TABLE></FORM>\n";
475 * Displays the standard message list header. To finish the table,
476 * you need to do a "</table></table>";
478 * $moveURL is the URL to submit the delete/move form to
479 * $mailbox is the current mailbox
480 * $sort is the current sorting method (-1 for no sorting available [searches])
481 * $Message is a message that is centered on top of the list
482 * $More is a second line that is left aligned
484 function mail_message_listing_beginning
485 ($imapConnection, $moveURL, $mailbox = '', $sort = -1,
486 $msg_cnt_str = '', $paginator = ' ', $start_msg = 1) {
487 global $color, $index_order, $auto_expunge, $move_to_trash;
488 global $checkall, $sent_folder, $draft_folder;
489 $urlMailbox = urlencode($mailbox);
492 * This is the beginning of the message list table.
493 * It wraps around all messages
495 echo "<FORM name=messageList method=post action=\"$moveURL\">\n"
496 . "<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLPADDING=\"1\" CELLSPACING=\"0\">\n"
497 . "<TR BGCOLOR=\"$color[0]\"><TD>"
498 . " <TABLE BGCOLOR=\"$color[4]\" width=\"100%\" CELLPADDING=\"2\" CELLSPACING=\"0\" BORDER=\"0\"><TR>\n"
499 . " <TD ALIGN=LEFT>$paginator</TD>\n"
500 . " <TD ALIGN=RIGHT>$msg_cnt_str</TD>\n"
503 . "<TR><TD BGCOLOR=\"$color[0]\">\n"
504 . "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=\"100%\">\n"
506 . " <TD ALIGN=LEFT VALIGN=MIDDLE NOWRAP>\n"
507 . ' <SMALL> ' . _("Move Selected To:") . "</SMALL>\n"
509 . " <TD ALIGN=RIGHT NOWRAP>\n"
510 . ' <SMALL> ' . _("Transform Selected Messages") . ": </SMALL><BR>\n"
514 . " <TD ALIGN=LEFT VALIGN=MIDDLE NOWRAP>\n"
515 . ' <SMALL> <TT><SELECT NAME="targetMailbox">';
517 $boxes = sqimap_mailbox_list($imapConnection);
518 for ($i = 0; $i < count($boxes); $i++
) {
519 if (!in_array("noselect", $boxes[$i]['flags'])) {
520 $box = $boxes[$i]['unformatted'];
521 $box2 = str_replace(' ', ' ', $boxes[$i]['unformatted-disp']);
522 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
525 echo ' </SELECT></TT> '.
526 "<INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"" . _("Move") . "\"></SMALL>\n".
528 " <TD ALIGN=RIGHT NOWRAP> \n";
529 if (!$auto_expunge) {
530 echo ' <INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'"> '. _("mailbox") ." \n";
532 echo " <INPUT TYPE=SUBMIT NAME=\"markRead\" VALUE=\"". _("Read")."\">\n".
533 " <INPUT TYPE=SUBMIT NAME=\"markUnread\" VALUE=\"". _("Unread")."\">\n".
534 " <INPUT TYPE=SUBMIT VALUE=\"". _("Delete") . "\"> \n".
538 do_hook('mailbox_form_before');
541 "<TR><TD BGCOLOR=\"$color[0]\">".
542 "<TABLE WIDTH=\"100%\" BORDER=0 CELLPADDING=2 CELLSPACING=";
543 if ($GLOBALS['alt_index_colors']) {
548 echo " BGCOLOR=\"$color[0]\">".
549 "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
551 /* Print the headers. */
552 for ($i=1; $i <= count($index_order); $i++
) {
553 switch ($index_order[$i]) {
554 case 1: /* checkbox */
556 echo ' <TD WIDTH="1%"><B> </B></TD>';
560 if (handleAsSent($mailbox)) {
561 echo ' <TD WIDTH="25%"><B>'. _("To") .'</B>';
563 echo ' <TD WIDTH="25%"><B>'. _("From") .'</B>';
566 ShowSortButton($sort, $mailbox, 2, 3);
571 echo ' <TD NOWRAP WIDTH="5%"><B>'. _("Date") .'</B>';
572 ShowSortButton($sort, $mailbox, 0, 1);
576 case 4: /* subject */
577 echo ' <TD><B>'. _("Subject") .'</B> ';
578 ShowSortButton($sort, $mailbox, 4, 5);
583 echo ' <TD WIDTH="5%"><b>' . _("Size")."</b></TD>\n";
591 * This function shows the sort button. Isn't this a good comment?
593 function ShowSortButton($sort, $mailbox, $Up, $Down) {
594 /* Figure out which image we want to use. */
595 if ($sort != $Up && $sort != $Down) {
596 $img = 'sort_none.png';
598 } elseif ($sort == $Up) {
599 $img = 'up_pointer.png';
602 $img = 'down_pointer.png';
606 /* Now that we have everything figured out, show the actual button. */
607 echo ' <a href="right_main.php?newsort=' . $which .
608 '&startMessage=1&mailbox=' . urlencode($mailbox) .
609 '"><IMG SRC="../images/' . $img .
610 '" BORDER=0 WIDTH=12 HEIGHT=10></a>';
613 function get_selectall_link($start_msg, $sort) {
614 global $checkall, $what, $where, $mailbox, $javascript_on;
615 global $PHP_SELF, $PG_SHOWNUM;
617 if ($javascript_on) {
619 '<script language="JavaScript">' .
621 "function CheckAll() {\n" .
622 " for (var i = 0; i < document.messageList.elements.length; i++) {\n" .
623 " if( document.messageList.elements[i].type == 'checkbox' ) {\n" .
624 " document.messageList.elements[i].checked = !(document.messageList.elements[i].checked);\n".
629 '</script><a href="#" onClick="CheckAll();">' . _("Toggle All") . "</a>\n";
631 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
632 . "&startMessage=$start_msg&sort=$sort&checkall=";
633 if (isset($checkall) && $checkall == '1') {
639 if (isset($where) && isset($what)) {
640 $result .= '&where=' . urlencode($where)
641 . '&what=' . urlencode($what);
644 if ($PG_SHOWNUM == 999999) {
645 $result .= '&PG_SHOWNUM=999999';
650 if (isset($checkall) && ($checkall == '1')) {
651 $result .= _("Unselect All");
653 $result .= _("Select All");
659 /* Return our final result. */
664 * This function computes the "Viewing Messages..." string.
666 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
667 /* Compute the $msg_cnt_str. */
669 if ($start_msg < $end_msg) {
670 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"), $start_msg, $end_msg, $num_msgs);
671 } else if ($start_msg == $end_msg) {
672 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
677 /* Return our result string. */
682 * Generate a paginator link.
684 function get_paginator_link
685 ($box, $start_msg, $use, $text) {
686 $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
687 . "&startMessage=$start_msg&mailbox=$box\" "
688 . "TARGET=\"right\">$text</A>";
693 * This function computes the paginator string.
695 function get_paginator_str
696 ($box, $start_msg, $end_msg, $num_msgs, $show_num, $sort) {
697 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
699 /* Initialize paginator string chunks. */
706 /* Create simple strings that will be creating the paginator. */
707 $spc = ' '; /* This will be used as a space. */
708 $sep = '|'; /* This will be used as a seperator. */
710 /* Get some paginator preference values. */
711 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON
);
712 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
);
714 /* Make sure that our start message number is not too big. */
715 $start_msg = min($start_msg, $num_msgs);
717 /* Decide whether or not we will use the mailbox cache. */
718 /* Not sure why $use_mailbox_cache is even passed in. */
725 /* Compute the starting message of the previous and next page group. */
726 $next_grp = $start_msg +
$show_num;
727 $prev_grp = $start_msg - $show_num;
729 /* Compute the basic previous and next strings. */
730 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
731 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
732 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
733 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
734 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
735 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
736 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
737 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
738 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
741 /* Page selector block. Following code computes page links. */
742 if ($pg_sel && ($num_msgs > $show_num)) {
743 /* Most importantly, what is the current page!!! */
744 $cur_pg = intval($start_msg / $show_num) +
1;
746 /* Compute total # of pages and # of paginator page links. */
747 $tot_pgs = ceil($num_msgs / $show_num); /* Total # of Pages */
748 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
750 /************************************************************/
751 /* Compute the size of the four quarters of the page links. */
752 /************************************************************/
754 /* If we can, just show all the pages. */
755 if (($tot_pgs - 1) <= $pg_max) {
756 $q1_pgs = $cur_pg - 1;
757 $q2_pgs = $q3_pgs = 0;
758 $q4_pgs = $tot_pgs - $cur_pg;
760 /* Otherwise, compute some magic to choose the four quarters. */
762 /* Compute the magic base values. Added together, */
763 /* these values will always equal to the $pag_pgs. */
764 /* NOTE: These are DEFAULT values and do not take */
765 /* the current page into account. That is below. */
766 $q1_pgs = floor($vis_pgs/4);
767 $q2_pgs = round($vis_pgs/4, 0);
768 $q3_pgs = ceil($vis_pgs/4);
769 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
771 /* Adjust if the first quarter contains the current page. */
772 if (($cur_pg - $q1_pgs) < 1) {
773 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) +
$q2_pgs;
774 $q1_pgs = $cur_pg - 1;
776 $q3_pgs +
= ceil($extra_pgs / 2);
777 $q4_pgs +
= floor($extra_pgs / 2);
779 /* Adjust if the first and second quarters intersect. */
780 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
781 $extra_pgs = $q2_pgs;
782 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
783 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
784 $q3_pgs +
= ceil($extra_pgs / 2);
785 $q4_pgs +
= floor($extra_pgs / 2);
787 /* Adjust if the fourth quarter contains the current page. */
788 } else if (($cur_pg +
$q4_pgs) >= $tot_pgs) {
789 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) +
$q3_pgs;
791 $q4_pgs = $tot_pgs - $cur_pg;
792 $q1_pgs +
= floor($extra_pgs / 2);
793 $q2_pgs +
= ceil($extra_pgs / 2);
795 /* Adjust if the third and fourth quarter intersect. */
796 } else if (($cur_pg +
$q3_pgs +
1) >= ($tot_pgs - $q4_pgs +
1)) {
797 $extra_pgs = $q3_pgs;
798 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
799 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
800 $q1_pgs +
= floor($extra_pgs / 2);
801 $q2_pgs +
= ceil($extra_pgs / 2);
805 /* I am leaving this debug code here, commented out, because */
806 /* it is a really nice way to see what the above code is doing. */
807 /* echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = " */
808 /* . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>'; */
810 /************************************************************/
811 /* Print out the page links from the compute page quarters. */
812 /************************************************************/
814 /* Start with the first quarter. */
815 if (($q1_pgs == 0) && ($cur_pg > 1)) {
816 $pg_str .= "...$spc";
818 for ($pg = 1; $pg <= $q1_pgs; ++
$pg) {
819 $start = (($pg-1) * $show_num) +
1;
820 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
822 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
823 $pg_str .= "...$spc";
827 /* Continue with the second quarter. */
828 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++
$pg) {
829 $start = (($pg-1) * $show_num) +
1;
830 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
833 /* Now print the current page. */
834 $pg_str .= $cur_pg . $spc;
836 /* Next comes the third quarter. */
837 for ($pg = $cur_pg +
1; $pg <= $cur_pg +
$q3_pgs; ++
$pg) {
838 $start = (($pg-1) * $show_num) +
1;
839 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
842 /* And last, print the forth quarter page links. */
843 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
844 $pg_str .= "...$spc";
846 if (($tot_pgs - $q4_pgs) > ($cur_pg +
$q3_pgs)) {
847 $pg_str .= "...$spc";
849 for ($pg = $tot_pgs - $q4_pgs +
1; $pg <= $tot_pgs; ++
$pg) {
850 $start = (($pg-1) * $show_num) +
1;
851 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
854 } else if ($PG_SHOWNUM == 999999) {
855 $pg_str = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
856 . "&startMessage=1&mailbox=$box\" TARGET=\"right\">"
857 . _("Paginate") . '</A>' . $spc;
860 /* If necessary, compute the 'show all' string. */
861 if (($prv_str != '') ||
($nxt_str != '')) {
862 $all_str = "<A HREF=\"right_main.php?PG_SHOWNUM=999999"
863 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
864 . "TARGET=\"right\">" . _("Show All") . '</A>';
867 /* Last but not least, get the value for the toggle all link. */
868 $tgl_str = get_selectall_link($start_msg, $sort);
870 /* Put all the pieces of the paginator string together. */
872 $result .= ($prv_str != '' ?
$prv_str . $spc . $sep . $spc : '');
873 $result .= ($nxt_str != '' ?
$nxt_str . $spc . $sep . $spc : '');
874 $result .= ($pg_str != '' ?
$pg_str : '');
875 $result .= ($all_str != '' ?
$sep . $spc . $all_str . $spc : '');
876 $result .= ($result != '' ?
$sep . $spc . $tgl_str: $tgl_str);
878 /* If the resulting string is blank, return a non-breaking space. */
883 /* Return our final magical paginator string. */
887 function processSubject($subject) {
888 // Shouldn't ever happen -- caught too many times in the IMAP functions
890 return _("(no subject)");
892 if (strlen($subject) <= 55)
895 $ent_strlen=strlen($subject);
898 // see if this is entities-encoded string
899 // If so, Iterate through the whole string, find out
900 // the real number of characters, and if more
901 // than 55, substr with an updated trim value.
902 while (($ent_loc = strpos($subject, '&', $ent_offset)) !== false &&
903 ($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false)
905 $trim_val +
= ($ent_loc_end-$ent_loc)+
1;
906 $ent_strlen -= $ent_loc_end-$ent_loc;
907 $ent_offset = $ent_loc_end+
1;
910 if ($ent_strlen <= 55)
913 return substr($subject, 0, $trim_val) . '...';
916 function handleAsSent($mailbox) {
917 global $sent_folder, $draft_folder;
918 global $handleAsSent_result;
920 /* First check if this is the sent or draft folder. */
921 $handleAsSent_result = (($mailbox == $sent_folder)
922 ||
($mailbox == $draft_folder));
924 /* Then check the result of the handleAsSent hook. */
925 do_hook('check_handleAsSent_result', $mailbox);
927 /* And return the result. */
928 return ($handleAsSent_result);