13f185a37b5b08af6bdf10579da967d8d823c806
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');
17 require_once('../functions/html.php');
19 /* Default value for page_selector_max. */
20 define('PG_SEL_MAX', 10);
22 function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort,
23 $start_msg, $where, $what){
25 $color, $msgs, $msort,
26 $sent_folder, $draft_folder,
27 $default_use_priority,
28 $message_highlight_list,
30 $indent_array, /* indent subject by */
31 $pos, /* Search postion (if any) */
32 $thread_sort_messages, /* thread sorting on/off */
33 $server_sort_order, /* sort value when using server-sorting */
35 $allow_server_sort; /* enable/disable server-side sorting */
36 $color_string = $color[4];
38 if ($GLOBALS['alt_index_colors']) {
39 if (!isset($row_count)) {
44 if (!isset($color[12])) {
45 $color[12] = '#EAEAEA';
47 $color_string = $color[12];
53 * This is done in case you're looking into Sent folders,
54 * because you can have multiple receivers.
56 $senderNames = explode(',', $msg['FROM']);
58 if (sizeof($senderNames)){
59 foreach ($senderNames as $senderNames_part) {
60 if ($senderName != '') {
63 $senderName .= sqimap_find_displayable_name($senderNames_part);
67 if( $mailbox == 'None' ) {
68 $boxes = sqimap_mailbox_list($imapConnection);
69 $mailbox = $boxes[0]['unformatted'];
72 $urlMailbox = urlencode($mailbox);
73 $subject = processSubject($msg['SUBJECT']);
76 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
77 $flag = "<font color=\"$color[2]\">";
78 $flag_end = '</font>';
83 if (!isset($msg['FLAG_SEEN']) ||
($msg['FLAG_SEEN'] == false)) {
90 if (handleAsSent($mailbox)) {
97 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
98 $fontstr = "<font color=\"$color[9]\">";
99 $fontstr_end = '</font>';
106 * AAAAH! Make my eyes stop bleeding!
109 if (sizeof($message_highlight_list)){
110 foreach ($message_highlight_list as $message_highlight_list_part) {
111 if (trim($message_highlight_list_part['value']) != '') {
112 if ($message_highlight_list_part['match_type'] == 'to_cc') {
113 if (strstr('^^' . strtolower($msg['TO']),
114 strtolower($message_highlight_list_part['value']))
115 ||
strstr('^^'.strtolower($msg['CC']),
116 strtolower($message_highlight_list_part['value']))) {
117 $hlt_color = $message_highlight_list_part['color'];
121 if (strstr('^^' . strtolower($msg[strtoupper($message_highlight_list_part['match_type'])]),
122 strtolower($message_highlight_list_part['value']))) {
123 $hlt_color = $message_highlight_list_part['color'];
130 if (!isset($hlt_color)) {
131 $hlt_color = $color_string;
134 if ($where && $what) {
135 if(!isset($pos) ||
$pos == '') {
138 $search_stuff = "&pos=" . urlencode($pos)
139 . "&where=" . urlencode($where) . '&what=' . urlencode($what);
144 $checked = ($checkall == 1) ?
' checked' : '';
146 if (sizeof($index_order)){
147 foreach ($index_order as $index_order_part) {
148 switch ($index_order_part) {
149 case 1: /* checkbox */
150 echo " <td bgcolor=\"$hlt_color\" align=center>"
151 . "<input type=checkbox name=\"msg[$t]\" value="
152 . $msg["ID"]."$checked></TD>\n";
155 echo " <td bgcolor=\"$hlt_color\">$italic$bold$flag$fontstr"
156 . "$senderName$fontstr_end$flag_end$bold_end$italic_end</td>\n";
159 echo " <td nowrap bgcolor=\"$hlt_color\"><center>$bold$flag$fontstr"
160 . $msg["DATE_STRING"]
161 . "$fontstr_end$flag_end$bold_end</center></td>\n";
163 case 4: /* subject */
164 echo " <td bgcolor=\"$hlt_color\">$bold";
165 if ($thread_sort_messages == 1) {
166 if (isset($indent_array[$msg["ID"]])) {
167 echo str_repeat(" ",$indent_array[$msg["ID"]]);
170 echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id="
172 . "&startMessage=$start_msg&show_more=0$search_stuff\"";
173 do_hook("subject_link");
174 if ($subject != $msg['SUBJECT']) {
175 $title = get_html_translation_table(HTML_SPECIALCHARS
);
176 $title = array_flip($title);
177 $title = strtr($msg['SUBJECT'], $title);
178 $title = str_replace('"', "''", $title);
179 echo " title=\"$title\"";
181 echo ">$flag$subject$flag_end</a>$bold_end</td>\n";
185 echo " <td bgcolor=\"$hlt_color\" align=center nowrap><b><small>\n";
186 if (isset($msg['FLAG_ANSWERED']) && $msg['FLAG_ANSWERED'] == true) {
190 if ($msg['TYPE0'] == 'multipart') {
194 if ($default_use_priority) {
195 if ( ($msg['PRIORITY'] == 1) ||
($msg['PRIORITY'] == 2) ) {
196 echo "<font color=\"$color[1]\">!</font>\n";
199 if ($msg['PRIORITY'] == 5) {
200 echo "<font color=\"$color[8]\">?</font>\n";
204 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'] == true) {
205 echo "<font color=\"$color[1]\">D</font>\n";
211 echo "</small></b></td>\n";
214 echo " <td bgcolor=\"$hlt_color\">$bold$fontstr"
215 . show_readable_size($msg['SIZE']) . "$fontstr_end$bold_end</td>\n";
224 * This function loops through a group of messages in the mailbox
225 * and shows them to the user.
227 function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
228 $start_msg, $sort, $color, $show_num,
230 global $msgs, $msort,
231 $sent_folder, $draft_folder,
232 $message_highlight_list,
233 $auto_expunge, $thread_sort_messages, $allow_server_sort,
234 $data_dir, $username, $server_sort_order;
236 /* if $start_msg is lower than $num_msgs, we probably deleted all messages
237 * in the last page. We need to re-adjust the start_msg
240 if($start_msg > $num_msgs) {
241 $start_msg -= $show_num;
247 /* This code and the next if() block check for
248 * server-side sorting methods. The $id array is
249 * formatted and $sort is set to 6 to disable
250 * SM internal sorting
252 if ($thread_sort_messages == 1) {
253 $id = get_thread_sort($imapConnection);
255 echo '<b><small><center><font color=red>Thread sorting is not'.
256 ' supported by your IMAP server.<br>Please report this'.
257 ' to the system administrator.</center></small></b>';
258 $thread_sort_messages = 0;
263 if ($start_msg +
($show_num - 1) < $num_msgs) {
264 $end_msg = $start_msg +
($show_num-1);
267 $end_msg = $num_msgs;
269 $id = array_slice($id, ($start_msg-1), ($end_msg));
273 if ($allow_server_sort == TRUE && $thread_sort_messages != 1) {
274 $server_sort_order = $sort;
275 $id = sqimap_get_sort_order($imapConnection, $server_sort_order);
277 echo '<b><small><center><font color=red>Server-side sorting'.
278 ' is not supported by your IMAP server.<br>Please report this'.
279 ' to the system administrator.</center></small></b>';
280 $sort = $server_sort_order;
281 $allow_server_sort = FALSE;
286 if ($start_msg +
($show_num - 1) < $num_msgs) {
287 $end_msg = $start_msg +
($show_num-1);
290 $end_msg = $num_msgs;
292 $id = array_slice($id, ($start_msg-1), ($end_msg));
296 /* If autoexpunge is turned on, then do it now. */
297 if ($auto_expunge == true) {
298 sqimap_mailbox_expunge($imapConnection, $mailbox, false);
300 sqimap_mailbox_select($imapConnection, $mailbox);
301 $issent = handleAsSent($mailbox);
303 /* If it is sorted... */
304 if ($num_msgs >= 1) {
306 $id = range(1, $num_msgs);
308 elseif ($thread_sort_messages != 1 && $allow_server_sort != TRUE && $sort == 6) {
309 /* if it's not sorted */
310 if ($start_msg +
($show_num - 1) < $num_msgs){
311 $end_msg = $start_msg +
($show_num - 1);
313 $end_msg = $num_msgs;
315 if ($end_msg < $start_msg) {
316 $start_msg = $start_msg - $show_num;
317 if ($start_msg < 1) {
322 $real_startMessage = $num_msgs - $start_msg +
1;
323 $real_endMessage = $num_msgs - $start_msg - $show_num +
2;
324 if ($real_endMessage <= 0) {
325 $real_endMessage = 1;
327 $id = array_reverse(range($real_endMessage, $real_startMessage));
329 $msgs_list = sqimap_get_small_header_list($imapConnection, $id, $issent);
330 // $flags = sqimap_get_flags_list($imapConnection, $id, $issent);
331 if (sizeof($msgs_list)){
332 foreach ($msgs_list as $hdr) {
333 $from[] = $hdr->from
;
334 $date[] = $hdr->date
;
335 $subject[] = $hdr->subject
;
337 $priority[] = $hdr->priority
;
339 $size[] = $hdr->size
;
340 $type[] = $hdr->type0
;
341 $flag_deleted[] = $hdr->flag_deleted
;
342 $flag_answered[] = $hdr->flag_answered
;
343 $flag_seen[] = $hdr->flag_seen
;
344 $flag_flagged[] = $hdr->flag_flagged
;
350 $end = $start_msg +
$show_num - 1;
351 if ($num_msgs < $show_num) {
352 $end_loop = $num_msgs;
353 } else if ($end > $num_msgs) {
354 $end_loop = $num_msgs - $start_msg +
1;
356 $end_loop = $show_num;
362 while ($j < $end_loop) {
363 if (isset($date[$j])) {
364 $date[$j] = str_replace(' ', ' ', $date[$j]);
365 $tmpdate = explode(' ', trim($date[$j]));
367 $tmpdate = $date = array('', '', '', '', '', '');
370 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
371 $messages[$j]['DATE_STRING'] =
372 getDateString($messages[$j]['TIME_STAMP']);
373 $messages[$j]['ID'] = $id[$j];
374 $messages[$j]['FROM'] = decodeHeader($from[$j]);
375 $messages[$j]['FROM-SORT'] =
376 strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
377 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
378 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
379 $messages[$j]['TO'] = decodeHeader($to[$j]);
380 $messages[$j]['PRIORITY'] = $priority[$j];
381 $messages[$j]['CC'] = $cc[$j];
382 $messages[$j]['SIZE'] = $size[$j];
383 $messages[$j]['TYPE0'] = $type[$j];
384 $messages[$j]['FLAG_DELETED'] = $flag_deleted[$j];
385 $messages[$j]['FLAG_ANSWERED'] = $flag_answered[$j];
386 $messages[$j]['FLAG_SEEN'] = $flag_seen[$j];
387 $messages[$j]['FLAG_FLAGGED'] = $flag_flagged[$j];
391 * fix SUBJECT-SORT to remove Re:
395 * TODO: i18n should be incorporated here. E.g. we catch the ones
396 * we know about, but also define in i18n what the localized
397 * "Re: " is for this or that locale.
399 if (preg_match("/^(vedr|sv|re|aw):\s*(.*)$/si",
400 $messages[$j]['SUBJECT-SORT'], $matches)){
401 $messages[$j]['SUBJECT-SORT'] = $matches[2];
405 while ($num < count($flags[$j])) {
406 if ($flags[$j][$num] == 'Deleted') {
407 $messages[$j]['FLAG_DELETED'] = true;
408 } else if ($flags[$j][$num] == 'Answered') {
409 $messages[$j]['FLAG_ANSWERED'] = true;
410 } else if ($flags[$j][$num] == 'Seen') {
411 $messages[$j]['FLAG_SEEN'] = true;
412 } else if ($flags[$j][$num] == 'Flagged') {
413 $messages[$j]['FLAG_FLAGGED'] = true;
423 * Only ignore messages flagged as deleted if we are
424 * using a trash folder or auto_expunge
426 if (((isset($move_to_trash) && $move_to_trash)
427 ||
(isset($auto_expunge) && $auto_expunge))
430 /* Find and remove the ones that are deleted */
434 while ($j < $num_msgs) {
435 if (isset($messages[$j]['FLAG_DELETED'])
436 && $messages[$j]['FLAG_DELETED'] == true) {
440 $msgs[$i] = $messages[$j];
447 if (!isset($messages)) {
454 /* There's gotta be messages in the array for it to sort them. */
455 if (($num_msgs > 0) && (!$use_cache)) {
464 session_unregister('msgs');
465 if (($sort == 0) ||
($sort == 1)) {
466 $msort = array_cleave ($msgs, 'TIME_STAMP');
467 } elseif (($sort == 2) ||
($sort == 3)) {
468 $msort = array_cleave ($msgs, 'FROM-SORT');
469 } elseif (($sort == 4) ||
($sort == 5)) {
470 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
482 session_register('msort');
483 } elseif ($thread_sort_messages == 1 ||
$allow_server_sort == TRUE) {
485 session_unregister('msgs');
486 session_register('msort');
488 displayMessageArray($imapConnection, $num_msgs, $start_msg, $msgs,
489 $msort, $mailbox, $sort, $color,$show_num);
491 * TODO: Switch to using $_SESSION[] whenever we ditch the 4.0.x series.
493 session_register('msgs');
496 /* Generic function to convert the msgs array into an HTML table. */
497 function displayMessageArray($imapConnection, $num_msgs, $start_msg,
498 &$msgs, $msort, $mailbox, $sort, $color,
500 global $folder_prefix, $sent_folder,
501 $imapServerAddress, $data_dir, $username, $use_mailbox_cache,
502 $index_order, $real_endMessage, $real_startMessage, $checkall,
503 $indent_array, $thread_sort_messages, $allow_server_sort, $server_sort_order;
505 /* If cache isn't already set, do it now. */
506 if (!session_is_registered('msgs')) {
507 session_register('msgs');
509 if (!session_is_registered('msort')) {
510 session_register('msort');
513 if ($start_msg +
($show_num - 1) < $num_msgs){
514 $end_msg = $start_msg +
($show_num - 1);
516 $end_msg = $num_msgs;
519 if ($end_msg < $start_msg) {
520 $start_msg = $start_msg - $show_num;
521 if ($start_msg < 1) {
526 $urlMailbox = urlencode($mailbox);
528 do_hook('mailbox_index_before');
530 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
531 $paginator_str = get_paginator_str($urlMailbox, $start_msg, $end_msg,
532 $num_msgs, $show_num, $sort);
538 /* get indent level for subject display */
539 if ($thread_sort_messages == 1 ) {
540 $indent_array = get_parent_level($imapConnection);
542 $fstring = "move_messages.php?msg=$msg&mailbox=$urlMailbox"
543 . "&startMessage=$start_msg";
544 mail_message_listing_beginning($imapConnection, $fstring,
545 $mailbox, $sort, $msg_cnt_str,
546 $paginator_str, $start_msg);
548 $groupNum = $start_msg %
($show_num - 1);
549 $real_startMessage = $start_msg;
551 if ($end_msg - $start_msg < $show_num - 1) {
552 $end_msg = $end_msg - $start_msg +
1;
554 } else if ($start_msg > $show_num) {
555 $end_msg = $show_num;
559 $endVar = $end_msg +
1;
562 * Loop through and display the info for each message.
563 * ($t is used for the checkbox number)
566 if ($num_msgs == 0) {
567 /* if there's no messages in this folder */
568 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN="
569 . count($index_order) . ">\n"
570 . " <CENTER><BR><B>". _("THIS FOLDER IS EMPTY")
571 . "</B><BR> </CENTER>\n"
573 } elseif ($start_msg == $end_msg) {
574 /* if there's only one message in the box, handle it differently. */
586 } while (isset ($key) && ($k < $i));
587 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort,
588 $real_startMessage, 0, 0);
597 } while (isset ($key) && ($k < $i));
599 printMessageInfo($imapConnection, $t, $i, $key, $mailbox,
600 $sort, $real_startMessage, 0, 0);
605 } while ($i && $i < $endVar);
609 . html_tag( 'table', '',
610 "bgcolor=\"$color[9]\" width=\"100%\" border=0 cellpadding=1 cellspacing=1" )
611 . "<tr BGCOLOR=\"$color[4]\"><td>"
612 . "<table width=\"100%\" BGCOLOR=\"$color[4]\" border=0 cellpadding=1 "
613 . "cellspacing=0><tr><td>$paginator_str</td>"
614 . html_tag( 'td', 'right' ) . "$msg_cnt_str</td></tr></table>"
615 . "</td></tr></table>";
616 /* End of message-list table */
618 do_hook('mailbox_index_after');
619 echo "</TABLE></FORM>\n";
623 * Displays the standard message list header. To finish the table,
624 * you need to do a "</table></table>";
626 * $moveURL is the URL to submit the delete/move form to
627 * $mailbox is the current mailbox
628 * $sort is the current sorting method (-1 for no sorting available [searches])
629 * $Message is a message that is centered on top of the list
630 * $More is a second line that is left aligned
633 function mail_message_listing_beginning ($imapConnection, $moveURL,
634 $mailbox = '', $sort = -1,
636 $paginator = ' ',
638 global $color, $index_order, $auto_expunge, $move_to_trash, $base_uri,
639 $checkall, $sent_folder, $draft_folder, $thread_sort_messages,
640 $allow_thread_sort, $allow_server_sort, $server_sort_order,
643 $urlMailbox = urlencode($mailbox);
646 * This is the beginning of the message list table.
647 * It wraps around all messages
649 echo "<FORM name=\"messageList\" method=post action=\"$moveURL\">\n"
650 . "<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLPADDING=\"1\" "
651 . "CELLSPACING=\"0\">\n<TR BGCOLOR=\"$color[0]\"><TD>"
652 . " <TABLE BGCOLOR=\"$color[4]\" width=\"100%\" CELLPADDING=\"2\" "
653 . "CELLSPACING=\"0\" BORDER=\"0\"><TR>\n"
654 . " <TD ALIGN=LEFT>$paginator\n";
656 echo " <TD ALIGN=RIGHT>$msg_cnt_str</TD>\n"
659 . "<TR><TD BGCOLOR=\"$color[0]\">\n"
660 . "<TABLE BGCOLOR=\"$color[0]\" BORDER=0 cellpadding=0 "
661 . "cellspacing=0 width=\"100%\">\n"
663 . " <TD ALIGN=LEFT VALIGN=MIDDLE NOWRAP>\n"
664 . ' <SMALL> ' . _("Move Selected To:") . "</SMALL>\n"
666 . " <TD ALIGN=RIGHT NOWRAP>\n"
667 . ' <SMALL> ' . _("Transform Selected Messages")
668 . ": </SMALL><BR>\n"
672 . " <TD ALIGN=\"LEFT\" VALIGN=\"MIDDLE\" NOWRAP>\n"
673 . ' <SMALL> <TT><SELECT NAME="targetMailbox">';
675 $boxes = sqimap_mailbox_list($imapConnection);
676 foreach ($boxes as $boxes_part) {
677 if (!in_array('noselect', $boxes_part['flags'])) {
678 $box = $boxes_part['unformatted'];
679 $box2 = str_replace(' ', ' ', imap_utf7_decode_local($boxes_part['unformatted-disp']));
680 if( $box2 == 'INBOX' ) {
683 if ($lastTargetMailbox == $box) {
684 echo " <OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
687 echo " <OPTION VALUE=\"$box\">$box2</OPTION>\n";
691 echo ' </SELECT></TT> '
692 . '<INPUT TYPE="SUBMIT" NAME="moveButton" VALUE="' . _("Move") . '"> '
693 . '<INPUT TYPE="SUBMIT" NAME="attache" VALUE="' . _("Forward")
694 . "\"> \n" . "</SMALL>\n";
697 . " <TD ALIGN=\"RIGHT\" NOWRAP>";
698 if (!$auto_expunge) {
699 echo '<INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="' . _("Expunge")
700 . '"> ' . _("mailbox") . ' ';
702 echo '<INPUT TYPE="SUBMIT" NAME="markRead" VALUE="' . _("Read") . '">'
703 . '<INPUT TYPE="SUBMIT" NAME="markUnread" VALUE="' . _("Unread") . '">'
704 . '<INPUT TYPE="SUBMIT" VALUE="' . _("Delete") . '"> '
708 /* draws thread sorting links */
709 if ($allow_thread_sort == TRUE) {
710 if ($thread_sort_messages == 1 ) {
712 $thread_name = _("Unthread View");
714 elseif ($thread_sort_messages == 0) {
716 $thread_name = _("Thread View");
718 echo '<tr><td> <a href=' . "$base_uri" . 'src/right_main.php?sort='
719 . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
720 . '&mailbox=' . urlencode($mailbox) . '><small>' . $thread_name
721 . '</a></small> </td></tr>';
725 do_hook('mailbox_form_before');
727 . "<TR><TD BGCOLOR=\"$color[0]\">"
728 . '<TABLE WIDTH="100%" BORDER=0 CELLPADDING=2 CELLSPACING=';
729 if ($GLOBALS['alt_index_colors']){
734 echo " BGCOLOR=\"$color[0]\">"
735 . "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
736 /* if using server sort we highjack the
737 * the $sort var and use $server_sort_order
738 * instead. but here we reset sort for a bit
741 if ($allow_server_sort == TRUE) {
742 $sort = $server_sort_order;
744 /* Print the headers. */
745 for ($i=1; $i <= count($index_order); $i++
) {
746 switch ($index_order[$i]) {
747 case 1: /* checkbox */
749 echo ' <TD WIDTH="1%"><B> </B></TD>';
752 if (handleAsSent($mailbox)) {
753 echo ' <TD WIDTH="25%"><B>' . _("To") . '</B>';
755 echo ' <TD WIDTH="25%"><B>' . _("From") . '</B>';
757 if ($allow_thread_sort != TRUE ||
$thread_sort_messages != 1) {
758 ShowSortButton($sort, $mailbox, 2, 3);
763 echo ' <TD NOWRAP WIDTH="5%"><B>' . _("Date") . '</B>';
764 if ($allow_thread_sort != TRUE ||
$thread_sort_messages != 1) {
765 ShowSortButton($sort, $mailbox, 0, 1);
769 case 4: /* subject */
770 echo ' <TD><B>' . _("Subject") . '</B> ';
771 if ($allow_thread_sort != TRUE ||
$thread_sort_messages != 1) {
772 ShowSortButton($sort, $mailbox, 4, 5);
777 echo ' <TD WIDTH="5%"><b>' . _("Size") . "</b></TD>\n";
781 /* if using server-sorting,
782 * send sort back to 6
784 if ($allow_server_sort == TRUE) {
791 * This function shows the sort button. Isn't this a good comment?
793 function ShowSortButton($sort, $mailbox, $Up, $Down) {
794 /* Figure out which image we want to use. */
795 if ($sort != $Up && $sort != $Down) {
796 $img = 'sort_none.png';
798 } elseif ($sort == $Up) {
799 $img = 'up_pointer.png';
802 $img = 'down_pointer.png';
806 /* Now that we have everything figured out, show the actual button. */
807 echo ' <a href="right_main.php?newsort=' . $which
808 . '&startMessage=1&mailbox=' . urlencode($mailbox)
809 . '"><IMG SRC="../images/' . $img
810 . '" BORDER=0 WIDTH=12 HEIGHT=10 ALT="sort"></a>';
813 function get_selectall_link($start_msg, $sort) {
814 global $checkall, $what, $where, $mailbox, $javascript_on;
815 global $PHP_SELF, $PG_SHOWNUM;
818 if ($javascript_on) {
820 '<script language="JavaScript" type="text/javascript">'
822 . "function CheckAll() {\n"
823 . " for (var i = 0; i < document.messageList.elements.length; i++) {\n"
824 . " if(document.messageList.elements[i].type == 'checkbox'){\n"
825 . " document.messageList.elements[i].checked = "
826 . " !(document.messageList.elements[i].checked);\n"
831 . '</script><a href="#" onClick="CheckAll();">' . _("Toggle All")
834 if (strpos($PHP_SELF, "?")) {
835 $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($mailbox)
836 . "&startMessage=$start_msg&sort=$sort&checkall=";
838 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
839 . "&startMessage=$start_msg&sort=$sort&checkall=";
841 if (isset($checkall) && $checkall == '1') {
847 if (isset($where) && isset($what)) {
848 $result .= '&where=' . urlencode($where)
849 . '&what=' . urlencode($what);
854 if (isset($checkall) && ($checkall == '1')) {
855 $result .= _("Unselect All");
857 $result .= _("Select All");
863 /* Return our final result. */
868 * This function computes the "Viewing Messages..." string.
870 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
871 /* Compute the $msg_cnt_str. */
873 if ($start_msg < $end_msg) {
874 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"),
875 $start_msg, $end_msg, $num_msgs);
876 } else if ($start_msg == $end_msg) {
877 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
882 /* Return our result string. */
887 * Generate a paginator link.
889 function get_paginator_link($box, $start_msg, $use, $text) {
890 $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
891 . "&startMessage=$start_msg&mailbox=$box\" "
892 . "TARGET=\"right\">$text</A>";
897 * This function computes the paginator string.
899 function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
901 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
903 /* Initialize paginator string chunks. */
910 /* Create simple strings that will be creating the paginator. */
911 $spc = ' '; /* This will be used as a space. */
912 $sep = '|'; /* This will be used as a seperator. */
914 /* Get some paginator preference values. */
915 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON
);
916 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
);
918 /* Make sure that our start message number is not too big. */
919 $start_msg = min($start_msg, $num_msgs);
921 /* Decide whether or not we will use the mailbox cache. */
922 /* Not sure why $use_mailbox_cache is even passed in. */
929 /* Compute the starting message of the previous and next page group. */
930 $next_grp = $start_msg +
$show_num;
931 $prev_grp = $start_msg - $show_num;
933 /* Compute the basic previous and next strings. */
934 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
935 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
936 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
937 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
938 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
939 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
940 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
941 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
942 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
945 /* Page selector block. Following code computes page links. */
946 if ($pg_sel && ($num_msgs > $show_num)) {
947 /* Most importantly, what is the current page!!! */
948 $cur_pg = intval($start_msg / $show_num) +
1;
950 /* Compute total # of pages and # of paginator page links. */
951 $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
952 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
954 /* Compute the size of the four quarters of the page links. */
956 /* If we can, just show all the pages. */
957 if (($tot_pgs - 1) <= $pg_max) {
958 $q1_pgs = $cur_pg - 1;
959 $q2_pgs = $q3_pgs = 0;
960 $q4_pgs = $tot_pgs - $cur_pg;
962 /* Otherwise, compute some magic to choose the four quarters. */
965 * Compute the magic base values. Added together,
966 * these values will always equal to the $pag_pgs.
967 * NOTE: These are DEFAULT values and do not take
968 * the current page into account. That is below.
970 $q1_pgs = floor($vis_pgs/4);
971 $q2_pgs = round($vis_pgs/4, 0);
972 $q3_pgs = ceil($vis_pgs/4);
973 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
975 /* Adjust if the first quarter contains the current page. */
976 if (($cur_pg - $q1_pgs) < 1) {
977 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) +
$q2_pgs;
978 $q1_pgs = $cur_pg - 1;
980 $q3_pgs +
= ceil($extra_pgs / 2);
981 $q4_pgs +
= floor($extra_pgs / 2);
983 /* Adjust if the first and second quarters intersect. */
984 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
985 $extra_pgs = $q2_pgs;
986 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
987 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
988 $q3_pgs +
= ceil($extra_pgs / 2);
989 $q4_pgs +
= floor($extra_pgs / 2);
991 /* Adjust if the fourth quarter contains the current page. */
992 } else if (($cur_pg +
$q4_pgs) >= $tot_pgs) {
993 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) +
$q3_pgs;
995 $q4_pgs = $tot_pgs - $cur_pg;
996 $q1_pgs +
= floor($extra_pgs / 2);
997 $q2_pgs +
= ceil($extra_pgs / 2);
999 /* Adjust if the third and fourth quarter intersect. */
1000 } else if (($cur_pg +
$q3_pgs +
1) >= ($tot_pgs - $q4_pgs +
1)) {
1001 $extra_pgs = $q3_pgs;
1002 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1003 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1004 $q1_pgs +
= floor($extra_pgs / 2);
1005 $q2_pgs +
= ceil($extra_pgs / 2);
1010 * I am leaving this debug code here, commented out, because
1011 * it is a really nice way to see what the above code is doing.
1012 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
1013 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
1016 /* Print out the page links from the compute page quarters. */
1018 /* Start with the first quarter. */
1019 if (($q1_pgs == 0) && ($cur_pg > 1)) {
1020 $pg_str .= "...$spc";
1022 for ($pg = 1; $pg <= $q1_pgs; ++
$pg) {
1023 $start = (($pg-1) * $show_num) +
1;
1024 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1026 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
1027 $pg_str .= "...$spc";
1031 /* Continue with the second quarter. */
1032 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++
$pg) {
1033 $start = (($pg-1) * $show_num) +
1;
1034 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1037 /* Now print the current page. */
1038 $pg_str .= $cur_pg . $spc;
1040 /* Next comes the third quarter. */
1041 for ($pg = $cur_pg +
1; $pg <= $cur_pg +
$q3_pgs; ++
$pg) {
1042 $start = (($pg-1) * $show_num) +
1;
1043 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1046 /* And last, print the forth quarter page links. */
1047 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
1048 $pg_str .= "...$spc";
1050 if (($tot_pgs - $q4_pgs) > ($cur_pg +
$q3_pgs)) {
1051 $pg_str .= "...$spc";
1053 for ($pg = $tot_pgs - $q4_pgs +
1; $pg <= $tot_pgs; ++
$pg) {
1054 $start = (($pg-1) * $show_num) +
1;
1055 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1058 } else if ($PG_SHOWNUM == 999999) {
1059 $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
1060 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1061 . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc;
1064 /* If necessary, compute the 'show all' string. */
1065 if (($prv_str != '') ||
($nxt_str != '')) {
1066 $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
1067 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1068 . "TARGET=\"right\">" . _("Show All") . '</A>';
1071 /* Last but not least, get the value for the toggle all link. */
1072 $tgl_str = get_selectall_link($start_msg, $sort);
1074 /* Put all the pieces of the paginator string together. */
1076 * Hairy code... But let's leave it like it is since I am not certain
1077 * a different approach would be any easier to read. ;)
1080 $result .= ($prv_str != '' ?
$prv_str . $spc . $sep . $spc : '');
1081 $result .= ($nxt_str != '' ?
$nxt_str . $spc . $sep . $spc : '');
1082 $result .= ($pg_str != '' ?
$pg_str : '');
1083 $result .= ($all_str != '' ?
$sep . $spc . $all_str . $spc : '');
1084 $result .= ($result != '' ?
$sep . $spc . $tgl_str: $tgl_str);
1086 /* If the resulting string is blank, return a non-breaking space. */
1087 if ($result == '') {
1091 /* Return our final magical paginator string. */
1095 function processSubject($subject) {
1096 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1098 return _("(no subject)");
1100 if (strlen($subject) <= 55)
1103 $ent_strlen=strlen($subject);
1107 * see if this is entities-encoded string
1108 * If so, Iterate through the whole string, find out
1109 * the real number of characters, and if more
1110 * than 55, substr with an updated trim value.
1112 while ( (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1113 (($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false) ) {
1114 $trim_val +
= ($ent_loc_end-$ent_loc)+
1;
1115 $ent_strlen -= $ent_loc_end-$ent_loc;
1116 $ent_offset = $ent_loc_end+
1;
1119 if ($ent_strlen <= 55){
1123 return substr($subject, 0, $trim_val) . '...';
1126 function handleAsSent($mailbox) {
1127 global $sent_folder, $draft_folder, $handleAsSent_result;
1129 /* First check if this is the sent or draft folder. */
1130 $handleAsSent_result = (($mailbox == $sent_folder)
1131 ||
($mailbox == $draft_folder));
1133 /* Then check the result of the handleAsSent hook. */
1134 do_hook('check_handleAsSent_result', $mailbox);
1136 /* And return the result. */
1137 return ($handleAsSent_result);