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/html.php');
17 require_once('../class/html.class.php');
18 require_once('../functions/imap_mailbox.php');
20 /* Default value for page_selector_max. */
21 define('PG_SEL_MAX', 10);
23 function printMessageInfo($imapConnection, $t, $i, $key, $mailbox,
24 $start_msg, $where, $what) {
26 $color, $msgs, $msort,
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];
52 if( $mailbox == 'None' ) {
53 $boxes = sqimap_mailbox_list($imapConnection);
54 $mailbox = $boxes[0]['unformatted'];
57 $urlMailbox = urlencode($mailbox);
59 if (handleAsSent($mailbox)) {
60 $msg['FROM'] = $msg['TO'];
62 * This is done in case you're looking into Sent folders,
63 * because you can have multiple receivers.
65 $senderNames = explode(',', $msg['FROM']);
67 if (sizeof($senderNames)){
68 foreach ($senderNames as $senderNames_part) {
69 if ($senderName != '') {
72 $senderName .= sqimap_find_displayable_name($senderNames_part);
76 $senderName = sqimap_find_displayable_name($msg['FROM']);
79 $subject = processSubject($msg['SUBJECT']);
81 echo html_tag( 'tr' ) . "\n";
83 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
84 $flag = "<font color=\"$color[2]\">";
85 $flag_end = '</font>';
90 if (!isset($msg['FLAG_SEEN']) ||
($msg['FLAG_SEEN'] == false)) {
97 if (handleAsSent($mailbox)) {
104 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
105 $fontstr = "<font color=\"$color[9]\">";
106 $fontstr_end = '</font>';
112 if ($where && $what) {
113 $searchstr = '&where='.$where.'&what='.$what;
118 * AAAAH! Make my eyes stop bleeding!
121 if (sizeof($message_highlight_list)){
122 foreach ($message_highlight_list as $message_highlight_list_part) {
123 if (trim($message_highlight_list_part['value']) != '') {
124 if ($message_highlight_list_part['match_type'] == 'to_cc') {
125 if (strstr('^^' . strtolower($msg['TO']),
126 strtolower($message_highlight_list_part['value']))
127 ||
strstr('^^'.strtolower($msg['CC']),
128 strtolower($message_highlight_list_part['value']))) {
129 $hlt_color = $message_highlight_list_part['color'];
133 if (strstr('^^' . strtolower($msg[strtoupper($message_highlight_list_part['match_type'])]),
134 strtolower($message_highlight_list_part['value']))) {
135 $hlt_color = $message_highlight_list_part['color'];
142 if (!isset($hlt_color)) {
143 $hlt_color = $color_string;
146 $checked = ($checkall == 1) ?
' checked' : '';
153 if (sizeof($index_order)){
154 foreach ($index_order as $index_order_part) {
155 switch ($index_order_part) {
156 case 1: /* checkbox */
158 "<input type=checkbox name=\"msg[$t]\" value=\"".$msg['ID']."\"$checked>",
164 $italic . $bold . $flag . $fontstr . $senderName .
165 $fontstr_end . $flag_end . $bold_end . $italic_end,
171 $bold . $flag . $fontstr . $msg['DATE_STRING'] .
172 $fontstr_end . $flag_end . $bold_end,
177 case 4: /* subject */
179 if ($thread_sort_messages == 1) {
180 if (isset($indent_array[$msg["ID"]])) {
181 $td_str .= str_repeat(" ",$indent_array[$msg['ID']]);
184 $td_str .= '<a href="read_body.php?mailbox='.$urlMailbox
185 .'&passed_id='. $msg["ID"]
186 . '&startMessage='.$start_msg.$searchstr.'"';
187 do_hook("subject_link");
188 if ($subject != $msg['SUBJECT']) {
189 $title = get_html_translation_table(HTML_SPECIALCHARS
);
190 $title = array_flip($title);
191 $title = strtr($msg['SUBJECT'], $title);
192 $title = str_replace('"', "''", $title);
193 $td_str .= " title=\"$title\"";
195 $td_str .= ">$flag$subject$flag_end</a>$bold_end";
196 echo html_tag( 'td', $td_str, 'left', $hlt_color );
200 $td_str = "<b><small>";
202 if (isset($msg['FLAG_ANSWERED']) && $msg['FLAG_ANSWERED'] == true) {
206 if ($msg['TYPE0'] == 'multipart') {
210 if ($default_use_priority) {
211 if ( ($msg['PRIORITY'] == 1) ||
($msg['PRIORITY'] == 2) ) {
212 $td_str .= "<font color=\"$color[1]\">!</font>";
215 if ($msg['PRIORITY'] == 5) {
216 $td_str .= "<font color=\"$color[8]\">?</font>";
220 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'] == true) {
221 $td_str .= "<font color=\"$color[1]\">D</font>";
227 $td_str .= '</small></b>';
237 $bold . $fontstr . show_readable_size($msg['SIZE']) .
238 $fontstr_end . $bold_end,
248 function getThreadMessages($imapConnection, $start_msg, $show_num, $num_msgs) {
249 $id = get_thread_sort($imapConnection);
251 if ($start_msg +
($show_num - 1) < $num_msgs) {
252 $end_msg = $start_msg +
($show_num-1);
254 $end_msg = $num_msgs;
256 $id = array_slice($id, ($start_msg-1), ($end_msg));
258 $end = $start_msg +
$show_num - 1;
259 if ($num_msgs < $show_num) {
260 $end_loop = $num_msgs;
261 } else if ($end > $num_msgs) {
262 $end_loop = $num_msgs - $start_msg +
1;
264 $end_loop = $show_num;
266 return fillMessageArray($imapConnection,$id,$end_loop);
272 function getServerSortMessages($imapConnection, $start_msg, $show_num,
273 $num_msgs, $server_sort_order, $mbxresponse) {
274 $id = sqimap_get_sort_order($imapConnection, $server_sort_order,$mbxresponse);
276 if ($start_msg +
($show_num - 1) < $num_msgs) {
277 $end_msg = $start_msg +
($show_num-1);
279 $end_msg = $num_msgs;
281 $id = array_slice($id, ($start_msg-1), ($end_msg));
283 $end = $start_msg +
$show_num - 1;
284 if ($num_msgs < $show_num) {
285 $end_loop = $num_msgs;
286 } else if ($end > $num_msgs) {
287 $end_loop = $num_msgs - $start_msg +
1;
289 $end_loop = $show_num;
291 return fillMessageArray($imapConnection,$id,$end_loop);
297 function getSelfSortMessages($imapConnection, $start_msg, $show_num,
298 $num_msgs, $sort, $mbxresponse) {
300 if ($num_msgs >= 1) {
301 $id = sqimap_get_php_sort_order ($imapConnection, $mbxresponse);
306 /* if it's not sorted */
307 if ($start_msg +
($show_num - 1) < $num_msgs) {
308 $end_msg = $start_msg +
($show_num - 1);
310 $end_msg = $num_msgs;
312 if ($end_msg < $start_msg) {
313 $start_msg = $start_msg - $show_num;
314 if ($start_msg < 1) {
318 $id = array_slice(array_reverse($id), ($start_msg-1), ($end_msg));
319 $end = $start_msg +
$show_num - 1;
320 if ($num_msgs < $show_num) {
321 $end_loop = $num_msgs;
322 } else if ($end > $num_msgs) {
323 $end_loop = $num_msgs - $start_msg +
1;
325 $end_loop = $show_num;
328 $msgs = fillMessageArray($imapConnection,$id,$end_loop);
336 * This function loops through a group of messages in the mailbox
337 * and shows them to the user.
339 function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
340 $start_msg, $sort, $color, $show_num,
341 $use_cache, $mode='') {
342 global $msgs, $msort, $auto_expunge, $thread_sort_messages,
343 $allow_server_sort, $server_sort_order;
345 /* If autoexpunge is turned on, then do it now. */
346 $mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox);
348 /* If autoexpunge is turned on, then do it now. */
349 if ($auto_expunge == true) {
350 $exp_cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, false, '');
351 $mbxresponse['EXISTS'] = $mbxresponse['EXISTS'] - $exp_cnt;
354 if ($mbxresponse['EXISTS']>0) {
355 /* if $start_msg is lower than $num_msgs, we probably deleted all messages
356 * in the last page. We need to re-adjust the start_msg
359 if($start_msg > $num_msgs) {
360 $start_msg -= $show_num;
366 /* This code and the next if() block check for
367 * server-side sorting methods. The $id array is
368 * formatted and $sort is set to 6 to disable
369 * SM internal sorting
372 if ($thread_sort_messages == 1) {
374 } elseif ($allow_server_sort == 1) {
375 $mode = 'serversort';
382 session_unregister('msort');
383 session_unregister('msgs');
384 $msgs = getThreadMessages($imapConnection, $start_msg, $show_num,
386 if ($msgs === false) {
387 echo '<b><small><center><font color=red>' .
388 _("Thread sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
389 '</center></small></b>';
390 $thread_sort_messages = 0;
391 $msort = $msgs = array();
392 session_register('msort');
393 session_register('msgs');
397 session_register('msort');
398 session_register('msgs');
403 $msgs = getServerSortMessages($imapConnection, $start_msg, $show_num,
404 $num_msgs, $sort, $mbxresponse);
405 if ($msgs === false) {
406 echo '<b><small><center><font color=red>' .
407 _( "Server-side sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
408 '</center></small></b>';
409 $sort = $server_sort_order;
410 $allow_server_sort = FALSE;
411 $msort = $msgs = array();
412 session_register('msort');
413 session_register('msgs');
418 session_register('msort');
419 session_register('msgs');
424 session_unregister('msgs');
425 session_unregister('msort');
426 $msgs= getSelfSortMessages($imapConnection, $start_msg, $show_num,
427 $num_msgs, $sort, $mbxresponse);
428 $msort = calc_msort($msgs, $sort);
429 session_register('msort');
430 session_register('msgs');
434 } /* if exists > 0 */
436 $res = getEndMessage($start_msg, $show_num, $num_msgs);
437 $start_msg = $res[0];
440 $paginator_str = get_paginator_str($mailbox, $start_msg, $end_msg,
441 $num_msgs, $show_num, $sort);
443 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
445 do_hook('mailbox_index_before');
447 mail_message_listing_beginning($imapConnection, $mailbox, $sort,
448 $msg_cnt_str, $paginator_str, $start_msg);
451 echo '<table bgcolor="' . $color[0] . '" border="0" width="100%" cellpadding="1" cellspacing="0"><tr><td>';
452 printHeader($mailbox, $srt, $color, !$thread_sort_messages);
454 displayMessageArray($imapConnection, $num_msgs, $start_msg,
455 $msort, $mailbox, $sort, $color, $show_num,0,0);
457 mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color);
458 echo '</td></tr></table>';
461 * TODO: Switch to using $_SESSION[] whenever we ditch the 4.0.x series.
465 function calc_msort($msgs, $sort) {
475 if (($sort == 0) ||
($sort == 1)) {
476 $msort = array_cleave ($msgs, 'TIME_STAMP');
477 } elseif (($sort == 2) ||
($sort == 3)) {
478 $msort = array_cleave ($msgs, 'FROM-SORT');
479 } elseif (($sort == 4) ||
($sort == 5)) {
480 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
494 function fillMessageArray($imapConnection,$id,$count) {
495 $msgs_list = sqimap_get_small_header_list($imapConnection, $id);
497 if (sizeof($msgs_list)){
498 foreach ($msgs_list as $hdr) {
499 $unique_id[] = $hdr->uid
;
500 $from[] = $hdr->from
;
501 $date[] = $hdr->date
;
502 $subject[] = $hdr->subject
;
504 $priority[] = $hdr->priority
;
506 $size[] = $hdr->size
;
507 $type[] = $hdr->type0
;
508 $flag_deleted[] = $hdr->flag_deleted
;
509 $flag_answered[] = $hdr->flag_answered
;
510 $flag_seen[] = $hdr->flag_seen
;
511 $flag_flagged[] = $hdr->flag_flagged
;
516 while ($j < $count) {
518 if (isset($date[$j])) {
519 $date[$j] = str_replace(' ', ' ', $date[$j]);
520 $tmpdate = explode(' ', trim($date[$j]));
522 $tmpdate = $date = array('', '', '', '', '', '');
524 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
525 $messages[$j]['DATE_STRING'] =
526 getDateString($messages[$j]['TIME_STAMP']);
527 $messages[$j]['ID'] = $unique_id[$j];
528 $messages[$j]['FROM'] = decodeHeader($from[$j]);
529 $messages[$j]['FROM-SORT'] =
530 strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
531 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
532 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
533 $messages[$j]['TO'] = decodeHeader($to[$j]);
534 $messages[$j]['PRIORITY'] = $priority[$j];
535 $messages[$j]['CC'] = $cc[$j];
536 $messages[$j]['SIZE'] = $size[$j];
537 $messages[$j]['TYPE0'] = $type[$j];
538 $messages[$j]['FLAG_DELETED'] = $flag_deleted[$j];
539 $messages[$j]['FLAG_ANSWERED'] = $flag_answered[$j];
540 $messages[$j]['FLAG_SEEN'] = $flag_seen[$j];
541 $messages[$j]['FLAG_FLAGGED'] = $flag_flagged[$j];
545 * fix SUBJECT-SORT to remove Re:
549 * TODO: i18n should be incorporated here. E.g. we catch the ones
550 * we know about, but also define in i18n what the localized
551 * "Re: " is for this or that locale.
553 if (preg_match("/^(vedr|sv|re|aw):\s*(.*)$/si",
554 $messages[$j]['SUBJECT-SORT'], $matches)){
555 $messages[$j]['SUBJECT-SORT'] = $matches[2];
563 /* Generic function to convert the msgs array into an HTML table. */
564 function displayMessageArray($imapConnection, $num_msgs, $start_msg,
565 $msort, $mailbox, $sort, $color,
566 $show_num, $where=0, $what=0) {
567 global $imapServerAddress, $use_mailbox_cache,
568 $index_order, $checkall,
569 $indent_array, $thread_sort_messages, $allow_server_sort,
570 $server_sort_order, $PHP_SELF;
572 $res = getEndMessage($start_msg, $show_num, $num_msgs);
573 $start_msg = $res[0];
576 $urlMailbox = urlencode($mailbox);
578 /* get indent level for subject display */
579 if ($thread_sort_messages == 1 ) {
580 $indent_array = get_parent_level($imapConnection);
584 $real_startMessage = $start_msg;
586 if ($end_msg - $start_msg < $show_num - 1) {
587 $end_msg = $end_msg - $start_msg +
1;
589 } else if ($start_msg > $show_num) {
590 $end_msg = $show_num;
594 $endVar = $end_msg +
1;
597 * Loop through and display the info for each message.
598 * ($t is used for the checkbox number)
602 /* messages display */
604 if ($num_msgs == 0) {
605 /* if there's no messages in this folder */
608 "<BR><b>" . _("THIS FOLDER IS EMPTY") . "</b><BR> ",
611 'COLSPAN="' . count($index_order) . '"'
614 } elseif ($start_msg == $end_msg) {
615 /* if there's only one message in the box, handle it differently. */
627 } while (isset ($key) && ($k < $i));
628 printMessageInfo($imapConnection, $t, $i, $key, $mailbox,
629 $real_startMessage, $where, $what);
638 } while (isset ($key) && ($k < $i));
640 printMessageInfo($imapConnection, $t, $i, $key, $mailbox,
641 $real_startMessage, $where, $what);
646 } while ($i && $i < $endVar);
652 * Displays the standard message list header. To finish the table,
653 * you need to do a "</table></table>";
655 * $moveURL is the URL to submit the delete/move form to
656 * $mailbox is the current mailbox
657 * $sort is the current sorting method (-1 for no sorting available [searches])
658 * $Message is a message that is centered on top of the list
659 * $More is a second line that is left aligned
662 function mail_message_listing_beginning ($imapConnection,
663 $mailbox = '', $sort = -1,
665 $paginator = ' ',
667 global $color, $auto_expunge, $base_uri, $thread_sort_messages,
668 $allow_thread_sort, $allow_server_sort, $server_sort_order,
671 $urlMailbox = urlencode($mailbox);
673 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
674 $source_url = $regs[1];
676 $source_url = $PHP_SELF;
682 $moveURL = "move_messages.php?msg=$msg&mailbox=$urlMailbox"
683 . "&startMessage=$start_msg";
686 * This is the beginning of the message list table.
687 * It wraps around all messages
690 echo "<FORM name=\"messageList\" method=post action=\"$moveURL\">\n"
691 . html_tag( 'table' ,'' , '', '', 'border="0" width="100%" cellpadding="1" cellspacing="0"' ) .
696 html_tag( 'td', $paginator, 'left' ) .
697 html_tag( 'td', $msg_cnt_str, 'right' )
699 , '', $color[4], 'border="0" width="100%" cellpadding="2" cellspacing="0"' )
702 . html_tag( 'tr' ) . "\n"
703 . html_tag( 'td' ,'' , 'left', $color[0], '' )
704 . html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="0" cellspacing="0"' )
706 getSmallStringCell(_("Move Selected To"), 'left') .
707 getSmallStringCell(_("Transform Selected Messages"), 'right')
709 . html_tag( 'tr' ) ."\n"
710 . html_tag( 'td', '', 'left', '', 'valign="middle" nowrap' );
711 getMbxList($imapConnection);
712 echo getButton('SUBMIT', 'moveButton',_("Move")) . "\n";
713 echo getButton('SUBMIT', 'attache',_("Forward")) . "\n";
716 . html_tag( 'td', '', 'right', '', 'nowrap' );
718 if (!$auto_expunge) {
719 echo getButton('SUBMIT', 'expungeButton',_("Expunge"))
720 .' ' . _("mailbox") . "\n";
723 echo getButton('SUBMIT', 'markRead',_("Read"));
724 echo getButton('SUBMIT', 'markUnread',_("Unread"));
725 echo getButton('SUBMIT', 'delete',_("Delete")) ." \n";
726 if (!strpos($PHP_SELF,'mailbox')) {
727 $location = $PHP_SELF.'?mailbox=INBOX&startMessage=1';
729 $location = $PHP_SELF;
731 echo '<INPUT TYPE="HIDDEN" NAME="location" VALUE="'.$location.'">';
735 /* draws thread sorting links */
736 if ($allow_thread_sort == TRUE) {
737 if ($thread_sort_messages == 1 ) {
739 $thread_name = _("Unthread View");
741 elseif ($thread_sort_messages == 0) {
743 $thread_name = _("Thread View");
745 echo html_tag( 'tr' ,
747 ' <a href=' . $source_url . '?sort='
748 . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
749 . '&mailbox=' . urlencode($mailbox) . '><small>' . $thread_name
750 . '</a></small> '
759 do_hook('mailbox_form_before');
763 . html_tag( 'td' ,'' , '', $color[0], '' );
764 if ($GLOBALS['alt_index_colors']){
769 echo html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="2" cellspacing="'. $cellspacing .'"' );
771 /* if using server sort we highjack the
772 * the $sort var and use $server_sort_order
773 * instead. but here we reset sort for a bit
776 if ($allow_server_sort == TRUE) {
777 $sort = $server_sort_order;
781 function mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color) {
783 echo html_tag( 'table',
788 html_tag( 'td', $paginator_str ) .
789 html_tag( 'td', $msg_cnt_str, 'right' )
791 , '', $color[4], 'width="100%" cellpadding="1" cellspacing="1"' )
794 , '', $color[9], 'width="100%" cellpadding="1" cellspacing="1"' );
797 /* End of message-list table */
799 do_hook('mailbox_index_after');
804 function printHeader($mailbox, $sort, $color, $showsort=true) {
806 echo html_tag( 'table' ,'' , '', $color[4], 'border="0" width="100%" cellpadding="1" cellspacing="0"' );
807 echo html_tag( 'tr' ,'' , 'center', $color[5] );
808 for ($i=1; $i <= count($index_order); $i++
) {
809 switch ($index_order[$i]) {
810 case 1: /* checkbox */
812 echo html_tag( 'td' ,' ' , '', '', 'width="1%"' );
815 if (handleAsSent($mailbox)) {
816 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
817 . '<b>' . _("To") . '</b>';
819 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
820 . '<b>' . _("From") . '</b>';
823 ShowSortButton($sort, $mailbox, 2, 3);
828 echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
829 . '<b>' . _("Date") . '</b>';
831 ShowSortButton($sort, $mailbox, 0, 1);
835 case 4: /* subject */
836 echo html_tag( 'td' ,'' , 'left', '', '' )
837 . '<b>' . _("Subject") . '</b>';
839 ShowSortButton($sort, $mailbox, 4, 5);
844 echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%"' );
853 * This function shows the sort button. Isn't this a good comment?
855 function ShowSortButton($sort, $mailbox, $Up, $Down ) {
857 /* Figure out which image we want to use. */
858 if ($sort != $Up && $sort != $Down) {
859 $img = 'sort_none.png';
861 } elseif ($sort == $Up) {
862 $img = 'up_pointer.png';
865 $img = 'down_pointer.png';
869 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
870 $source_url = $regs[1];
872 $source_url = $PHP_SELF;
875 /* Now that we have everything figured out, show the actual button. */
876 echo ' <a href="' . $source_url .'?newsort=' . $which
877 . '&startMessage=1&mailbox=' . urlencode($mailbox)
878 . '"><IMG SRC="../images/' . $img
879 . '" BORDER=0 WIDTH=12 HEIGHT=10 ALT="sort"></a>';
882 function get_selectall_link($start_msg, $sort) {
883 global $checkall, $what, $where, $mailbox, $javascript_on;
884 global $PHP_SELF, $PG_SHOWNUM;
887 if ($javascript_on) {
889 '<script language="JavaScript" type="text/javascript">'
891 . "function CheckAll() {\n"
892 . " for (var i = 0; i < document.messageList.elements.length; i++) {\n"
893 . " if(document.messageList.elements[i].type == 'checkbox'){\n"
894 . " document.messageList.elements[i].checked = "
895 . " !(document.messageList.elements[i].checked);\n"
900 . '</script><a href="#" onClick="CheckAll();">' . _("Toggle All")
903 if (strpos($PHP_SELF, "?")) {
904 $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($mailbox)
905 . "&startMessage=$start_msg&sort=$sort&checkall=";
907 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
908 . "&startMessage=$start_msg&sort=$sort&checkall=";
910 if (isset($checkall) && $checkall == '1') {
916 if (isset($where) && isset($what)) {
917 $result .= '&where=' . urlencode($where)
918 . '&what=' . urlencode($what);
923 if (isset($checkall) && ($checkall == '1')) {
924 $result .= _("Unselect All");
926 $result .= _("Select All");
932 /* Return our final result. */
937 * This function computes the "Viewing Messages..." string.
939 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
940 /* Compute the $msg_cnt_str. */
942 if ($start_msg < $end_msg) {
943 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"),
944 $start_msg, $end_msg, $num_msgs);
945 } else if ($start_msg == $end_msg) {
946 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
950 /* Return our result string. */
955 * Generate a paginator link.
957 function get_paginator_link($box, $start_msg, $use, $text) {
960 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
961 $source_url = $regs[1];
963 $source_url = $PHP_SELF;
966 $result = '<A HREF="'. $source_url . "?use_mailbox_cache=$use"
967 . "&startMessage=$start_msg&mailbox=$box\" "
968 . "TARGET=\"right\">$text</A>";
973 * This function computes the paginator string.
975 function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
977 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
979 /* Initialize paginator string chunks. */
986 $box = urlencode($box);
988 /* Create simple strings that will be creating the paginator. */
989 $spc = ' '; /* This will be used as a space. */
990 $sep = '|'; /* This will be used as a seperator. */
992 /* Get some paginator preference values. */
993 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON
);
994 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
);
996 /* Make sure that our start message number is not too big. */
997 $start_msg = min($start_msg, $num_msgs);
999 /* Decide whether or not we will use the mailbox cache. */
1000 /* Not sure why $use_mailbox_cache is even passed in. */
1007 /* Compute the starting message of the previous and next page group. */
1008 $next_grp = $start_msg +
$show_num;
1009 $prev_grp = $start_msg - $show_num;
1011 /* Compute the basic previous and next strings. */
1012 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
1013 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1014 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1015 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
1016 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1017 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
1018 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
1019 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
1020 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1023 /* Page selector block. Following code computes page links. */
1024 if ($pg_sel && ($num_msgs > $show_num)) {
1025 /* Most importantly, what is the current page!!! */
1026 $cur_pg = intval($start_msg / $show_num) +
1;
1028 /* Compute total # of pages and # of paginator page links. */
1029 $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
1030 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
1032 /* Compute the size of the four quarters of the page links. */
1034 /* If we can, just show all the pages. */
1035 if (($tot_pgs - 1) <= $pg_max) {
1036 $q1_pgs = $cur_pg - 1;
1037 $q2_pgs = $q3_pgs = 0;
1038 $q4_pgs = $tot_pgs - $cur_pg;
1040 /* Otherwise, compute some magic to choose the four quarters. */
1043 * Compute the magic base values. Added together,
1044 * these values will always equal to the $pag_pgs.
1045 * NOTE: These are DEFAULT values and do not take
1046 * the current page into account. That is below.
1048 $q1_pgs = floor($vis_pgs/4);
1049 $q2_pgs = round($vis_pgs/4, 0);
1050 $q3_pgs = ceil($vis_pgs/4);
1051 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
1053 /* Adjust if the first quarter contains the current page. */
1054 if (($cur_pg - $q1_pgs) < 1) {
1055 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) +
$q2_pgs;
1056 $q1_pgs = $cur_pg - 1;
1058 $q3_pgs +
= ceil($extra_pgs / 2);
1059 $q4_pgs +
= floor($extra_pgs / 2);
1061 /* Adjust if the first and second quarters intersect. */
1062 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
1063 $extra_pgs = $q2_pgs;
1064 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1065 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1066 $q3_pgs +
= ceil($extra_pgs / 2);
1067 $q4_pgs +
= floor($extra_pgs / 2);
1069 /* Adjust if the fourth quarter contains the current page. */
1070 } else if (($cur_pg +
$q4_pgs) >= $tot_pgs) {
1071 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) +
$q3_pgs;
1073 $q4_pgs = $tot_pgs - $cur_pg;
1074 $q1_pgs +
= floor($extra_pgs / 2);
1075 $q2_pgs +
= ceil($extra_pgs / 2);
1077 /* Adjust if the third and fourth quarter intersect. */
1078 } else if (($cur_pg +
$q3_pgs +
1) >= ($tot_pgs - $q4_pgs +
1)) {
1079 $extra_pgs = $q3_pgs;
1080 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1081 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1082 $q1_pgs +
= floor($extra_pgs / 2);
1083 $q2_pgs +
= ceil($extra_pgs / 2);
1088 * I am leaving this debug code here, commented out, because
1089 * it is a really nice way to see what the above code is doing.
1090 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
1091 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
1094 /* Print out the page links from the compute page quarters. */
1096 /* Start with the first quarter. */
1097 if (($q1_pgs == 0) && ($cur_pg > 1)) {
1098 $pg_str .= "...$spc";
1100 for ($pg = 1; $pg <= $q1_pgs; ++
$pg) {
1101 $start = (($pg-1) * $show_num) +
1;
1102 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1104 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
1105 $pg_str .= "...$spc";
1109 /* Continue with the second quarter. */
1110 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++
$pg) {
1111 $start = (($pg-1) * $show_num) +
1;
1112 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1115 /* Now print the current page. */
1116 $pg_str .= $cur_pg . $spc;
1118 /* Next comes the third quarter. */
1119 for ($pg = $cur_pg +
1; $pg <= $cur_pg +
$q3_pgs; ++
$pg) {
1120 $start = (($pg-1) * $show_num) +
1;
1121 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1124 /* And last, print the forth quarter page links. */
1125 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
1126 $pg_str .= "...$spc";
1128 if (($tot_pgs - $q4_pgs) > ($cur_pg +
$q3_pgs)) {
1129 $pg_str .= "...$spc";
1131 for ($pg = $tot_pgs - $q4_pgs +
1; $pg <= $tot_pgs; ++
$pg) {
1132 $start = (($pg-1) * $show_num) +
1;
1133 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1136 } else if ($PG_SHOWNUM == 999999) {
1137 $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
1138 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1139 . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc;
1142 /* If necessary, compute the 'show all' string. */
1143 if (($prv_str != '') ||
($nxt_str != '')) {
1144 $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
1145 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1146 . "TARGET=\"right\">" . _("Show All") . '</A>';
1149 /* Last but not least, get the value for the toggle all link. */
1150 $tgl_str = get_selectall_link($start_msg, $sort);
1152 /* Put all the pieces of the paginator string together. */
1154 * Hairy code... But let's leave it like it is since I am not certain
1155 * a different approach would be any easier to read. ;)
1158 $result .= ($prv_str != '' ?
$prv_str . $spc . $sep . $spc : '');
1159 $result .= ($nxt_str != '' ?
$nxt_str . $spc . $sep . $spc : '');
1160 $result .= ($pg_str != '' ?
$pg_str : '');
1161 $result .= ($all_str != '' ?
$sep . $spc . $all_str . $spc : '');
1162 $result .= ($result != '' ?
$sep . $spc . $tgl_str: $tgl_str);
1164 /* If the resulting string is blank, return a non-breaking space. */
1165 if ($result == '') {
1169 /* Return our final magical paginator string. */
1173 function processSubject($subject) {
1174 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1176 return _("(no subject)");
1178 if (strlen($subject) <= 55)
1181 $ent_strlen=strlen($subject);
1185 * see if this is entities-encoded string
1186 * If so, Iterate through the whole string, find out
1187 * the real number of characters, and if more
1188 * than 55, substr with an updated trim value.
1190 while ( (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1191 (($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false) ) {
1192 $trim_val +
= ($ent_loc_end-$ent_loc)+
1;
1193 $ent_strlen -= $ent_loc_end-$ent_loc;
1194 $ent_offset = $ent_loc_end+
1;
1197 if ($ent_strlen <= 55){
1201 return substr($subject, 0, $trim_val) . '...';
1204 function getMbxList($imapConnection) {
1205 global $lastTargetMailbox;
1206 echo ' <small> <tt><select name="targetMailbox">';
1207 $boxes = sqimap_mailbox_list($imapConnection);
1208 foreach ($boxes as $boxes_part) {
1209 if (!in_array('noselect', $boxes_part['flags'])) {
1210 $box = $boxes_part['unformatted'];
1211 $box2 = str_replace(' ', ' ', imap_utf7_decode_local($boxes_part['unformatted-disp']));
1212 if( $box2 == 'INBOX' ) {
1215 if ($lastTargetMailbox == $box) {
1216 echo " <OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
1219 echo " <OPTION VALUE=\"$box\">$box2</OPTION>\n";
1223 echo ' </SELECT></TT> ';
1226 function getButton($type, $name, $value) {
1227 return '<INPUT TYPE="'.$type.'" NAME="'.$name.'" VALUE="'.$value . '">';
1230 function getSmallStringCell($string, $align) {
1231 return html_tag( 'td',
1232 '<small>' . $string . ': </small>',
1238 function getEndMessage($start_msg, $show_num, $num_msgs) {
1239 if ($start_msg +
($show_num - 1) < $num_msgs){
1240 $end_msg = $start_msg +
($show_num - 1);
1242 $end_msg = $num_msgs;
1245 if ($end_msg < $start_msg) {
1246 $start_msg = $start_msg - $show_num;
1247 if ($start_msg < 1) {
1251 return (array($start_msg,$end_msg));
1254 function handleAsSent($mailbox) {
1255 global $sent_folder, $draft_folder, $handleAsSent_result;
1257 /* First check if this is the sent or draft folder. */
1258 $handleAsSent_result = (($mailbox == $sent_folder)
1259 ||
($mailbox == $draft_folder));
1261 /* Then check the result of the handleAsSent hook. */
1262 do_hook('check_handleAsSent_result', $mailbox);
1264 /* And return the result. */
1265 return ($handleAsSent_result);