6 * Copyright (c) 1999-2003 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(SM_PATH
. 'functions/strings.php');
16 require_once(SM_PATH
. 'functions/html.php');
17 require_once(SM_PATH
. 'class/html.class.php');
18 require_once(SM_PATH
. 'functions/imap_mailbox.php');
20 /* Default value for page_selector_max. */
21 define('PG_SEL_MAX', 10);
23 function printMessageInfo($imapConnection, $t, $not_last=true, $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'], $indent_array[$msg['ID']]);
81 echo html_tag( 'tr','','','','VALIGN="top"') . "\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 (is_array($message_highlight_list) && count($message_highlight_list)){
122 foreach ($message_highlight_list as $message_highlight_list_part) {
123 if (trim($message_highlight_list_part['value']) != '') {
124 $high_val = strtolower($message_highlight_list_part['value']);
125 $match_type = strtoupper($message_highlight_list_part['match_type']);
126 if ($match_type == 'TO_CC') {
127 if (strstr('^^' . strtolower($msg['TO']), $high_val) ||
128 strstr('^^' . strtolower($msg['CC']), $high_val)) {
129 $hlt_color = $message_highlight_list_part['color'];
133 if (strstr('^^' . strtolower($msg[$match_type]), $high_val)) {
134 $hlt_color = $message_highlight_list_part['color'];
142 if (!isset($hlt_color)) {
143 $hlt_color = $color_string;
145 $checked = ($checkall == 1) ?
' CHECKED' : '';
147 if (sizeof($index_order)) {
148 foreach ($index_order as $index_order_part) {
149 switch ($index_order_part) {
150 case 1: /* checkbox */
152 "<input type=checkbox name=\"msg[$t]\" value=\"".$msg['ID']."\"$checked>",
158 $italic . $bold . $flag . $fontstr . htmlentities($senderName) .
159 $fontstr_end . $flag_end . $bold_end . $italic_end,
164 $date_string = $msg['DATE_STRING'] . '';
165 if ($date_string == '') {
166 $date_string = _("Unknown date");
169 $bold . $flag . $fontstr . $date_string .
170 $fontstr_end . $flag_end . $bold_end,
175 case 4: /* subject */
177 if ($thread_sort_messages == 1) {
178 if (isset($indent_array[$msg['ID']])) {
179 $td_str .= str_repeat(" ",$indent_array[$msg['ID']]);
182 $td_str .= '<a href="read_body.php?mailbox='.$urlMailbox
183 . '&passed_id='. $msg["ID"]
184 . '&startMessage='.$start_msg.$searchstr.'"';
185 do_hook("subject_link");
186 if ($subject != $msg['SUBJECT']) {
187 $title = get_html_translation_table(HTML_SPECIALCHARS
);
188 $title = array_flip($title);
189 $title = strtr($msg['SUBJECT'], $title);
190 $title = str_replace('"', "''", $title);
191 $td_str .= " title=\"$title\"";
193 $td_str .= ">$flag$subject$flag_end</a>$bold_end";
194 echo html_tag( 'td', $td_str, 'left', $hlt_color );
198 $td_str = "<b><small>";
200 if (isset($msg['FLAG_ANSWERED']) && $msg['FLAG_ANSWERED'] == true) {
204 if ($msg['TYPE0'] == 'multipart') {
208 if ($default_use_priority) {
209 if ( ($msg['PRIORITY'] == 1) ||
($msg['PRIORITY'] == 2) ) {
210 $td_str .= "<font color=\"$color[1]\">!</font>";
213 if ($msg['PRIORITY'] == 5) {
214 $td_str .= "<font color=\"$color[8]\">?</font>";
218 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'] == true) {
219 $td_str .= "<font color=\"$color[1]\">D</font>";
225 $td_str .= '</small></b>';
234 $bold . $fontstr . show_readable_size($msg['SIZE']) .
235 $fontstr_end . $bold_end,
244 echo '</tr>' . "\n" . '<tr><td COLSPAN="' . $col . '" BGCOLOR="' .
245 $color[0] . '" HEIGHT="1"></td></tr>' . "\n";
251 function getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id) {
253 if ($start_msg +
($show_num - 1) < $num_msgs) {
254 $end_msg = $start_msg +
($show_num-1);
256 $end_msg = $num_msgs;
258 $id = array_slice($id, ($start_msg-1), ($end_msg));
260 $end = $start_msg +
$show_num - 1;
261 if ($num_msgs < $show_num) {
262 $end_loop = $num_msgs;
263 } else if ($end > $num_msgs) {
264 $end_loop = $num_msgs - $start_msg +
1;
266 $end_loop = $show_num;
268 return fillMessageArray($imapConnection,$id,$end_loop);
274 function getThreadMessages($imapConnection, $start_msg, $show_num, $num_msgs) {
275 $id = get_thread_sort($imapConnection);
276 return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
279 function getServerSortMessages($imapConnection, $start_msg, $show_num,
280 $num_msgs, $server_sort_order, $mbxresponse) {
281 $id = sqimap_get_sort_order($imapConnection, $server_sort_order,$mbxresponse);
282 return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
285 function getSelfSortMessages($imapConnection, $start_msg, $show_num,
286 $num_msgs, $sort, $mbxresponse) {
288 if ($num_msgs >= 1) {
289 $id = sqimap_get_php_sort_order ($imapConnection, $mbxresponse);
294 /* if it's not sorted */
295 if ($start_msg +
($show_num - 1) < $num_msgs) {
296 $end_msg = $start_msg +
($show_num - 1);
298 $end_msg = $num_msgs;
300 if ($end_msg < $start_msg) {
301 $start_msg = $start_msg - $show_num;
302 if ($start_msg < 1) {
306 $id = array_slice(array_reverse($id), ($start_msg-1), ($end_msg));
307 $end = $start_msg +
$show_num - 1;
308 if ($num_msgs < $show_num) {
309 $end_loop = $num_msgs;
310 } else if ($end > $num_msgs) {
311 $end_loop = $num_msgs - $start_msg +
1;
313 $end_loop = $show_num;
316 $msgs = fillMessageArray($imapConnection,$id,$end_loop);
324 * This function loops through a group of messages in the mailbox
325 * and shows them to the user.
327 function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
328 $start_msg, $sort, $color, $show_num,
329 $use_cache, $mode='') {
330 global $msgs, $msort, $auto_expunge, $thread_sort_messages,
331 $allow_server_sort, $server_sort_order;
333 /* If autoexpunge is turned on, then do it now. */
334 $mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox);
336 /* If autoexpunge is turned on, then do it now. */
337 if ($auto_expunge == true) {
338 $exp_cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, false, '');
339 $mbxresponse['EXISTS'] = $mbxresponse['EXISTS'] - $exp_cnt;
340 $num_msgs = $mbxresponse['EXISTS'];
343 if ($mbxresponse['EXISTS'] > 0) {
344 /* if $start_msg is lower than $num_msgs, we probably deleted all messages
345 * in the last page. We need to re-adjust the start_msg
348 if($start_msg > $num_msgs) {
349 $start_msg -= $show_num;
355 /* This code and the next if() block check for
356 * server-side sorting methods. The $id array is
357 * formatted and $sort is set to 6 to disable
358 * SM internal sorting
361 if ($thread_sort_messages == 1) {
363 } elseif ($allow_server_sort == 1) {
364 $mode = 'serversort';
369 sqsession_unregister('msort');
370 sqsession_unregister('msgs');
373 $id = get_thread_sort($imapConnection);
374 $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
375 if ($msgs === false) {
376 echo '<b><small><center><font color=red>' .
377 _("Thread sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
378 '</center></small></b>';
379 $thread_sort_messages = 0;
380 $msort = $msgs = array();
387 $id = sqimap_get_sort_order($imapConnection, $sort, $mbxresponse);
388 $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
389 if ($msgs === false) {
390 echo '<b><small><center><font color=red>' .
391 _( "Server-side sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
392 '</center></small></b>';
393 $sort = $server_sort_order;
394 $allow_server_sort = FALSE;
395 $msort = $msgs = array();
404 $msgs = getSelfSortMessages($imapConnection, $start_msg, $show_num,
405 $num_msgs, $sort, $mbxresponse);
406 $msort = calc_msort($msgs, $sort);
410 sqsession_register($msort, 'msort');
411 sqsession_register($msgs, 'msgs');
412 } /* if exists > 0 */
414 $res = getEndMessage($start_msg, $show_num, $num_msgs);
415 $start_msg = $res[0];
418 $paginator_str = get_paginator_str($mailbox, $start_msg, $end_msg,
419 $num_msgs, $show_num, $sort);
421 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
423 do_hook('mailbox_index_before');
424 echo '<table border="0" width="100%" cellpadding="0" cellspacing="0">';
427 mail_message_listing_beginning($imapConnection, $mailbox, $sort,
428 $msg_cnt_str, $paginator_str, $start_msg);
430 /* line between the button area and the list */
431 echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>';
434 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
436 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[5].'">';
438 printHeader($mailbox, $srt, $color, !$thread_sort_messages);
440 displayMessageArray($imapConnection, $num_msgs, $start_msg,
441 $msort, $mailbox, $sort, $color, $show_num,0,0);
442 echo '</td></tr></table></td></tr></table>';
444 mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color);
445 echo '</td></tr></table>';
448 function calc_msort($msgs, $sort) {
459 if (($sort == 0) ||
($sort == 1)) {
460 foreach ($msgs as $item) {
461 $msort[] = $item['TIME_STAMP'];
463 } elseif (($sort == 2) ||
($sort == 3)) {
464 foreach ($msgs as $item) {
465 $msort[] = $item['FROM-SORT'];
467 } elseif (($sort == 4) ||
($sort == 5)) {
468 foreach ($msgs as $item) {
469 $msort[] = $item['SUBJECT-SORT'];
484 function fillMessageArray($imapConnection, $id, $count) {
485 $msgs_list = sqimap_get_small_header_list($imapConnection, $id);
487 if (sizeof($msgs_list)) {
488 foreach ($msgs_list as $hdr) {
489 $unique_id[] = $hdr->uid
;
490 $from[] = $hdr->from
;
491 $date[] = $hdr->date
;
492 $subject[] = $hdr->subject
;
494 $priority[] = $hdr->priority
;
496 $size[] = $hdr->size
;
497 $type[] = $hdr->type0
;
498 $flag_deleted[] = $hdr->flag_deleted
;
499 $flag_answered[] = $hdr->flag_answered
;
500 $flag_seen[] = $hdr->flag_seen
;
501 $flag_flagged[] = $hdr->flag_flagged
;
505 for($j = 0; $j < $count; ++
$j) {
506 if (isset($date[$j])) {
507 $date[$j] = str_replace(' ', ' ', $date[$j]);
508 $tmpdate = explode(' ', trim($date[$j]));
510 $tmpdate = $date = array('', '', '', '', '', '');
512 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
513 $messages[$j]['DATE_STRING'] =
514 getDateString($messages[$j]['TIME_STAMP']);
515 $messages[$j]['ID'] = $unique_id[$j];
516 $messages[$j]['FROM'] = decodeHeader($from[$j]);
517 $messages[$j]['FROM-SORT'] =
518 strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
519 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
520 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
521 $messages[$j]['TO'] = decodeHeader($to[$j]);
522 $messages[$j]['PRIORITY'] = $priority[$j];
523 $messages[$j]['CC'] = $cc[$j];
524 $messages[$j]['SIZE'] = $size[$j];
525 $messages[$j]['TYPE0'] = $type[$j];
526 $messages[$j]['FLAG_DELETED'] = $flag_deleted[$j];
527 $messages[$j]['FLAG_ANSWERED'] = $flag_answered[$j];
528 $messages[$j]['FLAG_SEEN'] = $flag_seen[$j];
529 $messages[$j]['FLAG_FLAGGED'] = $flag_flagged[$j];
532 * fix SUBJECT-SORT to remove Re:
536 * TODO: i18n should be incorporated here. E.g. we catch the ones
537 * we know about, but also define in i18n what the localized
538 * "Re: " is for this or that locale.
540 if (preg_match("/^(vedr|sv|re|aw):\s*(.*)$/si",
541 $messages[$j]['SUBJECT-SORT'], $matches)){
542 $messages[$j]['SUBJECT-SORT'] = $matches[2];
549 /* Generic function to convert the msgs array into an HTML table. */
550 function displayMessageArray($imapConnection, $num_msgs, $start_msg,
551 $msort, $mailbox, $sort, $color,
552 $show_num, $where=0, $what=0) {
553 global $imapServerAddress, $use_mailbox_cache, $index_order,
554 $indent_array, $thread_sort_messages, $allow_server_sort,
555 $server_sort_order, $PHP_SELF;
557 $res = getEndMessage($start_msg, $show_num, $num_msgs);
558 $start_msg = $res[0];
561 $urlMailbox = urlencode($mailbox);
563 /* get indent level for subject display */
564 if ($thread_sort_messages == 1 && $num_msgs) {
565 $indent_array = get_parent_level($imapConnection);
568 $real_startMessage = $start_msg;
570 if ($end_msg - $start_msg < $show_num - 1) {
571 $end_msg = $end_msg - $start_msg +
1;
573 } else if ($start_msg > $show_num) {
574 $end_msg = $show_num;
578 $endVar = $end_msg +
1;
581 * Loop through and display the info for each message.
582 * ($t is used for the checkbox number)
586 /* messages display */
589 /* if there's no messages in this folder */
592 "<BR><b>" . _("THIS FOLDER IS EMPTY") . "</b><BR> ",
595 'COLSPAN="' . count($index_order) . '"'
598 } elseif ($start_msg == $end_msg) {
599 /* if there's only one message in the box, handle it differently. */
611 } while (isset ($key) && ($k < $i));
612 printMessageInfo($imapConnection, $t, true, $key, $mailbox,
613 $real_startMessage, $where, $what);
622 } while (isset ($key) && ($k < $i));
625 if (!$i ||
$i == $endVar-1) $not_last = false;
626 printMessageInfo($imapConnection, $t, $not_last, $key, $mailbox,
627 $real_startMessage, $where, $what);
632 } while ($i && $i < $endVar);
637 * Displays the standard message list header. To finish the table,
638 * you need to do a "</table></table>";
640 * $moveURL is the URL to submit the delete/move form to
641 * $mailbox is the current mailbox
642 * $sort is the current sorting method (-1 for no sorting available [searches])
643 * $Message is a message that is centered on top of the list
644 * $More is a second line that is left aligned
647 function mail_message_listing_beginning ($imapConnection,
648 $mailbox = '', $sort = -1,
650 $paginator = ' ',
652 global $color, $auto_expunge, $base_uri, $thread_sort_messages,
653 $allow_thread_sort, $allow_server_sort, $server_sort_order,
656 $php_self = $PHP_SELF;
657 /* fix for incorrect $PHP_SELF */
658 if (strpos($php_self, 'move_messages.php')) {
659 $php_self = str_replace('move_messages.php', 'right_main.php', $php_self);
661 $urlMailbox = urlencode($mailbox);
663 if (preg_match('/^(.+)\?.+$/',$php_self,$regs)) {
664 $source_url = $regs[1];
666 $source_url = $php_self;
672 $moveURL = "move_messages.php?msg=$msg&mailbox=$urlMailbox"
673 . "&startMessage=$start_msg";
675 * This is the beginning of the message list table.
676 * It wraps around all messages
678 echo "<FORM name=\"messageList\" method=post action=\"$moveURL\">\n"
679 . html_tag( 'table' ,
684 html_tag( 'td', $paginator, 'left' ) .
685 html_tag( 'td', $msg_cnt_str, 'right' )
687 , '', $color[4], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
690 , '', '', 'border="0" width="100%" cellpadding="1" cellspacing="0"' );
691 /* line between header and button area */
692 echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>';
695 echo html_tag( 'tr' ) . "\n"
696 . html_tag( 'td' ,'' , 'left', '', '' )
697 . html_tag( 'table' ,'' , '', $color[9], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
699 . html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
701 getSmallStringCell(_("Move Selected To"), 'left', 'nowrap') .
702 getSmallStringCell(_("Transform Selected Messages"), 'right')
704 . html_tag( 'tr' ) ."\n"
705 . html_tag( 'td', '', 'left', '', 'valign="middle" nowrap' );
706 getMbxList($imapConnection);
707 echo getButton('SUBMIT', 'moveButton',_("Move")) . "\n";
708 echo getButton('SUBMIT', 'attache',_("Forward")) . "\n";
711 . html_tag( 'td', '', 'right', '', 'nowrap' );
715 if (!$auto_expunge) {
716 echo getButton('SUBMIT', 'expungeButton',_("Expunge"))
717 .' ' . _("mailbox") . "\n";
720 echo getButton('SUBMIT', 'markRead',_("Read"));
721 echo getButton('SUBMIT', 'markUnread',_("Unread"));
722 echo getButton('SUBMIT', 'delete',_("Delete")) ." \n";
723 if (!strpos($php_self,'mailbox')) {
724 $location = $php_self.'?mailbox=INBOX&startMessage=1';
726 $location = $php_self;
728 echo '<INPUT TYPE="HIDDEN" NAME="location" VALUE="'.$location.'">';
732 /* draws thread sorting links */
733 if ($allow_thread_sort == TRUE) {
734 if ($thread_sort_messages == 1 ) {
736 $thread_name = _("Unthread View");
737 } elseif ($thread_sort_messages == 0) {
739 $thread_name = _("Thread View");
741 echo html_tag( 'tr' ,
743 ' <a href=' . $source_url . '?sort='
744 . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
745 . '&mailbox=' . urlencode($mailbox) . '><small>' . $thread_name
746 . '</a></small> '
751 echo "</TABLE></td></tr></table></td></tr>\n";
753 do_hook('mailbox_form_before');
755 /* if using server sort we highjack the
756 * the $sort var and use $server_sort_order
757 * instead. but here we reset sort for a bit
760 if ($allow_server_sort == TRUE) {
761 $sort = $server_sort_order;
765 function mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color) {
767 /* space between list and footer */
768 echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'" COLSPAN="1">';
770 echo '</td></tr><tr><td>';
771 echo html_tag( 'table',
776 html_tag( 'td', $paginator_str ) .
777 html_tag( 'td', $msg_cnt_str, 'right' )
779 , '', $color[4], 'width="100%" border="0" cellpadding="1" cellspacing="0"' )
782 , '', $color[9], 'width="100%" border="0" cellpadding="1" cellspacing="0"' );
785 /* End of message-list table */
787 do_hook('mailbox_index_after');
791 function printHeader($mailbox, $sort, $color, $showsort=true) {
793 echo html_tag( 'tr' ,'' , 'center', $color[5] );
795 /* calculate the width of the subject column based on the
796 * widths of the other columns */
797 $widths = array(1=>1,2=>25,3=>5,4=>0,5=>1,6=>5);
799 foreach($index_order as $item) {
800 $subjectwidth -= $widths[$item];
803 foreach ($index_order as $item) {
805 case 1: /* checkbox */
807 echo html_tag( 'td' ,' ' , '', '', 'width="1%"' );
810 if (handleAsSent($mailbox)) {
811 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
812 . '<b>' . _("To") . '</b>';
814 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
815 . '<b>' . _("From") . '</b>';
818 ShowSortButton($sort, $mailbox, 2, 3);
823 echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
824 . '<b>' . _("Date") . '</b>';
826 ShowSortButton($sort, $mailbox, 0, 1);
830 case 4: /* subject */
831 echo html_tag( 'td' ,'' , 'left', '', 'width="'.$subjectwidth.'%"' )
832 . '<b>' . _("Subject") . '</b>';
834 ShowSortButton($sort, $mailbox, 4, 5);
839 echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%"' );
848 * This function shows the sort button. Isn't this a good comment?
850 function ShowSortButton($sort, $mailbox, $Up, $Down ) {
852 /* Figure out which image we want to use. */
853 if ($sort != $Up && $sort != $Down) {
854 $img = 'sort_none.png';
856 } elseif ($sort == $Up) {
857 $img = 'up_pointer.png';
860 $img = 'down_pointer.png';
864 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
865 $source_url = $regs[1];
867 $source_url = $PHP_SELF;
870 /* Now that we have everything figured out, show the actual button. */
871 echo ' <a href="' . $source_url .'?newsort=' . $which
872 . '&startMessage=1&mailbox=' . urlencode($mailbox)
873 . '"><IMG SRC="../images/' . $img
874 . '" BORDER=0 WIDTH=12 HEIGHT=10 ALT="sort"></a>';
877 function get_selectall_link($start_msg, $sort) {
878 global $checkall, $what, $where, $mailbox, $javascript_on;
879 global $PHP_SELF, $PG_SHOWNUM;
882 if ($javascript_on) {
883 $result = '<script language="JavaScript" type="text/javascript">'
885 . "function CheckAll() {\n"
886 . " for (var i = 0; i < document.messageList.elements.length; i++) {\n"
887 . " if(document.messageList.elements[i].type == 'checkbox'){\n"
888 . " document.messageList.elements[i].checked = "
889 . " !(document.messageList.elements[i].checked);\n"
894 . '</script><a href="#" onClick="CheckAll();">' . _("Toggle All")
897 if (strpos($PHP_SELF, "?")) {
898 $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($mailbox)
899 . "&startMessage=$start_msg&sort=$sort&checkall=";
901 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
902 . "&startMessage=$start_msg&sort=$sort&checkall=";
904 if (isset($checkall) && $checkall == '1') {
910 if (isset($where) && isset($what)) {
911 $result .= '&where=' . urlencode($where)
912 . '&what=' . urlencode($what);
916 if (isset($checkall) && ($checkall == '1')) {
917 $result .= _("Unselect All");
919 $result .= _("Select All");
924 /* Return our final result. */
929 * This function computes the "Viewing Messages..." string.
931 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
932 /* Compute the $msg_cnt_str. */
934 if ($start_msg < $end_msg) {
935 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"),
936 $start_msg, $end_msg, $num_msgs);
937 } else if ($start_msg == $end_msg) {
938 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
942 /* Return our result string. */
947 * Generate a paginator link.
949 function get_paginator_link($box, $start_msg, $use, $text) {
952 $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
953 . "&startMessage=$start_msg&mailbox=$box\" "
954 . "TARGET=\"right\">$text</A>";
957 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
958 $source_url = $regs[1];
960 $source_url = $PHP_SELF;
963 $result = '<A HREF="'. $source_url . "?use_mailbox_cache=$use"
964 . "&startMessage=$start_msg&mailbox=$box\" "
965 . "TARGET=\"right\">$text</A>";
971 * This function computes the paginator string.
973 function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
975 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
977 /* Initialize paginator string chunks. */
984 $box = urlencode($box);
986 /* Create simple strings that will be creating the paginator. */
987 $spc = ' '; /* This will be used as a space. */
988 $sep = '|'; /* This will be used as a seperator. */
990 /* Get some paginator preference values. */
991 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON
);
992 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
);
994 /* Make sure that our start message number is not too big. */
995 $start_msg = min($start_msg, $num_msgs);
997 /* Decide whether or not we will use the mailbox cache. */
998 /* Not sure why $use_mailbox_cache is even passed in. */
1005 /* Compute the starting message of the previous and next page group. */
1006 $next_grp = $start_msg +
$show_num;
1007 $prev_grp = $start_msg - $show_num;
1009 /* Compute the basic previous and next strings. */
1010 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
1011 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1012 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1013 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
1014 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1015 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
1016 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
1017 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
1018 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1021 /* Page selector block. Following code computes page links. */
1022 if ($pg_sel && ($num_msgs > $show_num)) {
1023 /* Most importantly, what is the current page!!! */
1024 $cur_pg = intval($start_msg / $show_num) +
1;
1026 /* Compute total # of pages and # of paginator page links. */
1027 $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
1028 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
1030 /* Compute the size of the four quarters of the page links. */
1032 /* If we can, just show all the pages. */
1033 if (($tot_pgs - 1) <= $pg_max) {
1034 $q1_pgs = $cur_pg - 1;
1035 $q2_pgs = $q3_pgs = 0;
1036 $q4_pgs = $tot_pgs - $cur_pg;
1038 /* Otherwise, compute some magic to choose the four quarters. */
1041 * Compute the magic base values. Added together,
1042 * these values will always equal to the $pag_pgs.
1043 * NOTE: These are DEFAULT values and do not take
1044 * the current page into account. That is below.
1046 $q1_pgs = floor($vis_pgs/4);
1047 $q2_pgs = round($vis_pgs/4, 0);
1048 $q3_pgs = ceil($vis_pgs/4);
1049 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
1051 /* Adjust if the first quarter contains the current page. */
1052 if (($cur_pg - $q1_pgs) < 1) {
1053 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) +
$q2_pgs;
1054 $q1_pgs = $cur_pg - 1;
1056 $q3_pgs +
= ceil($extra_pgs / 2);
1057 $q4_pgs +
= floor($extra_pgs / 2);
1059 /* Adjust if the first and second quarters intersect. */
1060 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
1061 $extra_pgs = $q2_pgs;
1062 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1063 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1064 $q3_pgs +
= ceil($extra_pgs / 2);
1065 $q4_pgs +
= floor($extra_pgs / 2);
1067 /* Adjust if the fourth quarter contains the current page. */
1068 } else if (($cur_pg +
$q4_pgs) >= $tot_pgs) {
1069 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) +
$q3_pgs;
1071 $q4_pgs = $tot_pgs - $cur_pg;
1072 $q1_pgs +
= floor($extra_pgs / 2);
1073 $q2_pgs +
= ceil($extra_pgs / 2);
1075 /* Adjust if the third and fourth quarter intersect. */
1076 } else if (($cur_pg +
$q3_pgs +
1) >= ($tot_pgs - $q4_pgs +
1)) {
1077 $extra_pgs = $q3_pgs;
1078 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1079 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1080 $q1_pgs +
= floor($extra_pgs / 2);
1081 $q2_pgs +
= ceil($extra_pgs / 2);
1086 * I am leaving this debug code here, commented out, because
1087 * it is a really nice way to see what the above code is doing.
1088 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
1089 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
1092 /* Print out the page links from the compute page quarters. */
1094 /* Start with the first quarter. */
1095 if (($q1_pgs == 0) && ($cur_pg > 1)) {
1096 $pg_str .= "...$spc";
1098 for ($pg = 1; $pg <= $q1_pgs; ++
$pg) {
1099 $start = (($pg-1) * $show_num) +
1;
1100 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1102 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
1103 $pg_str .= "...$spc";
1107 /* Continue with the second quarter. */
1108 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++
$pg) {
1109 $start = (($pg-1) * $show_num) +
1;
1110 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1113 /* Now print the current page. */
1114 $pg_str .= $cur_pg . $spc;
1116 /* Next comes the third quarter. */
1117 for ($pg = $cur_pg +
1; $pg <= $cur_pg +
$q3_pgs; ++
$pg) {
1118 $start = (($pg-1) * $show_num) +
1;
1119 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1122 /* And last, print the forth quarter page links. */
1123 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
1124 $pg_str .= "...$spc";
1126 if (($tot_pgs - $q4_pgs) > ($cur_pg +
$q3_pgs)) {
1127 $pg_str .= "...$spc";
1129 for ($pg = $tot_pgs - $q4_pgs +
1; $pg <= $tot_pgs; ++
$pg) {
1130 $start = (($pg-1) * $show_num) +
1;
1131 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1134 } else if ($PG_SHOWNUM == 999999) {
1135 $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
1136 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1137 . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc;
1140 /* If necessary, compute the 'show all' string. */
1141 if (($prv_str != '') ||
($nxt_str != '')) {
1142 $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
1143 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1144 . "TARGET=\"right\">" . _("Show All") . '</A>';
1147 /* Last but not least, get the value for the toggle all link. */
1148 $tgl_str = get_selectall_link($start_msg, $sort);
1150 /* Put all the pieces of the paginator string together. */
1152 * Hairy code... But let's leave it like it is since I am not certain
1153 * a different approach would be any easier to read. ;)
1156 $result .= ($prv_str != '' ?
$prv_str . $spc . $sep . $spc : '');
1157 $result .= ($nxt_str != '' ?
$nxt_str . $spc . $sep . $spc : '');
1158 $result .= ($pg_str != '' ?
$pg_str : '');
1159 $result .= ($all_str != '' ?
$sep . $spc . $all_str . $spc : '');
1160 $result .= ($result != '' ?
$sep . $spc . $tgl_str: $tgl_str);
1162 /* If the resulting string is blank, return a non-breaking space. */
1163 if ($result == '') {
1167 /* Return our final magical paginator string. */
1171 function processSubject($subject, $threadlevel = 0) {
1172 global $languages, $squirrelmail_language;
1173 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1175 return _("(no subject)");
1179 /* if this is threaded, substract two chars per indentlevel */
1180 if($threadlevel > 0 && $threadlevel <= 10)
1181 $trim_at -= (2*$threadlevel);
1183 if (strlen($subject) <= $trim_at)
1186 $ent_strlen = strlen($subject);
1187 $trim_val = $trim_at - 5;
1190 * see if this is entities-encoded string
1191 * If so, Iterate through the whole string, find out
1192 * the real number of characters, and if more
1193 * than 55, substr with an updated trim value.
1195 while ( (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1196 (($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false) ) {
1197 $trim_val +
= ($ent_loc_end-$ent_loc)+
1;
1198 $ent_strlen -= $ent_loc_end-$ent_loc;
1199 $ent_offset = $ent_loc_end+
1;
1202 if ($ent_strlen <= $trim_at){
1206 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
1207 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
1208 return $languages[$squirrelmail_language]['XTRA_CODE']('strimwidth', $subject, $trim_val);
1211 return substr($subject, 0, $trim_val) . '...';
1214 function getMbxList($imapConnection) {
1215 global $lastTargetMailbox;
1216 echo ' <small> <tt><select name="targetMailbox">';
1217 echo sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)) );
1218 echo ' </SELECT></TT> ';
1221 function getButton($type, $name, $value) {
1222 return '<INPUT TYPE="'.$type.'" NAME="'.$name.'" VALUE="'.$value . '">';
1225 function getSmallStringCell($string, $align) {
1226 return html_tag('td',
1227 '<small>' . $string . ': </small>',
1233 function getEndMessage($start_msg, $show_num, $num_msgs) {
1234 if ($start_msg +
($show_num - 1) < $num_msgs){
1235 $end_msg = $start_msg +
($show_num - 1);
1237 $end_msg = $num_msgs;
1240 if ($end_msg < $start_msg) {
1241 $start_msg = $start_msg - $show_num;
1242 if ($start_msg < 1) {
1246 return (array($start_msg,$end_msg));
1249 function handleAsSent($mailbox) {
1250 global $sent_folder, $draft_folder, $handleAsSent_result;
1252 /* First check if this is the sent or draft folder. */
1253 $handleAsSent_result = (($mailbox == $sent_folder)
1254 ||
($mailbox == $draft_folder));
1256 /* Then check the result of the handleAsSent hook. */
1257 do_hook('check_handleAsSent_result', $mailbox);
1259 /* And return the result. */
1260 return ($handleAsSent_result);