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 /* Default value for page_selector_max. */
18 define('PG_SEL_MAX', 10);
20 function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort,
21 $start_msg, $where, $what){
23 $color, $msgs, $msort,
24 $sent_folder, $draft_folder,
25 $default_use_priority,
26 $message_highlight_list,
28 $indent_array, /* indent subject by */
29 $pos, /* Search postion (if any) */
30 $thread_sort_messages, /* thread sorting on/off */
31 $server_sort_order, /* sort value when using server-sorting */
33 $allow_server_sort; /* enable/disable server-side sorting */
34 $color_string = $color[4];
36 if ($GLOBALS['alt_index_colors']) {
37 if (!isset($row_count)) {
42 if (!isset($color[12])) {
43 $color[12] = '#EAEAEA';
45 $color_string = $color[12];
51 * This is done in case you're looking into Sent folders,
52 * because you can have multiple receivers.
54 $senderNames = explode(',', $msg['FROM']);
56 if (sizeof($senderNames)){
57 foreach ($senderNames as $senderNames_part) {
58 if ($senderName != '') {
61 $senderName .= sqimap_find_displayable_name($senderNames_part);
65 if( $mailbox == 'None' ) {
66 $boxes = sqimap_mailbox_list($imapConnection);
67 $mailbox = $boxes[0]['unformatted'];
70 $urlMailbox = urlencode($mailbox);
71 $subject = processSubject($msg['SUBJECT']);
74 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
75 $flag = "<font color=\"$color[2]\">";
76 $flag_end = '</font>';
81 if (!isset($msg['FLAG_SEEN']) ||
($msg['FLAG_SEEN'] == false)) {
88 if (handleAsSent($mailbox)) {
95 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
96 $fontstr = "<font color=\"$color[9]\">";
97 $fontstr_end = '</font>';
104 * AAAAH! Make my eyes stop bleeding!
107 if (sizeof($message_highlight_list)){
108 foreach ($message_highlight_list as $message_highlight_list_part) {
109 if (trim($message_highlight_list_part['value']) != '') {
110 if ($message_highlight_list_part['match_type'] == 'to_cc') {
111 if (strstr('^^' . strtolower($msg['TO']),
112 strtolower($message_highlight_list_part['value']))
113 ||
strstr('^^'.strtolower($msg['CC']),
114 strtolower($message_highlight_list_part['value']))) {
115 $hlt_color = $message_highlight_list_part['color'];
119 if (strstr('^^' . strtolower($msg[strtoupper($message_highlight_list_part['match_type'])]),
120 strtolower($message_highlight_list_part['value']))) {
121 $hlt_color = $message_highlight_list_part['color'];
128 if (!isset($hlt_color)) {
129 $hlt_color = $color_string;
132 if ($where && $what) {
133 if(!isset($pos) ||
$pos == '') {
136 $search_stuff = "&pos=" . urlencode($pos)
137 . "&where=" . urlencode($where) . '&what=' . urlencode($what);
142 $checked = ($checkall == 1) ?
' checked' : '';
144 if (sizeof($index_order)){
145 foreach ($index_order as $index_order_part) {
146 switch ($index_order_part) {
147 case 1: /* checkbox */
148 echo " <td bgcolor=\"$hlt_color\" align=center>"
149 . "<input type=checkbox name=\"msg[$t]\" value="
150 . $msg["ID"]."$checked></TD>\n";
153 echo " <td bgcolor=\"$hlt_color\">$italic$bold$flag$fontstr"
154 . "$senderName$fontstr_end$flag_end$bold_end$italic_end</td>\n";
157 echo " <td nowrap bgcolor=\"$hlt_color\"><center>$bold$flag$fontstr"
158 . $msg["DATE_STRING"]
159 . "$fontstr_end$flag_end$bold_end</center></td>\n";
161 case 4: /* subject */
162 echo " <td bgcolor=\"$hlt_color\">$bold";
163 if ($thread_sort_messages == 1) {
164 if (isset($indent_array[$msg["ID"]])) {
165 echo str_repeat(" ",$indent_array[$msg["ID"]]);
168 echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id="
170 . "&startMessage=$start_msg&show_more=0$search_stuff\"";
171 do_hook("subject_link");
172 if ($subject != $msg['SUBJECT']) {
173 $title = get_html_translation_table(HTML_SPECIALCHARS
);
174 $title = array_flip($title);
175 $title = strtr($msg['SUBJECT'], $title);
176 $title = str_replace('"', "''", $title);
177 echo " title=\"$title\"";
179 echo ">$flag$subject$flag_end</a>$bold_end</td>\n";
183 echo " <td bgcolor=\"$hlt_color\" align=center nowrap><b><small>\n";
184 if (isset($msg['FLAG_ANSWERED']) && $msg['FLAG_ANSWERED'] == true) {
188 if ($msg['TYPE0'] == 'multipart') {
192 if ($default_use_priority) {
193 if ( ($msg['PRIORITY'][0] == 1) ||
($msg['PRIORITY'][0] == 2) ) {
194 echo "<font color=\"$color[1]\">!</font>\n";
197 if ($msg['PRIORITY'][0] == 5) {
198 echo "<font color=\"$color[8]\">?</font>\n";
202 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'] == true) {
203 echo "<font color=\"$color[1]\">D</font>\n";
209 echo "</small></b></td>\n";
212 echo " <td bgcolor=\"$hlt_color\">$bold$fontstr"
213 . show_readable_size($msg['SIZE']) . "$fontstr_end$bold_end</td>\n";
222 * This function loops through a group of messages in the mailbox
223 * and shows them to the user.
225 function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
226 $start_msg, $sort, $color, $show_num,
228 global $msgs, $msort,
229 $sent_folder, $draft_folder,
230 $message_highlight_list,
231 $auto_expunge, $thread_sort_messages, $allow_server_sort,
232 $data_dir, $username, $server_sort_order;
234 /* if $start_msg is lower than $num_msgs, we probably deleted all messages
235 * in the last page. We need to re-adjust the start_msg
238 if($start_msg > $num_msgs) {
239 $start_msg -= $show_num;
245 /* This code and the next if() block check for
246 * server-side sorting methods. The $id array is
247 * formatted and $sort is set to 6 to disable
248 * SM internal sorting
250 if ($thread_sort_messages == 1) {
251 $id = get_thread_sort($imapConnection);
253 echo '<b><small><center><font color=red>Thread sorting is not'.
254 ' supported by your IMAP server.<br>Please report this'.
255 ' to the system administrator.</center></small></b>';
256 $thread_sort_messages = 0;
261 if ($start_msg +
($show_num - 1) < $num_msgs) {
262 $end_msg = $start_msg +
($show_num-1);
265 $end_msg = $num_msgs;
267 $id = array_slice($id, ($start_msg-1), ($end_msg));
271 if ($allow_server_sort == TRUE && $thread_sort_messages != 1) {
272 $server_sort_order = $sort;
273 $id = sqimap_get_sort_order($imapConnection, $server_sort_order);
275 echo '<b><small><center><font color=red>Server-side sorting'.
276 ' is not supported by your IMAP server.<br>Please report this'.
277 ' to the system administrator.</center></small></b>';
278 $sort = $server_sort_order;
279 $allow_server_sort = FALSE;
284 if ($start_msg +
($show_num - 1) < $num_msgs) {
285 $end_msg = $start_msg +
($show_num-1);
288 $end_msg = $num_msgs;
290 $id = array_slice($id, ($start_msg-1), ($end_msg));
294 /* If autoexpunge is turned on, then do it now. */
295 if ($auto_expunge == true) {
296 sqimap_mailbox_expunge($imapConnection, $mailbox, false);
298 sqimap_mailbox_select($imapConnection, $mailbox);
299 $issent = handleAsSent($mailbox);
301 /* If it is sorted... */
302 if ($num_msgs >= 1) {
304 $id = range(1, $num_msgs);
306 elseif ($thread_sort_messages != 1 && $allow_server_sort != TRUE && $sort == 6) {
307 /* if it's not sorted */
308 if ($start_msg +
($show_num - 1) < $num_msgs){
309 $end_msg = $start_msg +
($show_num - 1);
311 $end_msg = $num_msgs;
313 if ($end_msg < $start_msg) {
314 $start_msg = $start_msg - $show_num;
315 if ($start_msg < 1) {
320 $real_startMessage = $num_msgs - $start_msg +
1;
321 $real_endMessage = $num_msgs - $start_msg - $show_num +
2;
322 if ($real_endMessage <= 0) {
323 $real_endMessage = 1;
325 $id = array_reverse(range($real_endMessage, $real_startMessage));
327 $msgs_list = sqimap_get_small_header_list($imapConnection, $id, $issent);
328 // $flags = sqimap_get_flags_list($imapConnection, $id, $issent);
329 if (sizeof($msgs_list)){
330 foreach ($msgs_list as $hdr) {
331 $from[] = $hdr->from
;
332 $date[] = $hdr->date
;
333 $subject[] = $hdr->subject
;
335 $priority[] = $hdr->priority
;
337 $size[] = $hdr->size
;
338 $type[] = $hdr->type0
;
339 $flag_deleted[] = $hdr->flag_deleted
;
340 $flag_answered[] = $hdr->flag_answered
;
341 $flag_seen[] = $hdr->flag_seen
;
342 $flag_flagged[] = $hdr->flag_flagged
;
348 $end = $start_msg +
$show_num - 1;
349 if ($num_msgs < $show_num) {
350 $end_loop = $num_msgs;
351 } else if ($end > $num_msgs) {
352 $end_loop = $num_msgs - $start_msg +
1;
354 $end_loop = $show_num;
360 while ($j < $end_loop) {
361 if (isset($date[$j])) {
362 $date[$j] = str_replace(' ', ' ', $date[$j]);
363 $tmpdate = explode(' ', trim($date[$j]));
365 $tmpdate = $date = array('', '', '', '', '', '');
368 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
369 $messages[$j]['DATE_STRING'] =
370 getDateString($messages[$j]['TIME_STAMP']);
371 $messages[$j]['ID'] = $id[$j];
372 $messages[$j]['FROM'] = decodeHeader($from[$j]);
373 $messages[$j]['FROM-SORT'] =
374 strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
375 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
376 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
377 $messages[$j]['TO'] = decodeHeader($to[$j]);
378 $messages[$j]['PRIORITY'] = $priority[$j];
379 $messages[$j]['CC'] = $cc[$j];
380 $messages[$j]['SIZE'] = $size[$j];
381 $messages[$j]['TYPE0'] = $type[$j];
382 $messages[$j]['FLAG_DELETED'] = $flag_deleted[$j];
383 $messages[$j]['FLAG_ANSWERED'] = $flag_answered[$j];
384 $messages[$j]['FLAG_SEEN'] = $flag_seen[$j];
385 $messages[$j]['FLAG_FLAGGED'] = $flag_flagged[$j];
389 * fix SUBJECT-SORT to remove Re:
393 * TODO: i18n should be incorporated here. E.g. we catch the ones
394 * we know about, but also define in i18n what the localized
395 * "Re: " is for this or that locale.
397 if (preg_match("/^(vedr|sv|re|aw):\s*(.*)$/si",
398 $messages[$j]['SUBJECT-SORT'], $matches)){
399 $messages[$j]['SUBJECT-SORT'] = $matches[2];
403 while ($num < count($flags[$j])) {
404 if ($flags[$j][$num] == 'Deleted') {
405 $messages[$j]['FLAG_DELETED'] = true;
406 } else if ($flags[$j][$num] == 'Answered') {
407 $messages[$j]['FLAG_ANSWERED'] = true;
408 } else if ($flags[$j][$num] == 'Seen') {
409 $messages[$j]['FLAG_SEEN'] = true;
410 } else if ($flags[$j][$num] == 'Flagged') {
411 $messages[$j]['FLAG_FLAGGED'] = true;
420 * Only ignore messages flagged as deleted if we are
421 * using a trash folder or auto_expunge
423 if (((isset($move_to_trash) && $move_to_trash)
424 ||
(isset($auto_expunge) && $auto_expunge))
427 /* Find and remove the ones that are deleted */
431 while ($j < $num_msgs) {
432 if (isset($messages[$j]['FLAG_DELETED'])
433 && $messages[$j]['FLAG_DELETED'] == true) {
437 $msgs[$i] = $messages[$j];
444 if (!isset($messages)) {
451 /* There's gotta be messages in the array for it to sort them. */
452 if (($num_msgs > 0) && (!$use_cache)) {
461 session_unregister('msgs');
462 if (($sort == 0) ||
($sort == 1)) {
463 $msort = array_cleave ($msgs, 'TIME_STAMP');
464 } elseif (($sort == 2) ||
($sort == 3)) {
465 $msort = array_cleave ($msgs, 'FROM-SORT');
466 } elseif (($sort == 4) ||
($sort == 5)) {
467 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
479 session_register('msort');
480 } elseif ($thread_sort_messages == 1 ||
$allow_server_sort == TRUE) {
482 session_unregister('msgs');
483 session_register('msort');
485 displayMessageArray($imapConnection, $num_msgs, $start_msg, $msgs,
486 $msort, $mailbox, $sort, $color,$show_num);
488 * TODO: Switch to using $_SESSION[] whenever we ditch the 4.0.x series.
490 session_register('msgs');
493 /* Generic function to convert the msgs array into an HTML table. */
494 function displayMessageArray($imapConnection, $num_msgs, $start_msg,
495 &$msgs, $msort, $mailbox, $sort, $color,
497 global $folder_prefix, $sent_folder,
498 $imapServerAddress, $data_dir, $username, $use_mailbox_cache,
499 $index_order, $real_endMessage, $real_startMessage, $checkall,
500 $indent_array, $thread_sort_messages, $allow_server_sort, $server_sort_order;
502 /* If cache isn't already set, do it now. */
503 if (!session_is_registered('msgs')) {
504 session_register('msgs');
506 if (!session_is_registered('msort')) {
507 session_register('msort');
510 if ($start_msg +
($show_num - 1) < $num_msgs){
511 $end_msg = $start_msg +
($show_num - 1);
513 $end_msg = $num_msgs;
516 if ($end_msg < $start_msg) {
517 $start_msg = $start_msg - $show_num;
518 if ($start_msg < 1) {
523 $urlMailbox = urlencode($mailbox);
525 do_hook('mailbox_index_before');
527 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
528 $paginator_str = get_paginator_str($urlMailbox, $start_msg, $end_msg,
529 $num_msgs, $show_num, $sort);
535 /* get indent level for subject display */
536 if ($thread_sort_messages == 1 ) {
537 $indent_array = get_parent_level($imapConnection);
539 $fstring = "move_messages.php?msg=$msg&mailbox=$urlMailbox"
540 . "&startMessage=$start_msg";
541 mail_message_listing_beginning($imapConnection, $fstring,
542 $mailbox, $sort, $msg_cnt_str,
543 $paginator_str, $start_msg);
545 $groupNum = $start_msg %
($show_num - 1);
546 $real_startMessage = $start_msg;
548 if ($end_msg - $start_msg < $show_num - 1) {
549 $end_msg = $end_msg - $start_msg +
1;
551 } else if ($start_msg > $show_num) {
552 $end_msg = $show_num;
556 $endVar = $end_msg +
1;
559 * Loop through and display the info for each message.
560 * ($t is used for the checkbox number)
563 if ($num_msgs == 0) {
564 /* if there's no messages in this folder */
565 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN="
566 . count($index_order) . ">\n"
567 . " <CENTER><BR><B>". _("THIS FOLDER IS EMPTY")
568 . "</B><BR> </CENTER>\n"
570 } elseif ($start_msg == $end_msg) {
571 /* if there's only one message in the box, handle it differently. */
583 } while (isset ($key) && ($k < $i));
584 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort,
585 $real_startMessage, 0, 0);
594 } while (isset ($key) && ($k < $i));
596 printMessageInfo($imapConnection, $t, $i, $key, $mailbox,
597 $sort, $real_startMessage, 0, 0);
602 } while ($i && $i < $endVar);
606 . "<table bgcolor=\"$color[9]\" width=\"100%\" border=0 cellpadding=1 "
607 . "cellspacing=1><tr BGCOLOR=\"$color[4]\"><td>"
608 . "<table width=\"100%\" BGCOLOR=\"$color[4]\" border=0 cellpadding=1 "
609 . "cellspacing=0><tr><td>$paginator_str</td>"
610 . "<td align=right>$msg_cnt_str</td></tr></table>"
611 . "</td></tr></table>";
612 /* End of message-list table */
614 do_hook('mailbox_index_after');
615 echo "</TABLE></FORM>\n";
619 * Displays the standard message list header. To finish the table,
620 * you need to do a "</table></table>";
622 * $moveURL is the URL to submit the delete/move form to
623 * $mailbox is the current mailbox
624 * $sort is the current sorting method (-1 for no sorting available [searches])
625 * $Message is a message that is centered on top of the list
626 * $More is a second line that is left aligned
628 function mail_message_listing_beginning ($imapConnection, $moveURL,
629 $mailbox = '', $sort = -1,
631 $paginator = ' ',
633 global $color, $index_order, $auto_expunge, $move_to_trash, $base_uri,
634 $checkall, $sent_folder, $draft_folder, $thread_sort_messages,
635 $allow_thread_sort, $allow_server_sort, $server_sort_order;
636 $urlMailbox = urlencode($mailbox);
639 * This is the beginning of the message list table.
640 * It wraps around all messages
642 echo "<FORM name=messageList method=post action=\"$moveURL\">\n"
643 . "<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLPADDING=\"1\" "
644 . "CELLSPACING=\"0\">\n<TR BGCOLOR=\"$color[0]\"><TD>"
645 . " <TABLE BGCOLOR=\"$color[4]\" width=\"100%\" CELLPADDING=\"2\" "
646 . "CELLSPACING=\"0\" BORDER=\"0\"><TR>\n"
647 . " <TD ALIGN=LEFT>$paginator\n";
649 echo " <TD ALIGN=RIGHT>$msg_cnt_str</TD>\n"
652 . "<TR><TD BGCOLOR=\"$color[0]\">\n"
653 . "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0"
654 . "cellspacing=0 width=\"100%\">\n"
656 . " <TD ALIGN=LEFT VALIGN=MIDDLE NOWRAP>\n"
657 . ' <SMALL> ' . _("Move Selected To:") . "</SMALL>\n"
659 . " <TD ALIGN=RIGHT NOWRAP>\n"
660 . ' <SMALL> ' . _("Transform Selected Messages")
661 . ": </SMALL><BR>\n"
665 . " <TD ALIGN=\"LEFT\" VALIGN=\"MIDDLE\" NOWRAP>\n"
666 . ' <SMALL> <TT><SELECT NAME="targetMailbox">';
668 $boxes = sqimap_mailbox_list($imapConnection);
669 foreach ($boxes as $boxes_part) {
670 if (!in_array('noselect', $boxes_part['flags'])) {
671 $box = $boxes_part['unformatted'];
672 $box2 = str_replace(' ', ' ', $boxes_part['unformatted-disp']);
673 if( $box2 == 'INBOX' ) {
676 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
679 echo ' </SELECT></TT> '
680 . '<INPUT TYPE="SUBMIT" NAME="moveButton" VALUE="' . _("Move") . '"> '
681 . '<INPUT TYPE="SUBMIT" NAME="attache" VALUE="' . _("Forward")
682 . "\"> \n" . "</SMALL>\n";
685 . " <TD ALIGN=\"RIGHT\" NOWRAP>";
686 if (!$auto_expunge) {
687 echo '<INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="' . _("Expunge")
688 . '"> ' . _("mailbox") . ' ';
690 echo '<INPUT TYPE="SUBMIT" NAME="markRead" VALUE="' . _("Read") . '">'
691 . '<INPUT TYPE="SUBMIT" NAME="markUnread" VALUE="' . _("Unread") . '">'
692 . '<INPUT TYPE="SUBMIT" VALUE="' . _("Delete") . '"> '
696 /* draws thread sorting links */
697 if ($allow_thread_sort == TRUE) {
698 if ($thread_sort_messages == 1 ) {
700 $thread_name = 'Unthread View';
702 elseif ($thread_sort_messages == 0) {
704 $thread_name = 'Thread View';
706 echo '<tr><td> <a href=' . "$base_uri" . 'src/right_main.php?sort='
707 . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
708 . '&mailbox=' . urlencode($mailbox) . '><small>' . _("$thread_name")
709 . '</a></small> </td></tr>';
713 do_hook('mailbox_form_before');
715 . "<TR><TD BGCOLOR=\"$color[0]\">"
716 . '<TABLE WIDTH="100%" BORDER=0 CELLPADDING=2 CELLSPACING=';
717 if ($GLOBALS['alt_index_colors']){
722 echo " BGCOLOR=\"$color[0]\">"
723 . "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
724 /* if using server sort we highjack the
725 * the $sort var and use $server_sort_order
726 * instead. but here we reset sort for a bit
729 if ($allow_server_sort == TRUE) {
730 $sort = $server_sort_order;
732 /* Print the headers. */
733 for ($i=1; $i <= count($index_order); $i++
) {
734 switch ($index_order[$i]) {
735 case 1: /* checkbox */
737 echo ' <TD WIDTH="1%"><B> </B></TD>';
740 if (handleAsSent($mailbox)) {
741 echo ' <TD WIDTH="25%"><B>' . _("To") . '</B>';
743 echo ' <TD WIDTH="25%"><B>' . _("From") . '</B>';
745 if ($allow_thread_sort != TRUE ||
$thread_sort_messages != 1) {
746 ShowSortButton($sort, $mailbox, 2, 3);
751 echo ' <TD NOWRAP WIDTH="5%"><B>' . _("Date") . '</B>';
752 if ($allow_thread_sort != TRUE ||
$thread_sort_messages != 1) {
753 ShowSortButton($sort, $mailbox, 0, 1);
757 case 4: /* subject */
758 echo ' <TD><B>' . _("Subject") . '</B> ';
759 if ($allow_thread_sort != TRUE ||
$thread_sort_messages != 1) {
760 ShowSortButton($sort, $mailbox, 4, 5);
765 echo ' <TD WIDTH="5%"><b>' . _("Size") . "</b></TD>\n";
769 /* if using server-sorting,
770 * send sort back to 6
772 if ($allow_server_sort == TRUE) {
779 * This function shows the sort button. Isn't this a good comment?
781 function ShowSortButton($sort, $mailbox, $Up, $Down) {
782 /* Figure out which image we want to use. */
783 if ($sort != $Up && $sort != $Down) {
784 $img = 'sort_none.png';
786 } elseif ($sort == $Up) {
787 $img = 'up_pointer.png';
790 $img = 'down_pointer.png';
794 /* Now that we have everything figured out, show the actual button. */
795 echo ' <a href="right_main.php?newsort=' . $which
796 . '&startMessage=1&mailbox=' . urlencode($mailbox)
797 . '"><IMG SRC="../images/' . $img
798 . '" BORDER=0 WIDTH=12 HEIGHT=10></a>';
801 function get_selectall_link($start_msg, $sort) {
802 global $checkall, $what, $where, $mailbox, $javascript_on;
803 global $PHP_SELF, $PG_SHOWNUM;
806 if ($javascript_on) {
808 '<script language="JavaScript" type="text/javascript">'
810 . "function CheckAll() {\n"
811 . " for (var i = 0; i < document.messageList.elements.length; i++) {\n"
812 . " if(document.messageList.elements[i].type == 'checkbox'){\n"
813 . " document.messageList.elements[i].checked = "
814 . " !(document.messageList.elements[i].checked);\n"
819 . '</script><a href="#" onClick="CheckAll();">' . _("Toggle All")
822 if (strpos($PHP_SELF, "?")) {
823 $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($mailbox)
824 . "&startMessage=$start_msg&sort=$sort&checkall=";
826 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
827 . "&startMessage=$start_msg&sort=$sort&checkall=";
829 if (isset($checkall) && $checkall == '1') {
835 if (isset($where) && isset($what)) {
836 $result .= '&where=' . urlencode($where)
837 . '&what=' . urlencode($what);
842 if (isset($checkall) && ($checkall == '1')) {
843 $result .= _("Unselect All");
845 $result .= _("Select All");
851 /* Return our final result. */
856 * This function computes the "Viewing Messages..." string.
858 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
859 /* Compute the $msg_cnt_str. */
861 if ($start_msg < $end_msg) {
862 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"),
863 $start_msg, $end_msg, $num_msgs);
864 } else if ($start_msg == $end_msg) {
865 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
870 /* Return our result string. */
875 * Generate a paginator link.
877 function get_paginator_link($box, $start_msg, $use, $text) {
878 $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
879 . "&startMessage=$start_msg&mailbox=$box\" "
880 . "TARGET=\"right\">$text</A>";
885 * This function computes the paginator string.
887 function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
889 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
891 /* Initialize paginator string chunks. */
898 /* Create simple strings that will be creating the paginator. */
899 $spc = ' '; /* This will be used as a space. */
900 $sep = '|'; /* This will be used as a seperator. */
902 /* Get some paginator preference values. */
903 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON
);
904 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
);
906 /* Make sure that our start message number is not too big. */
907 $start_msg = min($start_msg, $num_msgs);
909 /* Decide whether or not we will use the mailbox cache. */
910 /* Not sure why $use_mailbox_cache is even passed in. */
917 /* Compute the starting message of the previous and next page group. */
918 $next_grp = $start_msg +
$show_num;
919 $prev_grp = $start_msg - $show_num;
921 /* Compute the basic previous and next strings. */
922 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
923 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
924 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
925 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
926 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
927 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
928 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
929 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
930 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
933 /* Page selector block. Following code computes page links. */
934 if ($pg_sel && ($num_msgs > $show_num)) {
935 /* Most importantly, what is the current page!!! */
936 $cur_pg = intval($start_msg / $show_num) +
1;
938 /* Compute total # of pages and # of paginator page links. */
939 $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
940 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
942 /* Compute the size of the four quarters of the page links. */
944 /* If we can, just show all the pages. */
945 if (($tot_pgs - 1) <= $pg_max) {
946 $q1_pgs = $cur_pg - 1;
947 $q2_pgs = $q3_pgs = 0;
948 $q4_pgs = $tot_pgs - $cur_pg;
950 /* Otherwise, compute some magic to choose the four quarters. */
953 * Compute the magic base values. Added together,
954 * these values will always equal to the $pag_pgs.
955 * NOTE: These are DEFAULT values and do not take
956 * the current page into account. That is below.
958 $q1_pgs = floor($vis_pgs/4);
959 $q2_pgs = round($vis_pgs/4, 0);
960 $q3_pgs = ceil($vis_pgs/4);
961 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
963 /* Adjust if the first quarter contains the current page. */
964 if (($cur_pg - $q1_pgs) < 1) {
965 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) +
$q2_pgs;
966 $q1_pgs = $cur_pg - 1;
968 $q3_pgs +
= ceil($extra_pgs / 2);
969 $q4_pgs +
= floor($extra_pgs / 2);
971 /* Adjust if the first and second quarters intersect. */
972 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
973 $extra_pgs = $q2_pgs;
974 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
975 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
976 $q3_pgs +
= ceil($extra_pgs / 2);
977 $q4_pgs +
= floor($extra_pgs / 2);
979 /* Adjust if the fourth quarter contains the current page. */
980 } else if (($cur_pg +
$q4_pgs) >= $tot_pgs) {
981 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) +
$q3_pgs;
983 $q4_pgs = $tot_pgs - $cur_pg;
984 $q1_pgs +
= floor($extra_pgs / 2);
985 $q2_pgs +
= ceil($extra_pgs / 2);
987 /* Adjust if the third and fourth quarter intersect. */
988 } else if (($cur_pg +
$q3_pgs +
1) >= ($tot_pgs - $q4_pgs +
1)) {
989 $extra_pgs = $q3_pgs;
990 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
991 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
992 $q1_pgs +
= floor($extra_pgs / 2);
993 $q2_pgs +
= ceil($extra_pgs / 2);
998 * I am leaving this debug code here, commented out, because
999 * it is a really nice way to see what the above code is doing.
1000 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
1001 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
1004 /* Print out the page links from the compute page quarters. */
1006 /* Start with the first quarter. */
1007 if (($q1_pgs == 0) && ($cur_pg > 1)) {
1008 $pg_str .= "...$spc";
1010 for ($pg = 1; $pg <= $q1_pgs; ++
$pg) {
1011 $start = (($pg-1) * $show_num) +
1;
1012 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1014 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
1015 $pg_str .= "...$spc";
1019 /* Continue with the second quarter. */
1020 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++
$pg) {
1021 $start = (($pg-1) * $show_num) +
1;
1022 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1025 /* Now print the current page. */
1026 $pg_str .= $cur_pg . $spc;
1028 /* Next comes the third quarter. */
1029 for ($pg = $cur_pg +
1; $pg <= $cur_pg +
$q3_pgs; ++
$pg) {
1030 $start = (($pg-1) * $show_num) +
1;
1031 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1034 /* And last, print the forth quarter page links. */
1035 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
1036 $pg_str .= "...$spc";
1038 if (($tot_pgs - $q4_pgs) > ($cur_pg +
$q3_pgs)) {
1039 $pg_str .= "...$spc";
1041 for ($pg = $tot_pgs - $q4_pgs +
1; $pg <= $tot_pgs; ++
$pg) {
1042 $start = (($pg-1) * $show_num) +
1;
1043 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1046 } else if ($PG_SHOWNUM == 999999) {
1047 $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
1048 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1049 . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc;
1052 /* If necessary, compute the 'show all' string. */
1053 if (($prv_str != '') ||
($nxt_str != '')) {
1054 $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
1055 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1056 . "TARGET=\"right\">" . _("Show All") . '</A>';
1059 /* Last but not least, get the value for the toggle all link. */
1060 $tgl_str = get_selectall_link($start_msg, $sort);
1062 /* Put all the pieces of the paginator string together. */
1064 * Hairy code... But let's leave it like it is since I am not certain
1065 * a different approach would be any easier to read. ;)
1068 $result .= ($prv_str != '' ?
$prv_str . $spc . $sep . $spc : '');
1069 $result .= ($nxt_str != '' ?
$nxt_str . $spc . $sep . $spc : '');
1070 $result .= ($pg_str != '' ?
$pg_str : '');
1071 $result .= ($all_str != '' ?
$sep . $spc . $all_str . $spc : '');
1072 $result .= ($result != '' ?
$sep . $spc . $tgl_str: $tgl_str);
1074 /* If the resulting string is blank, return a non-breaking space. */
1075 if ($result == '') {
1079 /* Return our final magical paginator string. */
1083 function processSubject($subject) {
1084 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1086 return _("(no subject)");
1088 if (strlen($subject) <= 55)
1091 $ent_strlen=strlen($subject);
1095 * see if this is entities-encoded string
1096 * If so, Iterate through the whole string, find out
1097 * the real number of characters, and if more
1098 * than 55, substr with an updated trim value.
1100 while ( (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1101 (($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false) ) {
1102 $trim_val +
= ($ent_loc_end-$ent_loc)+
1;
1103 $ent_strlen -= $ent_loc_end-$ent_loc;
1104 $ent_offset = $ent_loc_end+
1;
1107 if ($ent_strlen <= 55){
1111 return substr($subject, 0, $trim_val) . '...';
1114 function handleAsSent($mailbox) {
1115 global $sent_folder, $draft_folder, $handleAsSent_result;
1117 /* First check if this is the sent or draft folder. */
1118 $handleAsSent_result = (($mailbox == $sent_folder)
1119 ||
($mailbox == $draft_folder));
1121 /* Then check the result of the handleAsSent hook. */
1122 do_hook('check_handleAsSent_result', $mailbox);
1124 /* And return the result. */
1125 return ($handleAsSent_result);