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');
16 require_once('../functions/imap_utf7_decode_local.php');
18 /* Default value for page_selector_max. */
19 define('PG_SEL_MAX', 10);
21 function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort,
22 $start_msg, $where, $what){
24 $color, $msgs, $msort,
25 $sent_folder, $draft_folder,
26 $default_use_priority,
27 $message_highlight_list,
29 $indent_array, /* indent subject by */
30 $pos, /* Search postion (if any) */
31 $thread_sort_messages, /* thread sorting on/off */
32 $server_sort_order, /* sort value when using server-sorting */
34 $allow_server_sort; /* enable/disable server-side sorting */
35 $color_string = $color[4];
37 if ($GLOBALS['alt_index_colors']) {
38 if (!isset($row_count)) {
43 if (!isset($color[12])) {
44 $color[12] = '#EAEAEA';
46 $color_string = $color[12];
52 * This is done in case you're looking into Sent folders,
53 * because you can have multiple receivers.
55 $senderNames = explode(',', $msg['FROM']);
57 if (sizeof($senderNames)){
58 foreach ($senderNames as $senderNames_part) {
59 if ($senderName != '') {
62 $senderName .= sqimap_find_displayable_name($senderNames_part);
66 if( $mailbox == 'None' ) {
67 $boxes = sqimap_mailbox_list($imapConnection);
68 $mailbox = $boxes[0]['unformatted'];
71 $urlMailbox = urlencode($mailbox);
72 $subject = processSubject($msg['SUBJECT']);
75 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
76 $flag = "<font color=\"$color[2]\">";
77 $flag_end = '</font>';
82 if (!isset($msg['FLAG_SEEN']) ||
($msg['FLAG_SEEN'] == false)) {
89 if (handleAsSent($mailbox)) {
96 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
97 $fontstr = "<font color=\"$color[9]\">";
98 $fontstr_end = '</font>';
105 * AAAAH! Make my eyes stop bleeding!
108 if (sizeof($message_highlight_list)){
109 foreach ($message_highlight_list as $message_highlight_list_part) {
110 if (trim($message_highlight_list_part['value']) != '') {
111 if ($message_highlight_list_part['match_type'] == 'to_cc') {
112 if (strstr('^^' . strtolower($msg['TO']),
113 strtolower($message_highlight_list_part['value']))
114 ||
strstr('^^'.strtolower($msg['CC']),
115 strtolower($message_highlight_list_part['value']))) {
116 $hlt_color = $message_highlight_list_part['color'];
120 if (strstr('^^' . strtolower($msg[strtoupper($message_highlight_list_part['match_type'])]),
121 strtolower($message_highlight_list_part['value']))) {
122 $hlt_color = $message_highlight_list_part['color'];
129 if (!isset($hlt_color)) {
130 $hlt_color = $color_string;
133 if ($where && $what) {
134 if(!isset($pos) ||
$pos == '') {
137 $search_stuff = "&pos=" . urlencode($pos)
138 . "&where=" . urlencode($where) . '&what=' . urlencode($what);
143 $checked = ($checkall == 1) ?
' checked' : '';
145 if (sizeof($index_order)){
146 foreach ($index_order as $index_order_part) {
147 switch ($index_order_part) {
148 case 1: /* checkbox */
149 echo " <td bgcolor=\"$hlt_color\" align=center>"
150 . "<input type=checkbox name=\"msg[$t]\" value="
151 . $msg["ID"]."$checked></TD>\n";
154 echo " <td bgcolor=\"$hlt_color\">$italic$bold$flag$fontstr"
155 . "$senderName$fontstr_end$flag_end$bold_end$italic_end</td>\n";
158 echo " <td nowrap bgcolor=\"$hlt_color\"><center>$bold$flag$fontstr"
159 . $msg["DATE_STRING"]
160 . "$fontstr_end$flag_end$bold_end</center></td>\n";
162 case 4: /* subject */
163 echo " <td bgcolor=\"$hlt_color\">$bold";
164 if ($thread_sort_messages == 1) {
165 if (isset($indent_array[$msg["ID"]])) {
166 echo str_repeat(" ",$indent_array[$msg["ID"]]);
169 echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id="
171 . "&startMessage=$start_msg&show_more=0$search_stuff\"";
172 do_hook("subject_link");
173 if ($subject != $msg['SUBJECT']) {
174 $title = get_html_translation_table(HTML_SPECIALCHARS
);
175 $title = array_flip($title);
176 $title = strtr($msg['SUBJECT'], $title);
177 $title = str_replace('"', "''", $title);
178 echo " title=\"$title\"";
180 echo ">$flag$subject$flag_end</a>$bold_end</td>\n";
184 echo " <td bgcolor=\"$hlt_color\" align=center nowrap><b><small>\n";
185 if (isset($msg['FLAG_ANSWERED']) && $msg['FLAG_ANSWERED'] == true) {
189 if ($msg['TYPE0'] == 'multipart') {
193 if ($default_use_priority) {
194 if ( ($msg['PRIORITY'] == 1) ||
($msg['PRIORITY'] == 2) ) {
195 echo "<font color=\"$color[1]\">!</font>\n";
198 if ($msg['PRIORITY'] == 5) {
199 echo "<font color=\"$color[8]\">?</font>\n";
203 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'] == true) {
204 echo "<font color=\"$color[1]\">D</font>\n";
210 echo "</small></b></td>\n";
213 echo " <td bgcolor=\"$hlt_color\">$bold$fontstr"
214 . show_readable_size($msg['SIZE']) . "$fontstr_end$bold_end</td>\n";
223 * This function loops through a group of messages in the mailbox
224 * and shows them to the user.
226 function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
227 $start_msg, $sort, $color, $show_num,
229 global $msgs, $msort,
230 $sent_folder, $draft_folder,
231 $message_highlight_list,
232 $auto_expunge, $thread_sort_messages, $allow_server_sort,
233 $data_dir, $username, $server_sort_order;
235 /* if $start_msg is lower than $num_msgs, we probably deleted all messages
236 * in the last page. We need to re-adjust the start_msg
239 if($start_msg > $num_msgs) {
240 $start_msg -= $show_num;
246 /* This code and the next if() block check for
247 * server-side sorting methods. The $id array is
248 * formatted and $sort is set to 6 to disable
249 * SM internal sorting
251 if ($thread_sort_messages == 1) {
252 $id = get_thread_sort($imapConnection);
254 echo '<b><small><center><font color=red>Thread sorting is not'.
255 ' supported by your IMAP server.<br>Please report this'.
256 ' to the system administrator.</center></small></b>';
257 $thread_sort_messages = 0;
262 if ($start_msg +
($show_num - 1) < $num_msgs) {
263 $end_msg = $start_msg +
($show_num-1);
266 $end_msg = $num_msgs;
268 $id = array_slice($id, ($start_msg-1), ($end_msg));
272 if ($allow_server_sort == TRUE && $thread_sort_messages != 1) {
273 $server_sort_order = $sort;
274 $id = sqimap_get_sort_order($imapConnection, $server_sort_order);
276 echo '<b><small><center><font color=red>Server-side sorting'.
277 ' is not supported by your IMAP server.<br>Please report this'.
278 ' to the system administrator.</center></small></b>';
279 $sort = $server_sort_order;
280 $allow_server_sort = FALSE;
285 if ($start_msg +
($show_num - 1) < $num_msgs) {
286 $end_msg = $start_msg +
($show_num-1);
289 $end_msg = $num_msgs;
291 $id = array_slice($id, ($start_msg-1), ($end_msg));
295 /* If autoexpunge is turned on, then do it now. */
296 if ($auto_expunge == true) {
297 sqimap_mailbox_expunge($imapConnection, $mailbox, false);
299 sqimap_mailbox_select($imapConnection, $mailbox);
300 $issent = handleAsSent($mailbox);
302 /* If it is sorted... */
303 if ($num_msgs >= 1) {
305 $id = range(1, $num_msgs);
307 elseif ($thread_sort_messages != 1 && $allow_server_sort != TRUE && $sort == 6) {
308 /* if it's not sorted */
309 if ($start_msg +
($show_num - 1) < $num_msgs){
310 $end_msg = $start_msg +
($show_num - 1);
312 $end_msg = $num_msgs;
314 if ($end_msg < $start_msg) {
315 $start_msg = $start_msg - $show_num;
316 if ($start_msg < 1) {
321 $real_startMessage = $num_msgs - $start_msg +
1;
322 $real_endMessage = $num_msgs - $start_msg - $show_num +
2;
323 if ($real_endMessage <= 0) {
324 $real_endMessage = 1;
326 $id = array_reverse(range($real_endMessage, $real_startMessage));
328 $msgs_list = sqimap_get_small_header_list($imapConnection, $id, $issent);
329 // $flags = sqimap_get_flags_list($imapConnection, $id, $issent);
330 if (sizeof($msgs_list)){
331 foreach ($msgs_list as $hdr) {
332 $from[] = $hdr->from
;
333 $date[] = $hdr->date
;
334 $subject[] = $hdr->subject
;
336 $priority[] = $hdr->priority
;
338 $size[] = $hdr->size
;
339 $type[] = $hdr->type0
;
340 $flag_deleted[] = $hdr->flag_deleted
;
341 $flag_answered[] = $hdr->flag_answered
;
342 $flag_seen[] = $hdr->flag_seen
;
343 $flag_flagged[] = $hdr->flag_flagged
;
349 $end = $start_msg +
$show_num - 1;
350 if ($num_msgs < $show_num) {
351 $end_loop = $num_msgs;
352 } else if ($end > $num_msgs) {
353 $end_loop = $num_msgs - $start_msg +
1;
355 $end_loop = $show_num;
361 while ($j < $end_loop) {
362 if (isset($date[$j])) {
363 $date[$j] = str_replace(' ', ' ', $date[$j]);
364 $tmpdate = explode(' ', trim($date[$j]));
366 $tmpdate = $date = array('', '', '', '', '', '');
369 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
370 $messages[$j]['DATE_STRING'] =
371 getDateString($messages[$j]['TIME_STAMP']);
372 $messages[$j]['ID'] = $id[$j];
373 $messages[$j]['FROM'] = decodeHeader($from[$j]);
374 $messages[$j]['FROM-SORT'] =
375 strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
376 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
377 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
378 $messages[$j]['TO'] = decodeHeader($to[$j]);
379 $messages[$j]['PRIORITY'] = $priority[$j];
380 $messages[$j]['CC'] = $cc[$j];
381 $messages[$j]['SIZE'] = $size[$j];
382 $messages[$j]['TYPE0'] = $type[$j];
383 $messages[$j]['FLAG_DELETED'] = $flag_deleted[$j];
384 $messages[$j]['FLAG_ANSWERED'] = $flag_answered[$j];
385 $messages[$j]['FLAG_SEEN'] = $flag_seen[$j];
386 $messages[$j]['FLAG_FLAGGED'] = $flag_flagged[$j];
390 * fix SUBJECT-SORT to remove Re:
394 * TODO: i18n should be incorporated here. E.g. we catch the ones
395 * we know about, but also define in i18n what the localized
396 * "Re: " is for this or that locale.
398 if (preg_match("/^(vedr|sv|re|aw):\s*(.*)$/si",
399 $messages[$j]['SUBJECT-SORT'], $matches)){
400 $messages[$j]['SUBJECT-SORT'] = $matches[2];
404 while ($num < count($flags[$j])) {
405 if ($flags[$j][$num] == 'Deleted') {
406 $messages[$j]['FLAG_DELETED'] = true;
407 } else if ($flags[$j][$num] == 'Answered') {
408 $messages[$j]['FLAG_ANSWERED'] = true;
409 } else if ($flags[$j][$num] == 'Seen') {
410 $messages[$j]['FLAG_SEEN'] = true;
411 } else if ($flags[$j][$num] == 'Flagged') {
412 $messages[$j]['FLAG_FLAGGED'] = true;
422 * Only ignore messages flagged as deleted if we are
423 * using a trash folder or auto_expunge
425 if (((isset($move_to_trash) && $move_to_trash)
426 ||
(isset($auto_expunge) && $auto_expunge))
429 /* Find and remove the ones that are deleted */
433 while ($j < $num_msgs) {
434 if (isset($messages[$j]['FLAG_DELETED'])
435 && $messages[$j]['FLAG_DELETED'] == true) {
439 $msgs[$i] = $messages[$j];
446 if (!isset($messages)) {
453 /* There's gotta be messages in the array for it to sort them. */
454 if (($num_msgs > 0) && (!$use_cache)) {
463 session_unregister('msgs');
464 if (($sort == 0) ||
($sort == 1)) {
465 $msort = array_cleave ($msgs, 'TIME_STAMP');
466 } elseif (($sort == 2) ||
($sort == 3)) {
467 $msort = array_cleave ($msgs, 'FROM-SORT');
468 } elseif (($sort == 4) ||
($sort == 5)) {
469 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
481 session_register('msort');
482 } elseif ($thread_sort_messages == 1 ||
$allow_server_sort == TRUE) {
484 session_unregister('msgs');
485 session_register('msort');
487 displayMessageArray($imapConnection, $num_msgs, $start_msg, $msgs,
488 $msort, $mailbox, $sort, $color,$show_num);
490 * TODO: Switch to using $_SESSION[] whenever we ditch the 4.0.x series.
492 session_register('msgs');
495 /* Generic function to convert the msgs array into an HTML table. */
496 function displayMessageArray($imapConnection, $num_msgs, $start_msg,
497 &$msgs, $msort, $mailbox, $sort, $color,
499 global $folder_prefix, $sent_folder,
500 $imapServerAddress, $data_dir, $username, $use_mailbox_cache,
501 $index_order, $real_endMessage, $real_startMessage, $checkall,
502 $indent_array, $thread_sort_messages, $allow_server_sort, $server_sort_order;
504 /* If cache isn't already set, do it now. */
505 if (!session_is_registered('msgs')) {
506 session_register('msgs');
508 if (!session_is_registered('msort')) {
509 session_register('msort');
512 if ($start_msg +
($show_num - 1) < $num_msgs){
513 $end_msg = $start_msg +
($show_num - 1);
515 $end_msg = $num_msgs;
518 if ($end_msg < $start_msg) {
519 $start_msg = $start_msg - $show_num;
520 if ($start_msg < 1) {
525 $urlMailbox = urlencode($mailbox);
527 do_hook('mailbox_index_before');
529 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
530 $paginator_str = get_paginator_str($urlMailbox, $start_msg, $end_msg,
531 $num_msgs, $show_num, $sort);
537 /* get indent level for subject display */
538 if ($thread_sort_messages == 1 ) {
539 $indent_array = get_parent_level($imapConnection);
541 $fstring = "move_messages.php?msg=$msg&mailbox=$urlMailbox"
542 . "&startMessage=$start_msg";
543 mail_message_listing_beginning($imapConnection, $fstring,
544 $mailbox, $sort, $msg_cnt_str,
545 $paginator_str, $start_msg);
547 $groupNum = $start_msg %
($show_num - 1);
548 $real_startMessage = $start_msg;
550 if ($end_msg - $start_msg < $show_num - 1) {
551 $end_msg = $end_msg - $start_msg +
1;
553 } else if ($start_msg > $show_num) {
554 $end_msg = $show_num;
558 $endVar = $end_msg +
1;
561 * Loop through and display the info for each message.
562 * ($t is used for the checkbox number)
565 if ($num_msgs == 0) {
566 /* if there's no messages in this folder */
567 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN="
568 . count($index_order) . ">\n"
569 . " <CENTER><BR><B>". _("THIS FOLDER IS EMPTY")
570 . "</B><BR> </CENTER>\n"
572 } elseif ($start_msg == $end_msg) {
573 /* if there's only one message in the box, handle it differently. */
585 } while (isset ($key) && ($k < $i));
586 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort,
587 $real_startMessage, 0, 0);
596 } while (isset ($key) && ($k < $i));
598 printMessageInfo($imapConnection, $t, $i, $key, $mailbox,
599 $sort, $real_startMessage, 0, 0);
604 } while ($i && $i < $endVar);
608 . "<table bgcolor=\"$color[9]\" width=\"100%\" border=0 cellpadding=1 "
609 . "cellspacing=1><tr BGCOLOR=\"$color[4]\"><td>"
610 . "<table width=\"100%\" BGCOLOR=\"$color[4]\" border=0 cellpadding=1 "
611 . "cellspacing=0><tr><td>$paginator_str</td>"
612 . "<td align=right>$msg_cnt_str</td></tr></table>"
613 . "</td></tr></table>";
614 /* End of message-list table */
616 do_hook('mailbox_index_after');
617 echo "</TABLE></FORM>\n";
621 * Displays the standard message list header. To finish the table,
622 * you need to do a "</table></table>";
624 * $moveURL is the URL to submit the delete/move form to
625 * $mailbox is the current mailbox
626 * $sort is the current sorting method (-1 for no sorting available [searches])
627 * $Message is a message that is centered on top of the list
628 * $More is a second line that is left aligned
631 function mail_message_listing_beginning ($imapConnection, $moveURL,
632 $mailbox = '', $sort = -1,
634 $paginator = ' ',
636 global $color, $index_order, $auto_expunge, $move_to_trash, $base_uri,
637 $checkall, $sent_folder, $draft_folder, $thread_sort_messages,
638 $allow_thread_sort, $allow_server_sort, $server_sort_order,
641 $urlMailbox = urlencode($mailbox);
644 * This is the beginning of the message list table.
645 * It wraps around all messages
647 echo "<FORM name=\"messageList\" method=post action=\"$moveURL\">\n"
648 . "<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLPADDING=\"1\" "
649 . "CELLSPACING=\"0\">\n<TR BGCOLOR=\"$color[0]\"><TD>"
650 . " <TABLE BGCOLOR=\"$color[4]\" width=\"100%\" CELLPADDING=\"2\" "
651 . "CELLSPACING=\"0\" BORDER=\"0\"><TR>\n"
652 . " <TD ALIGN=LEFT>$paginator\n";
654 echo " <TD ALIGN=RIGHT>$msg_cnt_str</TD>\n"
657 . "<TR><TD BGCOLOR=\"$color[0]\">\n"
658 . "<TABLE BGCOLOR=\"$color[0]\" BORDER=0 cellpadding=0 "
659 . "cellspacing=0 width=\"100%\">\n"
661 . " <TD ALIGN=LEFT VALIGN=MIDDLE NOWRAP>\n"
662 . ' <SMALL> ' . _("Move Selected To:") . "</SMALL>\n"
664 . " <TD ALIGN=RIGHT NOWRAP>\n"
665 . ' <SMALL> ' . _("Transform Selected Messages")
666 . ": </SMALL><BR>\n"
670 . " <TD ALIGN=\"LEFT\" VALIGN=\"MIDDLE\" NOWRAP>\n"
671 . ' <SMALL> <TT><SELECT NAME="targetMailbox">';
673 $boxes = sqimap_mailbox_list($imapConnection);
674 foreach ($boxes as $boxes_part) {
675 if (!in_array('noselect', $boxes_part['flags'])) {
676 $box = $boxes_part['unformatted'];
677 $box2 = str_replace(' ', ' ', imap_utf7_decode_local($boxes_part['unformatted-disp']));
678 if( $box2 == 'INBOX' ) {
681 if ($lastTargetMailbox == $box) {
682 echo " <OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
685 echo " <OPTION VALUE=\"$box\">$box2</OPTION>\n";
689 echo ' </SELECT></TT> '
690 . '<INPUT TYPE="SUBMIT" NAME="moveButton" VALUE="' . _("Move") . '"> '
691 . '<INPUT TYPE="SUBMIT" NAME="attache" VALUE="' . _("Forward")
692 . "\"> \n" . "</SMALL>\n";
695 . " <TD ALIGN=\"RIGHT\" NOWRAP>";
696 if (!$auto_expunge) {
697 echo '<INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="' . _("Expunge")
698 . '"> ' . _("mailbox") . ' ';
700 echo '<INPUT TYPE="SUBMIT" NAME="markRead" VALUE="' . _("Read") . '">'
701 . '<INPUT TYPE="SUBMIT" NAME="markUnread" VALUE="' . _("Unread") . '">'
702 . '<INPUT TYPE="SUBMIT" VALUE="' . _("Delete") . '"> '
706 /* draws thread sorting links */
707 if ($allow_thread_sort == TRUE) {
708 if ($thread_sort_messages == 1 ) {
710 $thread_name = _("Unthread View");
712 elseif ($thread_sort_messages == 0) {
714 $thread_name = _("Thread View");
716 echo '<tr><td> <a href=' . "$base_uri" . 'src/right_main.php?sort='
717 . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
718 . '&mailbox=' . urlencode($mailbox) . '><small>' . $thread_name
719 . '</a></small> </td></tr>';
723 do_hook('mailbox_form_before');
725 . "<TR><TD BGCOLOR=\"$color[0]\">"
726 . '<TABLE WIDTH="100%" BORDER=0 CELLPADDING=2 CELLSPACING=';
727 if ($GLOBALS['alt_index_colors']){
732 echo " BGCOLOR=\"$color[0]\">"
733 . "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
734 /* if using server sort we highjack the
735 * the $sort var and use $server_sort_order
736 * instead. but here we reset sort for a bit
739 if ($allow_server_sort == TRUE) {
740 $sort = $server_sort_order;
742 /* Print the headers. */
743 for ($i=1; $i <= count($index_order); $i++
) {
744 switch ($index_order[$i]) {
745 case 1: /* checkbox */
747 echo ' <TD WIDTH="1%"><B> </B></TD>';
750 if (handleAsSent($mailbox)) {
751 echo ' <TD WIDTH="25%"><B>' . _("To") . '</B>';
753 echo ' <TD WIDTH="25%"><B>' . _("From") . '</B>';
755 if ($allow_thread_sort != TRUE ||
$thread_sort_messages != 1) {
756 ShowSortButton($sort, $mailbox, 2, 3);
761 echo ' <TD NOWRAP WIDTH="5%"><B>' . _("Date") . '</B>';
762 if ($allow_thread_sort != TRUE ||
$thread_sort_messages != 1) {
763 ShowSortButton($sort, $mailbox, 0, 1);
767 case 4: /* subject */
768 echo ' <TD><B>' . _("Subject") . '</B> ';
769 if ($allow_thread_sort != TRUE ||
$thread_sort_messages != 1) {
770 ShowSortButton($sort, $mailbox, 4, 5);
775 echo ' <TD WIDTH="5%"><b>' . _("Size") . "</b></TD>\n";
779 /* if using server-sorting,
780 * send sort back to 6
782 if ($allow_server_sort == TRUE) {
789 * This function shows the sort button. Isn't this a good comment?
791 function ShowSortButton($sort, $mailbox, $Up, $Down) {
792 /* Figure out which image we want to use. */
793 if ($sort != $Up && $sort != $Down) {
794 $img = 'sort_none.png';
796 } elseif ($sort == $Up) {
797 $img = 'up_pointer.png';
800 $img = 'down_pointer.png';
804 /* Now that we have everything figured out, show the actual button. */
805 echo ' <a href="right_main.php?newsort=' . $which
806 . '&startMessage=1&mailbox=' . urlencode($mailbox)
807 . '"><IMG SRC="../images/' . $img
808 . '" BORDER=0 WIDTH=12 HEIGHT=10 ALT="sort"></a>';
811 function get_selectall_link($start_msg, $sort) {
812 global $checkall, $what, $where, $mailbox, $javascript_on;
813 global $PHP_SELF, $PG_SHOWNUM;
816 if ($javascript_on) {
818 '<script language="JavaScript" type="text/javascript">'
820 . "function CheckAll() {\n"
821 . " for (var i = 0; i < document.messageList.elements.length; i++) {\n"
822 . " if(document.messageList.elements[i].type == 'checkbox'){\n"
823 . " document.messageList.elements[i].checked = "
824 . " !(document.messageList.elements[i].checked);\n"
829 . '</script><a href="#" onClick="CheckAll();">' . _("Toggle All")
832 if (strpos($PHP_SELF, "?")) {
833 $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($mailbox)
834 . "&startMessage=$start_msg&sort=$sort&checkall=";
836 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
837 . "&startMessage=$start_msg&sort=$sort&checkall=";
839 if (isset($checkall) && $checkall == '1') {
845 if (isset($where) && isset($what)) {
846 $result .= '&where=' . urlencode($where)
847 . '&what=' . urlencode($what);
852 if (isset($checkall) && ($checkall == '1')) {
853 $result .= _("Unselect All");
855 $result .= _("Select All");
861 /* Return our final result. */
866 * This function computes the "Viewing Messages..." string.
868 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
869 /* Compute the $msg_cnt_str. */
871 if ($start_msg < $end_msg) {
872 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"),
873 $start_msg, $end_msg, $num_msgs);
874 } else if ($start_msg == $end_msg) {
875 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
880 /* Return our result string. */
885 * Generate a paginator link.
887 function get_paginator_link($box, $start_msg, $use, $text) {
888 $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
889 . "&startMessage=$start_msg&mailbox=$box\" "
890 . "TARGET=\"right\">$text</A>";
895 * This function computes the paginator string.
897 function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
899 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
901 /* Initialize paginator string chunks. */
908 /* Create simple strings that will be creating the paginator. */
909 $spc = ' '; /* This will be used as a space. */
910 $sep = '|'; /* This will be used as a seperator. */
912 /* Get some paginator preference values. */
913 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON
);
914 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
);
916 /* Make sure that our start message number is not too big. */
917 $start_msg = min($start_msg, $num_msgs);
919 /* Decide whether or not we will use the mailbox cache. */
920 /* Not sure why $use_mailbox_cache is even passed in. */
927 /* Compute the starting message of the previous and next page group. */
928 $next_grp = $start_msg +
$show_num;
929 $prev_grp = $start_msg - $show_num;
931 /* Compute the basic previous and next strings. */
932 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
933 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
934 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
935 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
936 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
937 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
938 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
939 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
940 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
943 /* Page selector block. Following code computes page links. */
944 if ($pg_sel && ($num_msgs > $show_num)) {
945 /* Most importantly, what is the current page!!! */
946 $cur_pg = intval($start_msg / $show_num) +
1;
948 /* Compute total # of pages and # of paginator page links. */
949 $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
950 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
952 /* Compute the size of the four quarters of the page links. */
954 /* If we can, just show all the pages. */
955 if (($tot_pgs - 1) <= $pg_max) {
956 $q1_pgs = $cur_pg - 1;
957 $q2_pgs = $q3_pgs = 0;
958 $q4_pgs = $tot_pgs - $cur_pg;
960 /* Otherwise, compute some magic to choose the four quarters. */
963 * Compute the magic base values. Added together,
964 * these values will always equal to the $pag_pgs.
965 * NOTE: These are DEFAULT values and do not take
966 * the current page into account. That is below.
968 $q1_pgs = floor($vis_pgs/4);
969 $q2_pgs = round($vis_pgs/4, 0);
970 $q3_pgs = ceil($vis_pgs/4);
971 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
973 /* Adjust if the first quarter contains the current page. */
974 if (($cur_pg - $q1_pgs) < 1) {
975 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) +
$q2_pgs;
976 $q1_pgs = $cur_pg - 1;
978 $q3_pgs +
= ceil($extra_pgs / 2);
979 $q4_pgs +
= floor($extra_pgs / 2);
981 /* Adjust if the first and second quarters intersect. */
982 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
983 $extra_pgs = $q2_pgs;
984 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
985 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
986 $q3_pgs +
= ceil($extra_pgs / 2);
987 $q4_pgs +
= floor($extra_pgs / 2);
989 /* Adjust if the fourth quarter contains the current page. */
990 } else if (($cur_pg +
$q4_pgs) >= $tot_pgs) {
991 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) +
$q3_pgs;
993 $q4_pgs = $tot_pgs - $cur_pg;
994 $q1_pgs +
= floor($extra_pgs / 2);
995 $q2_pgs +
= ceil($extra_pgs / 2);
997 /* Adjust if the third and fourth quarter intersect. */
998 } else if (($cur_pg +
$q3_pgs +
1) >= ($tot_pgs - $q4_pgs +
1)) {
999 $extra_pgs = $q3_pgs;
1000 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1001 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1002 $q1_pgs +
= floor($extra_pgs / 2);
1003 $q2_pgs +
= ceil($extra_pgs / 2);
1008 * I am leaving this debug code here, commented out, because
1009 * it is a really nice way to see what the above code is doing.
1010 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
1011 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
1014 /* Print out the page links from the compute page quarters. */
1016 /* Start with the first quarter. */
1017 if (($q1_pgs == 0) && ($cur_pg > 1)) {
1018 $pg_str .= "...$spc";
1020 for ($pg = 1; $pg <= $q1_pgs; ++
$pg) {
1021 $start = (($pg-1) * $show_num) +
1;
1022 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1024 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
1025 $pg_str .= "...$spc";
1029 /* Continue with the second quarter. */
1030 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++
$pg) {
1031 $start = (($pg-1) * $show_num) +
1;
1032 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1035 /* Now print the current page. */
1036 $pg_str .= $cur_pg . $spc;
1038 /* Next comes the third quarter. */
1039 for ($pg = $cur_pg +
1; $pg <= $cur_pg +
$q3_pgs; ++
$pg) {
1040 $start = (($pg-1) * $show_num) +
1;
1041 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1044 /* And last, print the forth quarter page links. */
1045 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
1046 $pg_str .= "...$spc";
1048 if (($tot_pgs - $q4_pgs) > ($cur_pg +
$q3_pgs)) {
1049 $pg_str .= "...$spc";
1051 for ($pg = $tot_pgs - $q4_pgs +
1; $pg <= $tot_pgs; ++
$pg) {
1052 $start = (($pg-1) * $show_num) +
1;
1053 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1056 } else if ($PG_SHOWNUM == 999999) {
1057 $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
1058 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1059 . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc;
1062 /* If necessary, compute the 'show all' string. */
1063 if (($prv_str != '') ||
($nxt_str != '')) {
1064 $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
1065 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1066 . "TARGET=\"right\">" . _("Show All") . '</A>';
1069 /* Last but not least, get the value for the toggle all link. */
1070 $tgl_str = get_selectall_link($start_msg, $sort);
1072 /* Put all the pieces of the paginator string together. */
1074 * Hairy code... But let's leave it like it is since I am not certain
1075 * a different approach would be any easier to read. ;)
1078 $result .= ($prv_str != '' ?
$prv_str . $spc . $sep . $spc : '');
1079 $result .= ($nxt_str != '' ?
$nxt_str . $spc . $sep . $spc : '');
1080 $result .= ($pg_str != '' ?
$pg_str : '');
1081 $result .= ($all_str != '' ?
$sep . $spc . $all_str . $spc : '');
1082 $result .= ($result != '' ?
$sep . $spc . $tgl_str: $tgl_str);
1084 /* If the resulting string is blank, return a non-breaking space. */
1085 if ($result == '') {
1089 /* Return our final magical paginator string. */
1093 function processSubject($subject) {
1094 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1096 return _("(no subject)");
1098 if (strlen($subject) <= 55)
1101 $ent_strlen=strlen($subject);
1105 * see if this is entities-encoded string
1106 * If so, Iterate through the whole string, find out
1107 * the real number of characters, and if more
1108 * than 55, substr with an updated trim value.
1110 while ( (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1111 (($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false) ) {
1112 $trim_val +
= ($ent_loc_end-$ent_loc)+
1;
1113 $ent_strlen -= $ent_loc_end-$ent_loc;
1114 $ent_offset = $ent_loc_end+
1;
1117 if ($ent_strlen <= 55){
1121 return substr($subject, 0, $trim_val) . '...';
1124 function handleAsSent($mailbox) {
1125 global $sent_folder, $draft_folder, $handleAsSent_result;
1127 /* First check if this is the sent or draft folder. */
1128 $handleAsSent_result = (($mailbox == $sent_folder)
1129 ||
($mailbox == $draft_folder));
1131 /* Then check the result of the handleAsSent hook. */
1132 do_hook('check_handleAsSent_result', $mailbox);
1134 /* And return the result. */
1135 return ($handleAsSent_result);