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 define('PG_SEL_MAX', 10); /* Default value for page_selector_max. */
19 function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $start_msg, $where, $what) {
21 $color, $msgs, $msort,
22 $sent_folder, $draft_folder,
23 $default_use_priority,
24 $message_highlight_list,
26 $indent_array, /* indent subject by */
27 $pos, /* Search postion (if any) */
28 $thread_sort_messages; /* thread sorting on/off */
29 $color_string = $color[4];
31 if ($GLOBALS['alt_index_colors']) {
32 if (!isset($GLOBALS['row_count'])) {
33 $GLOBALS['row_count'] = 0;
35 $GLOBALS['row_count']++
;
36 if ($GLOBALS['row_count'] %
2) {
37 if (!isset($color[12])) {
38 $color[12] = '#EAEAEA';
40 $color_string = $color[12];
46 * This is done in case you're looking into Sent folders,
47 * because you can have multi receiver.
49 $sendersName = split(',', $msg['FROM']);
51 for ($index = 0 ; $index < count($sendersName) ; $index++
) {
52 if ($senderName != '') {
55 $senderName .= sqimap_find_displayable_name($sendersName[$index]);
58 if( $mailbox == 'None' ) {
59 // $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
60 $boxes = sqimap_mailbox_list($imapConnection);
61 // sqimap_logout($imapConnection);
62 $mailbox = $boxes[0]['unformatted'];
65 $urlMailbox = urlencode($mailbox);
66 $subject = processSubject($msg['SUBJECT']);
69 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
70 $flag = "<font color=\"$color[2]\">";
71 $flag_end = '</font>';
76 if (!isset($msg['FLAG_SEEN']) ||
($msg['FLAG_SEEN'] == false)) {
84 if (handleAsSent($mailbox)) {
92 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
93 $fontstr = "<font color=\"$color[9]\">";
94 $fontstr_end = '</font>';
100 for ($i=0; $i < count($message_highlight_list); $i++
) {
101 if (trim($message_highlight_list[$i]['value']) != '') {
102 if ($message_highlight_list[$i]['match_type'] == 'to_cc') {
103 if (strpos('^^'.strtolower($msg['TO']), strtolower($message_highlight_list[$i]['value'])) ||
strpos('^^'.strtolower($msg['CC']), strtolower($message_highlight_list[$i]['value']))) {
104 $hlt_color = $message_highlight_list[$i]['color'];
107 } else if (strpos('^^'.strtolower($msg[strtoupper($message_highlight_list[$i]['match_type'])]),strtolower($message_highlight_list[$i]['value']))) {
108 $hlt_color = $message_highlight_list[$i]['color'];
114 if (!isset($hlt_color)) {
115 $hlt_color = $color_string;
118 if ($where && $what) {
119 if( !isset( $pos ) ||
$pos == '' ) {
122 $search_stuff = "&pos=" . urlencode( $pos ) . "&where=".urlencode($where).'&what='.urlencode($what);
125 $checked = ($checkall == 1 ?
' checked' : '');
127 for ($i=1; $i <= count($index_order); $i++
) {
128 switch ($index_order[$i]) {
129 case 1: /* checkbox */
130 echo " <td bgcolor=\"$hlt_color\" align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."$checked></TD>\n";
133 echo " <td bgcolor=\"$hlt_color\">$italic$bold$flag$fontstr$senderName$fontstr_end$flag_end$bold_end$italic_end</td>\n";
136 echo " <td nowrap bgcolor=\"$hlt_color\"><center>$bold$flag$fontstr".$msg["DATE_STRING"]."$fontstr_end$flag_end$bold_end</center></td>\n";
138 case 4: /* subject */
139 echo " <td bgcolor=\"$hlt_color\">$bold";
140 if (! isset($search_stuff)) { $search_stuff = ''; }
141 if ($thread_sort_messages == 1) {
142 echo str_repeat(" ",$indent_array[$msg["ID"]]);
144 echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=".$msg["ID"]."&startMessage=$start_msg&show_more=0$search_stuff\"";
145 do_hook("subject_link");
147 if ($subject != $msg['SUBJECT']) {
148 $title = get_html_translation_table(HTML_SPECIALCHARS
);
149 $title = array_flip($title);
150 $title = strtr($msg['SUBJECT'], $title);
151 $title = str_replace('"', "''", $title);
152 echo " title=\"$title\"";
154 echo ">$flag$subject$flag_end</a>$bold_end</td>\n";
158 echo " <td bgcolor=\"$hlt_color\" align=center nowrap><b><small>\n";
159 if (isset($msg['FLAG_ANSWERED']) &&
160 $msg['FLAG_ANSWERED'] == true) {
164 if ($msg['TYPE0'] == 'multipart') {
168 if ($default_use_priority) {
169 if (ereg('(1|2)',substr($msg['PRIORITY'],0,1))) {
170 echo "<font color=\"$color[1]\">!</font>\n";
173 if (ereg('(5)',substr($msg['PRIORITY'],0,1))) {
174 echo "<font color=\"$color[8]\">?</font>\n";
178 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
179 echo "<font color=\"$color[1]\">D</font>\n";
186 echo "</small></b></td>\n";
189 echo " <td bgcolor=\"$hlt_color\">$bold$fontstr" .
190 show_readable_size($msg['SIZE']) .
191 "$fontstr_end$bold_end</td>\n";
199 * This function loops through a group of messages in the mailbox
200 * and shows them to the user.
202 function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs, $start_msg, $sort,
203 $color, $show_num, $use_cache) {
204 global $msgs, $msort,
205 $sent_folder, $draft_folder,
206 $message_highlight_list,
207 $auto_expunge, $thread_sort_messages,
208 $data_dir, $username;
209 /* If autoexpunge is turned on, then do it now. */
212 if ($thread_sort_messages == 1 ) {
213 $id = get_thread_sort($imapConnection);
215 if ($start_msg +
($show_num - 1) < $num_msgs) {
216 $end_msg = $start_msg +
($show_num-1);
219 $end_msg = $num_msgs;
221 $id = array_slice($id, ($start_msg-1), ($end_msg));
223 if ($auto_expunge == true) {
224 sqimap_mailbox_expunge($imapConnection, $mailbox, false);
226 sqimap_mailbox_select($imapConnection, $mailbox);
227 $issent = handleAsSent($mailbox);
229 /* If it is sorted... */
230 if ($num_msgs >= 1) {
232 $id = range(1, $num_msgs);
234 elseif ($thread_sort_messages != 1) {
235 // if it's not sorted
236 if ($start_msg +
($show_num - 1) < $num_msgs) {
237 $end_msg = $start_msg +
($show_num-1);
239 $end_msg = $num_msgs;
242 if ($end_msg < $start_msg) {
243 $start_msg = $start_msg - $show_num;
244 if ($start_msg < 1) {
249 $real_startMessage = $num_msgs - $start_msg +
1;
250 $real_endMessage = $num_msgs - $start_msg - $show_num +
2;
251 if ($real_endMessage <= 0) {
252 $real_endMessage = 1;
254 $id = array_reverse(range($real_endMessage, $real_startMessage));
256 $msgs_list = sqimap_get_small_header_list($imapConnection, $id, $issent);
257 $flags = sqimap_get_flags_list($imapConnection, $id, $issent);
258 foreach ($msgs_list as $hdr) {
259 $from[] = $hdr->from
;
260 $date[] = $hdr->date
;
261 $subject[] = $hdr->subject
;
263 $priority[] = $hdr->priority
;
265 $size[] = $hdr->size
;
266 $type[] = $hdr->type0
;
271 $end = $start_msg +
$show_num - 1;
272 if ($num_msgs < $show_num) {
273 $end_loop = $num_msgs;
274 } else if ($end > $num_msgs) {
275 $end_loop = $num_msgs - $start_msg +
1;
277 $end_loop = $show_num;
283 while ($j < $end_loop) {
284 if (isset($date[$j])) {
285 $date[$j] = str_replace(' ', ' ', $date[$j]);
286 $tmpdate = explode(' ', trim($date[$j]));
288 $tmpdate = $date = array('', '', '', '', '', '');
291 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
292 $messages[$j]['DATE_STRING'] = getDateString($messages[$j]['TIME_STAMP']);
293 $messages[$j]['ID'] = $id[$j];
294 $messages[$j]['FROM'] = decodeHeader($from[$j]);
295 $messages[$j]['FROM-SORT'] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
296 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
297 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
298 $messages[$j]['TO'] = decodeHeader($to[$j]);
299 $messages[$j]['PRIORITY'] = $priority[$j];
300 $messages[$j]['CC'] = $cc[$j];
301 $messages[$j]['SIZE'] = $size[$j];
302 $messages[$j]['TYPE0'] = $type[$j];
304 # fix SUBJECT-SORT to remove Re:
305 $re_abbr = /* Add more here! */
306 'vedr|sv|' . /* Danish */
307 're|aw'; /* English */
309 if (eregi( "^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs)) {
310 $messages[$j]['SUBJECT-SORT'] = $regs[2];
314 while ($num < count($flags[$j])) {
315 if ($flags[$j][$num] == 'Deleted') {
316 $messages[$j]['FLAG_DELETED'] = true;
317 } else if ($flags[$j][$num] == 'Answered') {
318 $messages[$j]['FLAG_ANSWERED'] = true;
319 } else if ($flags[$j][$num] == 'Seen') {
320 $messages[$j]['FLAG_SEEN'] = true;
321 } else if ($flags[$j][$num] == 'Flagged') {
322 $messages[$j]['FLAG_FLAGGED'] = true;
328 /* Only ignore messages flagged as deleted if we are using a
329 * trash folder or auto_expunge */
330 if (((isset($move_to_trash) && $move_to_trash)
331 ||
(isset($auto_expunge) && $auto_expunge)) && $sort != 6) {
333 /** Find and remove the ones that are deleted */
337 while ($j < $num_msgs) {
338 if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED'] == true) {
342 $msgs[$i] = $messages[$j];
349 if (!isset($messages)) {
356 // There's gotta be messages in the array for it to sort them.
357 if ($num_msgs > 0 && ! $use_cache && $thread_sort_messages != 1) {
358 /** 0 = Date (up) 4 = Subject (up)
359 ** 1 = Date (dn) 5 = Subject (dn)
363 session_unregister('msgs');
364 if (($sort == 0) ||
($sort == 1)) {
365 $msort = array_cleave ($msgs, 'TIME_STAMP');
366 } elseif (($sort == 2) ||
($sort == 3)) {
367 $msort = array_cleave ($msgs, 'FROM-SORT');
368 } elseif (($sort == 4) ||
($sort == 5)) {
369 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
370 } else { // ($sort == 6)
382 session_register('msort');
384 elseif ($thread_sort_messages == 1 ) {
386 session_unregister('msgs');
387 session_register('msort');
389 displayMessageArray($imapConnection, $num_msgs, $start_msg, $msgs, $msort, $mailbox, $sort, $color,$show_num);
390 session_register('msgs');
394 * Generic function to convert the msgs array into an HTML table.
396 function displayMessageArray($imapConnection, $num_msgs, $start_msg, &$msgs, $msort, $mailbox, $sort, $color, $show_num) {
397 global $folder_prefix, $sent_folder;
398 global $imapServerAddress, $data_dir, $username, $use_mailbox_cache;
399 global $index_order, $real_endMessage, $real_startMessage, $checkall;
400 global $indent_array, $thread_sort_messages;
402 /* If cache isn't already set, do it now. */
403 if (!session_is_registered('msgs')) { session_register('msgs'); }
404 if (!session_is_registered('msort')) { session_register('msort'); }
406 if ($start_msg +
($show_num - 1) < $num_msgs) {
407 $end_msg = $start_msg +
($show_num-1);
409 $end_msg = $num_msgs;
412 if ($end_msg < $start_msg) {
413 $start_msg = $start_msg - $show_num;
414 if ($start_msg < 1) { $start_msg = 1; }
417 $urlMailbox = urlencode($mailbox);
419 do_hook('mailbox_index_before');
421 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
422 $paginator_str = get_paginator_str
423 ($urlMailbox, $start_msg, $end_msg, $num_msgs, $show_num, $sort);
429 /* get indent level for subject display */
430 if ($thread_sort_messages == 1 ) {
431 $indent_array = get_parent_level($imapConnection);
433 mail_message_listing_beginning( $imapConnection,
434 "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$start_msg",
435 $mailbox, $sort, $msg_cnt_str, $paginator_str, $start_msg);
437 $groupNum = $start_msg %
($show_num - 1);
438 $real_startMessage = $start_msg;
440 if ($end_msg - $start_msg < $show_num - 1) {
441 $end_msg = $end_msg - $start_msg +
1;
443 } else if ($start_msg > $show_num) {
444 $end_msg = $show_num;
448 $endVar = $end_msg +
1;
450 /* Loop through and display the info for each message. */
451 $t = 0; // $t is used for the checkbox number
452 if ($num_msgs == 0) { // if there's no messages in this folder
453 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=" . count($index_order) . ">\n".
454 " <CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR> </CENTER>\n".
456 } elseif ($start_msg == $end_msg) {
457 /* If there's only one message in the box, handle it differently. */
470 } while (isset ($key) && ($k < $i));
471 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
481 } while (isset ($key) && ($k < $i));
484 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
489 } while ($i && $i < $endVar);
493 "<table bgcolor=\"$color[9]\" width=\"100%\" border=0 cellpadding=1 cellspacing=1>" .
494 "<tr BGCOLOR=\"$color[4]\"><td>" .
495 "<table width=\"100%\" BGCOLOR=\"$color[4]\" border=0 cellpadding=1 cellspacing=0><tr><td>$paginator_str</td>".
496 "<td align=right>$msg_cnt_str</td></tr></table>".
499 /** End of message-list table */
501 do_hook('mailbox_index_after');
502 echo "</TABLE></FORM>\n";
506 * Displays the standard message list header. To finish the table,
507 * you need to do a "</table></table>";
509 * $moveURL is the URL to submit the delete/move form to
510 * $mailbox is the current mailbox
511 * $sort is the current sorting method (-1 for no sorting available [searches])
512 * $Message is a message that is centered on top of the list
513 * $More is a second line that is left aligned
515 function mail_message_listing_beginning
516 ($imapConnection, $moveURL, $mailbox = '', $sort = -1,
517 $msg_cnt_str = '', $paginator = ' ', $start_msg = 1) {
518 global $color, $index_order, $auto_expunge, $move_to_trash, $base_uri;
519 global $checkall, $sent_folder, $draft_folder, $thread_sort_messages, $allow_thread_sort;
520 $urlMailbox = urlencode($mailbox);
523 * This is the beginning of the message list table.
524 * It wraps around all messages
526 echo "<FORM name=messageList method=post action=\"$moveURL\">\n"
527 . "<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLPADDING=\"1\" CELLSPACING=\"0\">\n"
528 . "<TR BGCOLOR=\"$color[0]\"><TD>"
529 . " <TABLE BGCOLOR=\"$color[4]\" width=\"100%\" CELLPADDING=\"2\" CELLSPACING=\"0\" BORDER=\"0\"><TR>\n"
530 . " <TD ALIGN=LEFT>$paginator\n";
532 if ($allow_thread_sort == TRUE) {
533 if ($thread_sort_messages == 1 ) {
535 $thread_name = 'Unthread View';
537 elseif ($thread_sort_messages == 0) {
539 $thread_name = 'Thread View';
541 echo '| <a href='."$base_uri".'src/right_main.php?sort='."$sort".'&start_messages=1&set_thread='."$set_thread".'&mailbox='.urlencode($mailbox).'>'._("$thread_name").'</a> ';
546 echo " <TD ALIGN=RIGHT>$msg_cnt_str</TD>\n"
549 . "<TR><TD BGCOLOR=\"$color[0]\">\n"
550 . "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=\"100%\">\n"
552 . " <TD ALIGN=LEFT VALIGN=MIDDLE NOWRAP>\n"
553 . ' <SMALL> ' . _("Move Selected To:") . "</SMALL>\n"
555 . " <TD ALIGN=RIGHT NOWRAP>\n"
556 . ' <SMALL> ' . _("Transform Selected Messages") . ": </SMALL><BR>\n"
560 . " <TD ALIGN=\"LEFT\" VALIGN=\"MIDDLE\" NOWRAP>\n"
561 . ' <SMALL> <TT><SELECT NAME="targetMailbox">';
563 $boxes = sqimap_mailbox_list($imapConnection);
564 for ($i = 0; $i < count($boxes); $i++
) {
565 if (!in_array('noselect', $boxes[$i]['flags'])) {
566 $box = $boxes[$i]['unformatted'];
567 $box2 = str_replace(' ', ' ', $boxes[$i]['unformatted-disp']);
568 if( $box2 == 'INBOX' ) {
571 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
574 echo ' </SELECT></TT> '.
575 '<INPUT TYPE="SUBMIT" NAME="moveButton" VALUE="' . _("Move") . '"> '.
576 '<INPUT TYPE="SUBMIT" NAME="attache" VALUE="' . _("Forward") . "\"> \n"."</SMALL>\n";
579 " <TD ALIGN=\"RIGHT\" NOWRAP>";
580 if (!$auto_expunge) {
581 echo '<INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="' . _("Expunge") . '"> ' . _("mailbox") . ' ';
583 echo '<INPUT TYPE="SUBMIT" NAME="markRead" VALUE="' . _("Read") . '">' .
584 '<INPUT TYPE="SUBMIT" NAME="markUnread" VALUE="' . _("Unread") . '">' .
585 '<INPUT TYPE="SUBMIT" VALUE="' . _("Delete") . '"> ' .
589 do_hook('mailbox_form_before');
592 "<TR><TD BGCOLOR=\"$color[0]\">".
593 '<TABLE WIDTH="100%" BORDER=0 CELLPADDING=2 CELLSPACING=';
594 if ($GLOBALS['alt_index_colors']) {
599 echo " BGCOLOR=\"$color[0]\">".
600 "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
602 /* Print the headers. */
603 for ($i=1; $i <= count($index_order); $i++
) {
604 switch ($index_order[$i]) {
605 case 1: /* checkbox */
607 echo ' <TD WIDTH="1%"><B> </B></TD>';
611 if (handleAsSent($mailbox)) {
612 echo ' <TD WIDTH="25%"><B>'. _("To") .'</B>';
614 echo ' <TD WIDTH="25%"><B>'. _("From") .'</B>';
616 if ($thread_sort_messages != 1) {
617 ShowSortButton($sort, $mailbox, 2, 3);
623 echo ' <TD NOWRAP WIDTH="5%"><B>'. _("Date") .'</B>';
624 if ($thread_sort_messages != 1) {
625 ShowSortButton($sort, $mailbox, 0, 1);
630 case 4: /* subject */
631 echo ' <TD><B>'. _("Subject") .'</B> ';
632 if ($thread_sort_messages != 1) {
633 ShowSortButton($sort, $mailbox, 4, 5);
639 echo ' <TD WIDTH="5%"><b>' . _("Size")."</b></TD>\n";
647 * This function shows the sort button. Isn't this a good comment?
649 function ShowSortButton($sort, $mailbox, $Up, $Down) {
650 /* Figure out which image we want to use. */
651 if ($sort != $Up && $sort != $Down) {
652 $img = 'sort_none.png';
654 } elseif ($sort == $Up) {
655 $img = 'up_pointer.png';
658 $img = 'down_pointer.png';
662 /* Now that we have everything figured out, show the actual button. */
663 echo ' <a href="right_main.php?newsort=' . $which .
664 '&startMessage=1&mailbox=' . urlencode($mailbox) .
665 '"><IMG SRC="../images/' . $img .
666 '" BORDER=0 WIDTH=12 HEIGHT=10></a>';
669 function get_selectall_link($start_msg, $sort) {
670 global $checkall, $what, $where, $mailbox, $javascript_on;
671 global $PHP_SELF, $PG_SHOWNUM;
674 if ($javascript_on) {
676 '<script language="JavaScript" type="text/javascript">' .
678 "function CheckAll() {\n" .
679 " for (var i = 0; i < document.messageList.elements.length; i++) {\n" .
680 " if( document.messageList.elements[i].type == 'checkbox' ) {\n" .
681 " document.messageList.elements[i].checked = !(document.messageList.elements[i].checked);\n".
686 '</script><a href="#" onClick="CheckAll();">' . _("Toggle All") . "</a>\n";
688 if (strpos($PHP_SELF, "?")) {
689 $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($mailbox)
690 . "&startMessage=$start_msg&sort=$sort&checkall=";
693 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
694 . "&startMessage=$start_msg&sort=$sort&checkall=";
696 if (isset($checkall) && $checkall == '1') {
702 if (isset($where) && isset($what)) {
703 $result .= '&where=' . urlencode($where)
704 . '&what=' . urlencode($what);
707 if ($PG_SHOWNUM == 999999) {
708 $result .= '&PG_SHOWNUM=999999';
713 if (isset($checkall) && ($checkall == '1')) {
714 $result .= _("Unselect All");
716 $result .= _("Select All");
722 /* Return our final result. */
727 * This function computes the "Viewing Messages..." string.
729 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
730 /* Compute the $msg_cnt_str. */
732 if ($start_msg < $end_msg) {
733 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"), $start_msg, $end_msg, $num_msgs);
734 } else if ($start_msg == $end_msg) {
735 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
740 /* Return our result string. */
745 * Generate a paginator link.
747 function get_paginator_link
748 ($box, $start_msg, $use, $text) {
749 $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
750 . "&startMessage=$start_msg&mailbox=$box\" "
751 . "TARGET=\"right\">$text</A>";
756 * This function computes the paginator string.
758 function get_paginator_str
759 ($box, $start_msg, $end_msg, $num_msgs, $show_num, $sort) {
760 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
762 /* Initialize paginator string chunks. */
769 /* Create simple strings that will be creating the paginator. */
770 $spc = ' '; /* This will be used as a space. */
771 $sep = '|'; /* This will be used as a seperator. */
773 /* Get some paginator preference values. */
774 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON
);
775 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
);
777 /* Make sure that our start message number is not too big. */
778 $start_msg = min($start_msg, $num_msgs);
780 /* Decide whether or not we will use the mailbox cache. */
781 /* Not sure why $use_mailbox_cache is even passed in. */
788 /* Compute the starting message of the previous and next page group. */
789 $next_grp = $start_msg +
$show_num;
790 $prev_grp = $start_msg - $show_num;
792 /* Compute the basic previous and next strings. */
793 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
794 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
795 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
796 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
797 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
798 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
799 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
800 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
801 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
804 /* Page selector block. Following code computes page links. */
805 if ($pg_sel && ($num_msgs > $show_num)) {
806 /* Most importantly, what is the current page!!! */
807 $cur_pg = intval($start_msg / $show_num) +
1;
809 /* Compute total # of pages and # of paginator page links. */
810 $tot_pgs = ceil($num_msgs / $show_num); /* Total # of Pages */
811 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
813 /************************************************************/
814 /* Compute the size of the four quarters of the page links. */
815 /************************************************************/
817 /* If we can, just show all the pages. */
818 if (($tot_pgs - 1) <= $pg_max) {
819 $q1_pgs = $cur_pg - 1;
820 $q2_pgs = $q3_pgs = 0;
821 $q4_pgs = $tot_pgs - $cur_pg;
823 /* Otherwise, compute some magic to choose the four quarters. */
825 /* Compute the magic base values. Added together, */
826 /* these values will always equal to the $pag_pgs. */
827 /* NOTE: These are DEFAULT values and do not take */
828 /* the current page into account. That is below. */
829 $q1_pgs = floor($vis_pgs/4);
830 $q2_pgs = round($vis_pgs/4, 0);
831 $q3_pgs = ceil($vis_pgs/4);
832 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
834 /* Adjust if the first quarter contains the current page. */
835 if (($cur_pg - $q1_pgs) < 1) {
836 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) +
$q2_pgs;
837 $q1_pgs = $cur_pg - 1;
839 $q3_pgs +
= ceil($extra_pgs / 2);
840 $q4_pgs +
= floor($extra_pgs / 2);
842 /* Adjust if the first and second quarters intersect. */
843 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
844 $extra_pgs = $q2_pgs;
845 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
846 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
847 $q3_pgs +
= ceil($extra_pgs / 2);
848 $q4_pgs +
= floor($extra_pgs / 2);
850 /* Adjust if the fourth quarter contains the current page. */
851 } else if (($cur_pg +
$q4_pgs) >= $tot_pgs) {
852 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) +
$q3_pgs;
854 $q4_pgs = $tot_pgs - $cur_pg;
855 $q1_pgs +
= floor($extra_pgs / 2);
856 $q2_pgs +
= ceil($extra_pgs / 2);
858 /* Adjust if the third and fourth quarter intersect. */
859 } else if (($cur_pg +
$q3_pgs +
1) >= ($tot_pgs - $q4_pgs +
1)) {
860 $extra_pgs = $q3_pgs;
861 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
862 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
863 $q1_pgs +
= floor($extra_pgs / 2);
864 $q2_pgs +
= ceil($extra_pgs / 2);
868 /* I am leaving this debug code here, commented out, because */
869 /* it is a really nice way to see what the above code is doing. */
870 /* echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = " */
871 /* . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>'; */
873 /************************************************************/
874 /* Print out the page links from the compute page quarters. */
875 /************************************************************/
877 /* Start with the first quarter. */
878 if (($q1_pgs == 0) && ($cur_pg > 1)) {
879 $pg_str .= "...$spc";
881 for ($pg = 1; $pg <= $q1_pgs; ++
$pg) {
882 $start = (($pg-1) * $show_num) +
1;
883 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
885 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
886 $pg_str .= "...$spc";
890 /* Continue with the second quarter. */
891 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++
$pg) {
892 $start = (($pg-1) * $show_num) +
1;
893 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
896 /* Now print the current page. */
897 $pg_str .= $cur_pg . $spc;
899 /* Next comes the third quarter. */
900 for ($pg = $cur_pg +
1; $pg <= $cur_pg +
$q3_pgs; ++
$pg) {
901 $start = (($pg-1) * $show_num) +
1;
902 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
905 /* And last, print the forth quarter page links. */
906 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
907 $pg_str .= "...$spc";
909 if (($tot_pgs - $q4_pgs) > ($cur_pg +
$q3_pgs)) {
910 $pg_str .= "...$spc";
912 for ($pg = $tot_pgs - $q4_pgs +
1; $pg <= $tot_pgs; ++
$pg) {
913 $start = (($pg-1) * $show_num) +
1;
914 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
917 } else if ($PG_SHOWNUM == 999999) {
918 $pg_str = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
919 . "&startMessage=1&mailbox=$box\" TARGET=\"right\">"
920 . _("Paginate") . '</A>' . $spc;
923 /* If necessary, compute the 'show all' string. */
924 if (($prv_str != '') ||
($nxt_str != '')) {
925 $all_str = "<A HREF=\"right_main.php?PG_SHOWNUM=999999"
926 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
927 . "TARGET=\"right\">" . _("Show All") . '</A>';
930 /* Last but not least, get the value for the toggle all link. */
931 $tgl_str = get_selectall_link($start_msg, $sort);
933 /* Put all the pieces of the paginator string together. */
935 $result .= ($prv_str != '' ?
$prv_str . $spc . $sep . $spc : '');
936 $result .= ($nxt_str != '' ?
$nxt_str . $spc . $sep . $spc : '');
937 $result .= ($pg_str != '' ?
$pg_str : '');
938 $result .= ($all_str != '' ?
$sep . $spc . $all_str . $spc : '');
939 $result .= ($result != '' ?
$sep . $spc . $tgl_str: $tgl_str);
941 /* If the resulting string is blank, return a non-breaking space. */
946 /* Return our final magical paginator string. */
950 function processSubject($subject) {
951 // Shouldn't ever happen -- caught too many times in the IMAP functions
953 return _("(no subject)");
955 if (strlen($subject) <= 55)
958 $ent_strlen=strlen($subject);
961 // see if this is entities-encoded string
962 // If so, Iterate through the whole string, find out
963 // the real number of characters, and if more
964 // than 55, substr with an updated trim value.
965 while (($ent_loc = strpos($subject, '&', $ent_offset)) !== false &&
966 ($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false)
968 $trim_val +
= ($ent_loc_end-$ent_loc)+
1;
969 $ent_strlen -= $ent_loc_end-$ent_loc;
970 $ent_offset = $ent_loc_end+
1;
973 if ($ent_strlen <= 55)
976 return substr($subject, 0, $trim_val) . '...';
979 function handleAsSent($mailbox) {
980 global $sent_folder, $draft_folder;
981 global $handleAsSent_result;
983 /* First check if this is the sent or draft folder. */
984 $handleAsSent_result = (($mailbox == $sent_folder)
985 ||
($mailbox == $draft_folder));
987 /* Then check the result of the handleAsSent hook. */
988 do_hook('check_handleAsSent_result', $mailbox);
990 /* And return the result. */
991 return ($handleAsSent_result);