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 = imap_utf7_decode_local(
678 str_replace(' ', ' ', $boxes_part['unformatted-disp']));
679 if( $box2 == 'INBOX' ) {
682 if ($lastTargetMailbox == $box) {
683 echo " <OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
686 echo " <OPTION VALUE=\"$box\">$box2</OPTION>\n";
690 echo ' </SELECT></TT> '
691 . '<INPUT TYPE="SUBMIT" NAME="moveButton" VALUE="' . _("Move") . '"> '
692 . '<INPUT TYPE="SUBMIT" NAME="attache" VALUE="' . _("Forward")
693 . "\"> \n" . "</SMALL>\n";
696 . " <TD ALIGN=\"RIGHT\" NOWRAP>";
697 if (!$auto_expunge) {
698 echo '<INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="' . _("Expunge")
699 . '"> ' . _("mailbox") . ' ';
701 echo '<INPUT TYPE="SUBMIT" NAME="markRead" VALUE="' . _("Read") . '">'
702 . '<INPUT TYPE="SUBMIT" NAME="markUnread" VALUE="' . _("Unread") . '">'
703 . '<INPUT TYPE="SUBMIT" VALUE="' . _("Delete") . '"> '
707 /* draws thread sorting links */
708 if ($allow_thread_sort == TRUE) {
709 if ($thread_sort_messages == 1 ) {
711 $thread_name = _("Unthread View");
713 elseif ($thread_sort_messages == 0) {
715 $thread_name = _("Thread View");
717 echo '<tr><td> <a href=' . "$base_uri" . 'src/right_main.php?sort='
718 . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
719 . '&mailbox=' . urlencode($mailbox) . '><small>' . $thread_name
720 . '</a></small> </td></tr>';
724 do_hook('mailbox_form_before');
726 . "<TR><TD BGCOLOR=\"$color[0]\">"
727 . '<TABLE WIDTH="100%" BORDER=0 CELLPADDING=2 CELLSPACING=';
728 if ($GLOBALS['alt_index_colors']){
733 echo " BGCOLOR=\"$color[0]\">"
734 . "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
735 /* if using server sort we highjack the
736 * the $sort var and use $server_sort_order
737 * instead. but here we reset sort for a bit
740 if ($allow_server_sort == TRUE) {
741 $sort = $server_sort_order;
743 /* Print the headers. */
744 for ($i=1; $i <= count($index_order); $i++
) {
745 switch ($index_order[$i]) {
746 case 1: /* checkbox */
748 echo ' <TD WIDTH="1%"><B> </B></TD>';
751 if (handleAsSent($mailbox)) {
752 echo ' <TD WIDTH="25%"><B>' . _("To") . '</B>';
754 echo ' <TD WIDTH="25%"><B>' . _("From") . '</B>';
756 if ($allow_thread_sort != TRUE ||
$thread_sort_messages != 1) {
757 ShowSortButton($sort, $mailbox, 2, 3);
762 echo ' <TD NOWRAP WIDTH="5%"><B>' . _("Date") . '</B>';
763 if ($allow_thread_sort != TRUE ||
$thread_sort_messages != 1) {
764 ShowSortButton($sort, $mailbox, 0, 1);
768 case 4: /* subject */
769 echo ' <TD><B>' . _("Subject") . '</B> ';
770 if ($allow_thread_sort != TRUE ||
$thread_sort_messages != 1) {
771 ShowSortButton($sort, $mailbox, 4, 5);
776 echo ' <TD WIDTH="5%"><b>' . _("Size") . "</b></TD>\n";
780 /* if using server-sorting,
781 * send sort back to 6
783 if ($allow_server_sort == TRUE) {
790 * This function shows the sort button. Isn't this a good comment?
792 function ShowSortButton($sort, $mailbox, $Up, $Down) {
793 /* Figure out which image we want to use. */
794 if ($sort != $Up && $sort != $Down) {
795 $img = 'sort_none.png';
797 } elseif ($sort == $Up) {
798 $img = 'up_pointer.png';
801 $img = 'down_pointer.png';
805 /* Now that we have everything figured out, show the actual button. */
806 echo ' <a href="right_main.php?newsort=' . $which
807 . '&startMessage=1&mailbox=' . urlencode($mailbox)
808 . '"><IMG SRC="../images/' . $img
809 . '" BORDER=0 WIDTH=12 HEIGHT=10 ALT="sort"></a>';
812 function get_selectall_link($start_msg, $sort) {
813 global $checkall, $what, $where, $mailbox, $javascript_on;
814 global $PHP_SELF, $PG_SHOWNUM;
817 if ($javascript_on) {
819 '<script language="JavaScript" type="text/javascript">'
821 . "function CheckAll() {\n"
822 . " for (var i = 0; i < document.messageList.elements.length; i++) {\n"
823 . " if(document.messageList.elements[i].type == 'checkbox'){\n"
824 . " document.messageList.elements[i].checked = "
825 . " !(document.messageList.elements[i].checked);\n"
830 . '</script><a href="#" onClick="CheckAll();">' . _("Toggle All")
833 if (strpos($PHP_SELF, "?")) {
834 $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($mailbox)
835 . "&startMessage=$start_msg&sort=$sort&checkall=";
837 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
838 . "&startMessage=$start_msg&sort=$sort&checkall=";
840 if (isset($checkall) && $checkall == '1') {
846 if (isset($where) && isset($what)) {
847 $result .= '&where=' . urlencode($where)
848 . '&what=' . urlencode($what);
853 if (isset($checkall) && ($checkall == '1')) {
854 $result .= _("Unselect All");
856 $result .= _("Select All");
862 /* Return our final result. */
867 * This function computes the "Viewing Messages..." string.
869 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
870 /* Compute the $msg_cnt_str. */
872 if ($start_msg < $end_msg) {
873 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"),
874 $start_msg, $end_msg, $num_msgs);
875 } else if ($start_msg == $end_msg) {
876 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
881 /* Return our result string. */
886 * Generate a paginator link.
888 function get_paginator_link($box, $start_msg, $use, $text) {
889 $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
890 . "&startMessage=$start_msg&mailbox=$box\" "
891 . "TARGET=\"right\">$text</A>";
896 * This function computes the paginator string.
898 function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
900 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
902 /* Initialize paginator string chunks. */
909 /* Create simple strings that will be creating the paginator. */
910 $spc = ' '; /* This will be used as a space. */
911 $sep = '|'; /* This will be used as a seperator. */
913 /* Get some paginator preference values. */
914 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON
);
915 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
);
917 /* Make sure that our start message number is not too big. */
918 $start_msg = min($start_msg, $num_msgs);
920 /* Decide whether or not we will use the mailbox cache. */
921 /* Not sure why $use_mailbox_cache is even passed in. */
928 /* Compute the starting message of the previous and next page group. */
929 $next_grp = $start_msg +
$show_num;
930 $prev_grp = $start_msg - $show_num;
932 /* Compute the basic previous and next strings. */
933 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
934 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
935 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
936 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
937 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
938 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
939 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
940 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
941 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
944 /* Page selector block. Following code computes page links. */
945 if ($pg_sel && ($num_msgs > $show_num)) {
946 /* Most importantly, what is the current page!!! */
947 $cur_pg = intval($start_msg / $show_num) +
1;
949 /* Compute total # of pages and # of paginator page links. */
950 $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
951 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
953 /* Compute the size of the four quarters of the page links. */
955 /* If we can, just show all the pages. */
956 if (($tot_pgs - 1) <= $pg_max) {
957 $q1_pgs = $cur_pg - 1;
958 $q2_pgs = $q3_pgs = 0;
959 $q4_pgs = $tot_pgs - $cur_pg;
961 /* Otherwise, compute some magic to choose the four quarters. */
964 * Compute the magic base values. Added together,
965 * these values will always equal to the $pag_pgs.
966 * NOTE: These are DEFAULT values and do not take
967 * the current page into account. That is below.
969 $q1_pgs = floor($vis_pgs/4);
970 $q2_pgs = round($vis_pgs/4, 0);
971 $q3_pgs = ceil($vis_pgs/4);
972 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
974 /* Adjust if the first quarter contains the current page. */
975 if (($cur_pg - $q1_pgs) < 1) {
976 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) +
$q2_pgs;
977 $q1_pgs = $cur_pg - 1;
979 $q3_pgs +
= ceil($extra_pgs / 2);
980 $q4_pgs +
= floor($extra_pgs / 2);
982 /* Adjust if the first and second quarters intersect. */
983 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
984 $extra_pgs = $q2_pgs;
985 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
986 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
987 $q3_pgs +
= ceil($extra_pgs / 2);
988 $q4_pgs +
= floor($extra_pgs / 2);
990 /* Adjust if the fourth quarter contains the current page. */
991 } else if (($cur_pg +
$q4_pgs) >= $tot_pgs) {
992 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) +
$q3_pgs;
994 $q4_pgs = $tot_pgs - $cur_pg;
995 $q1_pgs +
= floor($extra_pgs / 2);
996 $q2_pgs +
= ceil($extra_pgs / 2);
998 /* Adjust if the third and fourth quarter intersect. */
999 } else if (($cur_pg +
$q3_pgs +
1) >= ($tot_pgs - $q4_pgs +
1)) {
1000 $extra_pgs = $q3_pgs;
1001 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1002 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1003 $q1_pgs +
= floor($extra_pgs / 2);
1004 $q2_pgs +
= ceil($extra_pgs / 2);
1009 * I am leaving this debug code here, commented out, because
1010 * it is a really nice way to see what the above code is doing.
1011 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
1012 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
1015 /* Print out the page links from the compute page quarters. */
1017 /* Start with the first quarter. */
1018 if (($q1_pgs == 0) && ($cur_pg > 1)) {
1019 $pg_str .= "...$spc";
1021 for ($pg = 1; $pg <= $q1_pgs; ++
$pg) {
1022 $start = (($pg-1) * $show_num) +
1;
1023 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1025 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
1026 $pg_str .= "...$spc";
1030 /* Continue with the second quarter. */
1031 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++
$pg) {
1032 $start = (($pg-1) * $show_num) +
1;
1033 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1036 /* Now print the current page. */
1037 $pg_str .= $cur_pg . $spc;
1039 /* Next comes the third quarter. */
1040 for ($pg = $cur_pg +
1; $pg <= $cur_pg +
$q3_pgs; ++
$pg) {
1041 $start = (($pg-1) * $show_num) +
1;
1042 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1045 /* And last, print the forth quarter page links. */
1046 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
1047 $pg_str .= "...$spc";
1049 if (($tot_pgs - $q4_pgs) > ($cur_pg +
$q3_pgs)) {
1050 $pg_str .= "...$spc";
1052 for ($pg = $tot_pgs - $q4_pgs +
1; $pg <= $tot_pgs; ++
$pg) {
1053 $start = (($pg-1) * $show_num) +
1;
1054 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1057 } else if ($PG_SHOWNUM == 999999) {
1058 $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
1059 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1060 . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc;
1063 /* If necessary, compute the 'show all' string. */
1064 if (($prv_str != '') ||
($nxt_str != '')) {
1065 $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
1066 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1067 . "TARGET=\"right\">" . _("Show All") . '</A>';
1070 /* Last but not least, get the value for the toggle all link. */
1071 $tgl_str = get_selectall_link($start_msg, $sort);
1073 /* Put all the pieces of the paginator string together. */
1075 * Hairy code... But let's leave it like it is since I am not certain
1076 * a different approach would be any easier to read. ;)
1079 $result .= ($prv_str != '' ?
$prv_str . $spc . $sep . $spc : '');
1080 $result .= ($nxt_str != '' ?
$nxt_str . $spc . $sep . $spc : '');
1081 $result .= ($pg_str != '' ?
$pg_str : '');
1082 $result .= ($all_str != '' ?
$sep . $spc . $all_str . $spc : '');
1083 $result .= ($result != '' ?
$sep . $spc . $tgl_str: $tgl_str);
1085 /* If the resulting string is blank, return a non-breaking space. */
1086 if ($result == '') {
1090 /* Return our final magical paginator string. */
1094 function processSubject($subject) {
1095 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1097 return _("(no subject)");
1099 if (strlen($subject) <= 55)
1102 $ent_strlen=strlen($subject);
1106 * see if this is entities-encoded string
1107 * If so, Iterate through the whole string, find out
1108 * the real number of characters, and if more
1109 * than 55, substr with an updated trim value.
1111 while ( (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1112 (($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false) ) {
1113 $trim_val +
= ($ent_loc_end-$ent_loc)+
1;
1114 $ent_strlen -= $ent_loc_end-$ent_loc;
1115 $ent_offset = $ent_loc_end+
1;
1118 if ($ent_strlen <= 55){
1122 return substr($subject, 0, $trim_val) . '...';
1125 function handleAsSent($mailbox) {
1126 global $sent_folder, $draft_folder, $handleAsSent_result;
1128 /* First check if this is the sent or draft folder. */
1129 $handleAsSent_result = (($mailbox == $sent_folder)
1130 ||
($mailbox == $draft_folder));
1132 /* Then check the result of the handleAsSent hook. */
1133 do_hook('check_handleAsSent_result', $mailbox);
1135 /* And return the result. */
1136 return ($handleAsSent_result);