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;
25 $color_string = $color[4];
26 if ($GLOBALS['alt_index_colors']) {
27 if (!isset($GLOBALS["row_count"])) {
28 $GLOBALS["row_count"] = 0;
30 $GLOBALS["row_count"]++
;
31 if ($GLOBALS["row_count"] %
2) {
32 if (!isset($color[12])) $color[12] = '#EAEAEA';
33 $color_string = $color[12];
38 $senderName = htmlspecialchars(sqimap_find_displayable_name($msg['FROM']));
39 if( $mailbox == 'None' ) {
40 // $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
41 $boxes = sqimap_mailbox_list($imapConnection);
42 // sqimap_logout($imapConnection);
43 $mailbox = $boxes[0]['unformatted'];
46 $urlMailbox = urlencode($mailbox);
47 $subject = processSubject($msg['SUBJECT']);
50 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
51 $flag = "<font color=$color[2]>";
52 $flag_end = '</font>';
57 if (!isset($msg['FLAG_SEEN']) ||
($msg['FLAG_SEEN'] == false)) {
65 if (handleAsSent($mailbox)) {
73 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
74 $fontstr = "<font color=\"$color[9]\">";
75 $fontstr_end = '</font>';
81 for ($i=0; $i < count($message_highlight_list); $i++
) {
82 if (trim($message_highlight_list[$i]['value']) != '') {
83 if ($message_highlight_list[$i]['match_type'] == 'to_cc') {
84 if (strpos('^^'.strtolower($msg['TO']), strtolower($message_highlight_list[$i]['value'])) ||
strpos('^^'.strtolower($msg['CC']), strtolower($message_highlight_list[$i]['value']))) {
85 $hlt_color = $message_highlight_list[$i]['color'];
88 } else if (strpos('^^'.strtolower($msg[strtoupper($message_highlight_list[$i]['match_type'])]),strtolower($message_highlight_list[$i]['value']))) {
89 $hlt_color = $message_highlight_list[$i]['color'];
95 if (!isset($hlt_color)) {
96 $hlt_color = $color_string;
99 if ($where && $what) {
100 $search_stuff = '&where='.urlencode($where).'&what='.urlencode($what);
103 $checked = ($checkall == 1 ?
' checked' : '');
105 for ($i=1; $i <= count($index_order); $i++
) {
106 switch ($index_order[$i]) {
107 case 1: /* checkbox */
108 echo " <td bgcolor=$hlt_color align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."$checked></TD>\n";
111 echo " <td bgcolor=$hlt_color>$italic$bold$flag$fontstr$senderName$fontstr_end$flag_end$bold_end$italic_end</td>\n";
114 echo " <td nowrap bgcolor=$hlt_color><center>$bold$flag$fontstr".$msg["DATE_STRING"]."$fontstr_end$flag_end$bold_end</center></td>\n";
116 case 4: /* subject */
117 echo " <td bgcolor=$hlt_color>$bold";
118 if (! isset($search_stuff)) { $search_stuff = ''; }
119 echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=".$msg["ID"]."&startMessage=$start_msg&show_more=0$search_stuff\"";
120 do_hook("subject_link");
122 if ($subject != $msg['SUBJECT']) {
123 $title = get_html_translation_table(HTML_SPECIALCHARS
);
124 $title = array_flip($title);
125 $title = strtr($msg['SUBJECT'], $title);
126 $title = str_replace('"', "''", $title);
127 echo " title=\"$title\"";
129 echo ">$flag$subject$flag_end</a>$bold_end</td>\n";
133 echo " <td bgcolor=$hlt_color align=center nowrap><b><small>\n";
134 if (isset($msg['FLAG_ANSWERED']) &&
135 $msg['FLAG_ANSWERED'] == true) {
139 if ($msg['TYPE0'] == 'multipart') {
143 if ($default_use_priority) {
144 if (ereg('(1|2)',substr($msg['PRIORITY'],0,1))) {
145 echo "<font color=$color[1]>!</font>\n";
148 if (ereg('(5)',substr($msg['PRIORITY'],0,1))) {
149 echo "<font color=$color[8]>?</font>\n";
153 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
154 echo "<font color=\"$color[1]\">D</font>\n";
161 echo "</small></b></td>\n";
164 echo " <td bgcolor=$hlt_color>$bold$fontstr" .
165 show_readable_size($msg['SIZE']) .
166 "$fontstr_end$bold_end</td>\n";
174 * This function loops through a group of messages in the mailbox
175 * and shows them to the user.
177 function showMessagesForMailbox
178 ($imapConnection, $mailbox, $num_msgs, $start_msg,
179 $sort, $color,$show_num, $use_cache) {
180 global $msgs, $msort;
181 global $sent_folder, $draft_folder;
182 global $message_highlight_list;
183 global $auto_expunge;
185 /* If autoexpunge is turned on, then do it now. */
186 if ($auto_expunge == true) {
187 sqimap_mailbox_expunge($imapConnection, $mailbox, false);
189 sqimap_mailbox_select($imapConnection, $mailbox);
191 $issent = handleAsSent($mailbox);
193 /* If it is sorted... */
194 if ($num_msgs >= 1) {
196 $id = range(1, $num_msgs);
198 // if it's not sorted
199 if ($start_msg +
($show_num - 1) < $num_msgs) {
200 $end_msg = $start_msg +
($show_num-1);
202 $end_msg = $num_msgs;
205 if ($end_msg < $start_msg) {
206 $start_msg = $start_msg - $show_num;
207 if ($start_msg < 1) {
212 $real_startMessage = $num_msgs - $start_msg +
1;
213 $real_endMessage = $num_msgs - $start_msg - $show_num +
2;
214 if ($real_endMessage <= 0) {
215 $real_endMessage = 1;
217 $id = array_reverse(range($real_endMessage, $real_startMessage));
220 $msgs_list = sqimap_get_small_header_list($imapConnection, $id, $issent);
221 $flags = sqimap_get_flags_list($imapConnection, $id, $issent);
222 foreach ($msgs_list as $hdr) {
223 $from[] = $hdr->from
;
224 $date[] = $hdr->date
;
225 $subject[] = $hdr->subject
;
227 $priority[] = $hdr->priority
;
229 $size[] = $hdr->size
;
230 $type[] = $hdr->type0
;
236 $end = $start_msg +
$show_num - 1;
237 if ($num_msgs < $show_num) {
238 $end_loop = $num_msgs;
239 } else if ($end > $num_msgs) {
240 $end_loop = $num_msgs - $start_msg +
1;
242 $end_loop = $show_num;
249 while ($j < $end_loop) {
250 if (isset($date[$j])) {
251 $date[$j] = ereg_replace(' ', ' ', $date[$j]);
252 $tmpdate = explode(' ', trim($date[$j]));
254 $tmpdate = $date = array('', '', '', '', '', '');
257 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
258 $messages[$j]['DATE_STRING'] = getDateString($messages[$j]['TIME_STAMP']);
259 $messages[$j]['ID'] = $id[$j];
260 $messages[$j]['FROM'] = decodeHeader($from[$j]);
261 $messages[$j]['FROM-SORT'] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
262 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
263 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
264 $messages[$j]['TO'] = decodeHeader($to[$j]);
265 $messages[$j]['PRIORITY'] = $priority[$j];
266 $messages[$j]['CC'] = $cc[$j];
267 $messages[$j]['SIZE'] = $size[$j];
268 $messages[$j]['TYPE0'] = $type[$j];
270 # fix SUBJECT-SORT to remove Re:
271 $re_abbr = /* Add more here! */
272 'vedr|sv|' . /* Danish */
273 're|aw'; /* English */
275 if (eregi( "^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs)) {
276 $messages[$j]['SUBJECT-SORT'] = $regs[2];
280 while ($num < count($flags[$j])) {
281 if ($flags[$j][$num] == 'Deleted') {
282 $messages[$j]['FLAG_DELETED'] = true;
283 } else if ($flags[$j][$num] == 'Answered') {
284 $messages[$j]['FLAG_ANSWERED'] = true;
285 } else if ($flags[$j][$num] == 'Seen') {
286 $messages[$j]['FLAG_SEEN'] = true;
287 } else if ($flags[$j][$num] == 'Flagged') {
288 $messages[$j]['FLAG_FLAGGED'] = true;
295 /* Only ignore messages flagged as deleted if we are using a
296 * trash folder or auto_expunge */
297 if (((isset($move_to_trash) && $move_to_trash)
298 ||
(isset($auto_expunge) && $auto_expunge)) && $sort != 6) {
300 /** Find and remove the ones that are deleted */
304 while ($j < $num_msgs) {
305 if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED'] == true) {
309 $msgs[$i] = $messages[$j];
316 if (!isset($messages)) {
323 // There's gotta be messages in the array for it to sort them.
324 if ($num_msgs > 0 && ! $use_cache) {
325 /** 0 = Date (up) 4 = Subject (up)
326 ** 1 = Date (dn) 5 = Subject (dn)
330 session_unregister("msgs");
331 if (($sort == 0) ||
($sort == 1))
332 $msort = array_cleave ($msgs, 'TIME_STAMP');
333 elseif (($sort == 2) ||
($sort == 3))
334 $msort = array_cleave ($msgs, 'FROM-SORT');
335 elseif (($sort == 4) ||
($sort == 5))
336 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
347 session_register('msort');
349 displayMessageArray($imapConnection, $num_msgs, $start_msg, $msgs, $msort, $mailbox, $sort, $color,$show_num);
350 session_register('msgs');
354 * Generic function to convert the msgs array into an HTML table.
356 function displayMessageArray($imapConnection, $num_msgs, $start_msg, &$msgs, $msort, $mailbox, $sort, $color, $show_num) {
357 global $folder_prefix, $sent_folder;
358 global $imapServerAddress, $data_dir, $username, $use_mailbox_cache;
359 global $index_order, $real_endMessage, $real_startMessage, $checkall;
361 /* If cache isn't already set, do it now. */
362 if (!session_is_registered('msgs')) { session_register('msgs'); }
363 if (!session_is_registered('msort')) { session_register('msort'); }
365 if ($start_msg +
($show_num - 1) < $num_msgs) {
366 $end_msg = $start_msg +
($show_num-1);
368 $end_msg = $num_msgs;
371 if ($end_msg < $start_msg) {
372 $start_msg = $start_msg - $show_num;
373 if ($start_msg < 1) { $start_msg = 1; }
376 $urlMailbox = urlencode($mailbox);
378 do_hook('mailbox_index_before');
380 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
381 $paginator_str = get_paginator_str
382 ($urlMailbox, $start_msg, $end_msg, $num_msgs, $show_num, $sort);
388 mail_message_listing_beginning( $imapConnection,
389 "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$start_msg",
390 $mailbox, $sort, $msg_cnt_str, $paginator_str, $start_msg);
392 $groupNum = $start_msg %
($show_num - 1);
393 $real_startMessage = $start_msg;
395 if ($end_msg - $start_msg < $show_num - 1) {
396 $end_msg = $end_msg - $start_msg +
1;
398 } else if ($start_msg > $show_num) {
399 $end_msg = $show_num;
403 $endVar = $end_msg +
1;
405 /* Loop through and display the info for each message. */
406 $t = 0; // $t is used for the checkbox number
407 if ($num_msgs == 0) { // if there's no messages in this folder
408 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=" . count($index_order) . ">\n".
409 " <CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR> </CENTER>\n".
411 } elseif ($start_msg == $end_msg) {
412 /* If there's only one message in the box, handle it differently. */
425 } while (isset ($key) && ($k < $i));
426 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
436 } while (isset ($key) && ($k < $i));
439 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
444 } while ($i && $i < $endVar);
448 "<table bgcolor=\"$color[9]\" width=100% border=0 cellpadding=1 cellspacing=1>" .
449 "<tr BGCOLOR=\"$color[4]\">" .
450 "<table width=100% BGCOLOR=\"$color[4]\" border=0 cellpadding=1 cellspacing=0><tr><td>$paginator_str</td>".
451 "<td align=right>$msg_cnt_str</td></tr></table>".
454 /** End of message-list table */
456 do_hook('mailbox_index_after');
457 echo "</TABLE></FORM>\n";
461 * Displays the standard message list header. To finish the table,
462 * you need to do a "</table></table>";
464 * $moveURL is the URL to submit the delete/move form to
465 * $mailbox is the current mailbox
466 * $sort is the current sorting method (-1 for no sorting available [searches])
467 * $Message is a message that is centered on top of the list
468 * $More is a second line that is left aligned
470 function mail_message_listing_beginning
471 ($imapConnection, $moveURL, $mailbox = '', $sort = -1,
472 $msg_cnt_str = '', $paginator = ' ', $start_msg = 1) {
473 global $color, $index_order, $auto_expunge, $move_to_trash;
474 global $checkall, $sent_folder, $draft_folder;
475 $urlMailbox = urlencode($mailbox);
478 * This is the beginning of the message list table.
479 * It wraps around all messages
481 echo "<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLPADDING=\"1\" CELLSPACING=\"0\">\n"
482 . "<TR BGCOLOR=\"$color[0]\"><TD>"
483 . " <TABLE BGCOLOR=\"$color[4]\" width=\"100%\" CELLPADDING=\"2\" CELLSPACING=\"0\" BORDER=\"0\"><TR>\n"
484 . " <TD ALIGN=LEFT>$paginator</TD>\n"
485 . " <TD ALIGN=RIGHT>$msg_cnt_str</TD>\n"
488 . "<TR><TD BGCOLOR=\"$color[0]\">\n"
489 . "<FORM name=messageList method=post action=\"$moveURL\">\n"
490 . "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=\"100%\">\n"
492 . " <TD ALIGN=LEFT VALIGN=CENTER NOWRAP>\n"
493 . ' <SMALL> ' . _("Move selected to:") . "</SMALL>\n"
495 . " <TD ALIGN=RIGHT NOWRAP>\n"
496 . ' <SMALL> ' . _("Transform Selected Messages") . ": </SMALL><BR>\n"
500 . " <TD ALIGN=LEFT VALIGN=CENTER NOWRAP>\n"
501 . ' <SMALL> <TT><SELECT NAME="targetMailbox">';
503 $boxes = sqimap_mailbox_list($imapConnection);
504 for ($i = 0; $i < count($boxes); $i++
) {
505 if (!in_array("noselect", $boxes[$i]['flags'])) {
506 $box = $boxes[$i]['unformatted'];
507 $box2 = str_replace(' ', ' ', $boxes[$i]['unformatted-disp']);
508 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
511 echo ' </SELECT></TT></SMALL>'.
512 "<SMALL><INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"" . _("Move") . "\"></SMALL>\n".
514 " <TD ALIGN=RIGHT NOWRAP> \n";
515 if (!$auto_expunge) {
516 echo ' <INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'"> '. _("mailbox") ." \n";
518 echo " <INPUT TYPE=SUBMIT NAME=\"markRead\" VALUE=\"". _("Read")."\">\n".
519 " <INPUT TYPE=SUBMIT NAME=\"markUnread\" VALUE=\"". _("Unread")."\">\n".
520 " <INPUT TYPE=SUBMIT VALUE=\"". _("Delete") . "\"> \n".
524 do_hook('mailbox_form_before');
527 "<TR><TD BGCOLOR=\"$color[0]\">".
528 "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=";
529 if ($GLOBALS['alt_index_colors']) {
534 echo " BGCOLOR=\"$color[0]\">".
535 "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
537 /* Print the headers. */
538 for ($i=1; $i <= count($index_order); $i++
) {
539 switch ($index_order[$i]) {
540 case 1: /* checkbox */
542 echo ' <TD WIDTH="1%"><B> </B></TD>';
546 if (handleAsSent($mailbox)) {
547 echo ' <TD WIDTH="25%"><B>'. _("To") .'</B>';
549 echo ' <TD WIDTH="25%"><B>'. _("From") .'</B>';
552 ShowSortButton($sort, $mailbox, 2, 3);
557 echo ' <TD NOWRAP WIDTH="5%"><B>'. _("Date") .'</B>';
558 ShowSortButton($sort, $mailbox, 0, 1);
562 case 4: /* subject */
563 echo ' <TD><B>'. _("Subject") .'</B> ';
564 ShowSortButton($sort, $mailbox, 4, 5);
569 echo ' <TD WIDTH="5%"><b>' . _("Size")."</b></TD>\n";
577 * This function shows the sort button. Isn't this a good comment?
579 function ShowSortButton($sort, $mailbox, $Up, $Down) {
580 /* Figure out which image we want to use. */
581 if ($sort != $Up && $sort != $Down) {
582 $img = 'sort_none.png';
584 } elseif ($sort == $Up) {
585 $img = 'up_pointer.png';
588 $img = 'down_pointer.png';
592 /* Now that we have everything figured out, show the actual button. */
593 echo ' <a href="right_main.php?newsort=' . $which .
594 '&startMessage=1&mailbox=' . urlencode($mailbox) .
595 '"><IMG SRC="../images/' . $img .
596 '" BORDER=0 WIDTH=12 HEIGHT=10></a>';
599 function get_selectall_link($start_msg, $sort) {
600 global $checkall, $PHP_SELF, $what, $where, $mailbox, $javascript_on;
602 if ($javascript_on) {
604 '<script language="JavaScript">' .
606 "function CheckAll() {\n" .
607 " for (var i = 0; i < document.messageList.elements.length; i++) {\n" .
608 " if( document.messageList.elements[i].type == 'checkbox' ) {\n" .
609 " document.messageList.elements[i].checked = !(document.messageList.elements[i].checked);\n".
614 '</script><a href=# onClick="CheckAll();">' . _("Toggle All") . "</a>\n";
616 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
617 . "&startMessage=$start_msg&sort=$sort&checkall=";
618 if (isset($checkall) && $checkall == '1') {
624 if (isset($where) && isset($what)) {
625 $result .= '&where=' . urlencode($where)
626 . '&what=' . urlencode($what);
631 if (isset($checkall) && ($checkall == '1')) {
632 $result .= _("Unselect All");
634 $result .= _("Select All");
640 /* Return our final result. */
645 * This function computes the "Viewing Messages..." string.
647 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
648 /* Compute the $msg_cnt_str. */
650 if ($start_msg < $end_msg) {
651 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"), $start_msg, $end_msg, $num_msgs);
652 } else if ($start_msg == $end_msg) {
653 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
658 /* Return our result string. */
663 * Generate a paginator link.
665 function get_paginator_link
666 ($box, $start_msg, $use, $text) {
667 $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
668 . "&startMessage=$start_msg&mailbox=$box\" "
669 . "TARGET=\"right\">$text</A>";
674 * This function computes the paginator string.
676 function get_paginator_str
677 ($box, $start_msg, $end_msg, $num_msgs, $show_num, $sort) {
678 global $username, $data_dir, $use_mailbox_cache, $color;
680 /* Initialize paginator string chunks. */
687 /* Create simple strings that will be creating the paginator. */
688 $spc = ' '; /* This will be used as a space. */
689 $sep = '|'; /* This will be used as a seperator. */
691 /* Get some paginator preference values. */
692 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON
);
693 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
);
695 /* Make sure that our start message number is not too big. */
696 $start_msg = min($start_msg, $num_msgs);
698 /* Decide whether or not we will use the mailbox cache. */
699 /* Not sure why $use_mailbox_cache is even passed in. */
706 /* Compute the starting message of the previous and next page group. */
707 $next_grp = $start_msg +
$show_num;
708 $prev_grp = $start_msg - $show_num;
710 /* Compute the basic previous and next strings. */
711 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
712 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
713 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
714 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
715 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
716 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
717 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
718 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
719 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
722 /* Page selector block. Following code computes page links. */
723 if ($pg_sel && ($num_msgs > $show_num)) {
724 /* Most importantly, what is the current page!!! */
725 $cur_pg = intval($start_msg / $show_num) +
1;
727 /* Compute total # of pages and # of paginator page links. */
728 $tot_pgs = ceil($num_msgs / $show_num); /* Total # of Pages */
729 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
731 /************************************************************/
732 /* Compute the size of the four quarters of the page links. */
733 /************************************************************/
735 /* If we can, just show all the pages. */
736 if (($tot_pgs - 1) <= $pg_max) {
737 $q1_pgs = $cur_pg - 1;
738 $q2_pgs = $q3_pgs = 0;
739 $q4_pgs = $tot_pgs - $cur_pg;
741 /* Otherwise, compute some magic to choose the four quarters. */
743 /* Compute the magic base values. Added together, */
744 /* these values will always equal to the $pag_pgs. */
745 /* NOTE: These are DEFAULT values and do not take */
746 /* the current page into account. That is below. */
747 $q1_pgs = floor($vis_pgs/4);
748 $q2_pgs = round($vis_pgs/4, 0);
749 $q3_pgs = ceil($vis_pgs/4);
750 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
752 /* Adjust if the first quarter contains the current page. */
753 if (($cur_pg - $q1_pgs) < 1) {
754 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) +
$q2_pgs;
755 $q1_pgs = $cur_pg - 1;
757 $q3_pgs +
= ceil($extra_pgs / 2);
758 $q4_pgs +
= floor($extra_pgs / 2);
760 /* Adjust if the first and second quarters intersect. */
761 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
762 $extra_pgs = $q2_pgs;
763 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
764 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
765 $q3_pgs +
= ceil($extra_pgs / 2);
766 $q4_pgs +
= floor($extra_pgs / 2);
768 /* Adjust if the fourth quarter contains the current page. */
769 } else if (($cur_pg +
$q4_pgs) >= $tot_pgs) {
770 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) +
$q3_pgs;
772 $q4_pgs = $tot_pgs - $cur_pg;
773 $q1_pgs +
= floor($extra_pgs / 2);
774 $q2_pgs +
= ceil($extra_pgs / 2);
776 /* Adjust if the third and fourth quarter intersect. */
777 } else if (($cur_pg +
$q3_pgs +
1) >= ($tot_pgs - $q4_pgs +
1)) {
778 $extra_pgs = $q3_pgs;
779 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
780 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
781 $q1_pgs +
= floor($extra_pgs / 2);
782 $q2_pgs +
= ceil($extra_pgs / 2);
786 /* I am leaving this debug code here, commented out, because */
787 /* it is a really nice way to see what the above code is doing. */
788 /* echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = " */
789 /* . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>'; */
791 /************************************************************/
792 /* Print out the page links from the compute page quarters. */
793 /************************************************************/
795 /* Start with the first quarter. */
796 if (($q1_pgs == 0) && ($cur_pg > 1)) {
797 $pg_str .= "...$spc";
799 for ($pg = 1; $pg <= $q1_pgs; ++
$pg) {
800 $start = (($pg-1) * $show_num) +
1;
801 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
803 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
804 $pg_str .= "...$spc";
808 /* Continue with the second quarter. */
809 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++
$pg) {
810 $start = (($pg-1) * $show_num) +
1;
811 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
814 /* Now print the current page. */
815 $pg_str .= $cur_pg . $spc;
817 /* Next comes the third quarter. */
818 for ($pg = $cur_pg +
1; $pg <= $cur_pg +
$q3_pgs; ++
$pg) {
819 $start = (($pg-1) * $show_num) +
1;
820 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
823 /* And last, print the forth quarter page links. */
824 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
825 $pg_str .= "...$spc";
827 if (($tot_pgs - $q4_pgs) > ($cur_pg +
$q3_pgs)) {
828 $pg_str .= "...$spc";
830 for ($pg = $tot_pgs - $q4_pgs +
1; $pg <= $tot_pgs; ++
$pg) {
831 $start = (($pg-1) * $show_num) +
1;
832 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
837 /* If necessary, compute the 'show all' string. */
838 if (($prv_str != '') ||
($nxt_str != '')) {
839 $all_str = "<A HREF=\"right_main.php?PG_SHOWNUM=9999"
840 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
841 . "TARGET=\"right\">" . _("Show All") . '</A>';
844 /* Last but not least, get the value for the toggle all link. */
845 $tgl_str = get_selectall_link($start_msg, $sort);
847 /* Put all the pieces of the paginator string together. */
849 $result .= ($all_str != '' ?
$all_str . $spc . $sep . $spc: '');
850 $result .= ($prv_str != '' ?
$prv_str . $spc . $sep . $spc : '');
851 $result .= ($pg_str != '' ?
$pg_str . $sep . $spc : '');
852 $result .= ($nxt_str != '' ?
$nxt_str : '');
853 $result .= ($result != '' ?
$spc . $sep . $spc . $tgl_str: $tgl_str);
855 /* If the resulting string is blank, return a non-breaking space. */
860 /* Return our final magical paginator string. */
864 function processSubject($subject) {
865 // Shouldn't ever happen -- caught too many times in the IMAP functions
867 return _("(no subject)");
869 if (strlen($subject) <= 55)
872 $ent_strlen=strlen($subject);
875 // see if this is entities-encoded string
876 // If so, Iterate through the whole string, find out
877 // the real number of characters, and if more
878 // than 55, substr with an updated trim value.
879 while (($ent_loc = strpos($subject, '&', $ent_offset)) !== false &&
880 ($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false)
882 $trim_val +
= ($ent_loc_end-$ent_loc)+
1;
883 $ent_strlen -= $ent_loc_end-$ent_loc;
884 $ent_offset = $ent_loc_end+
1;
887 if ($ent_strlen <= 55)
890 return substr($subject, 0, $trim_val) . '...';
893 function handleAsSent($mailbox) {
894 global $sent_folder, $draft_folder;
895 global $handleAsSent_result;
897 /* First check if this is the sent or draft folder. */
898 $handleAsSent_result = (($mailbox == $sent_folder)
899 ||
($mailbox == $draft_folder));
901 /* Then check the result of the handleAsSent hook. */
902 do_hook('check_handleAsSent_result', $mailbox);
904 /* And return the result. */
905 return ($handleAsSent_result);