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');
19 require_once(SM_PATH
. 'functions/set_language_align.php');
21 /* --------------------- Get globals ------------------------------------- */
22 $language_align = set_language_align();
24 /* Default value for page_selector_max. */
25 define('PG_SEL_MAX', 10);
27 function printMessageInfo($imapConnection, $t, $not_last=true, $key, $mailbox,
28 $start_msg, $where, $what) {
30 $color, $msgs, $msort,
31 $default_use_priority,
32 $message_highlight_list,
34 $indent_array, /* indent subject by */
35 $pos, /* Search postion (if any) */
36 $thread_sort_messages, /* thread sorting on/off */
37 $server_sort_order, /* sort value when using server-sorting */
39 $allow_server_sort; /* enable/disable server-side sorting */
40 $color_string = $color[4];
42 if ($GLOBALS['alt_index_colors']) {
43 if (!isset($row_count)) {
48 if (!isset($color[12])) {
49 $color[12] = '#EAEAEA';
51 $color_string = $color[12];
56 if($mailbox == 'None') {
57 $boxes = sqimap_mailbox_list($imapConnection);
58 $mailbox = $boxes[0]['unformatted'];
61 $urlMailbox = urlencode($mailbox);
63 if (handleAsSent($mailbox)) {
64 $msg['FROM'] = $msg['TO'];
66 * This is done in case you're looking into Sent folders,
67 * because you can have multiple receivers.
69 $senderNames = explode(',', $msg['FROM']);
71 if (sizeof($senderNames)){
72 foreach ($senderNames as $senderNames_part) {
73 if ($senderName != '') {
76 $senderName .= sqimap_find_displayable_name($senderNames_part);
80 $senderName = sqimap_find_displayable_name($msg['FROM']);
83 $subject = processSubject($msg['SUBJECT'], $indent_array[$msg['ID']]);
85 echo html_tag( 'tr','','','','VALIGN="top"') . "\n";
87 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
88 $flag = "<font color=\"$color[2]\">";
89 $flag_end = '</font>';
94 if (!isset($msg['FLAG_SEEN']) ||
($msg['FLAG_SEEN'] == false)) {
101 if (handleAsSent($mailbox)) {
103 $italic_end = '</i>';
108 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
109 $fontstr = "<font color=\"$color[9]\">";
110 $fontstr_end = '</font>';
116 if ($where && $what) {
117 $searchstr = '&where='.$where.'&what='.$what;
122 * AAAAH! Make my eyes stop bleeding!
125 if (is_array($message_highlight_list) && count($message_highlight_list)){
126 foreach ($message_highlight_list as $message_highlight_list_part) {
127 if (trim($message_highlight_list_part['value']) != '') {
128 $high_val = strtolower($message_highlight_list_part['value']);
129 $match_type = strtoupper($message_highlight_list_part['match_type']);
130 if ($match_type == 'TO_CC') {
131 if (strstr('^^' . strtolower($msg['TO']), $high_val) ||
132 strstr('^^' . strtolower($msg['CC']), $high_val)) {
133 $hlt_color = $message_highlight_list_part['color'];
137 if (strstr('^^' . strtolower($msg[$match_type]), $high_val)) {
138 $hlt_color = $message_highlight_list_part['color'];
146 if (!isset($hlt_color)) {
147 $hlt_color = $color_string;
149 $checked = ($checkall == 1) ?
' CHECKED' : '';
151 if (sizeof($index_order)) {
152 foreach ($index_order as $index_order_part) {
153 switch ($index_order_part) {
154 case 1: /* checkbox */
156 "<input type=checkbox name=\"msg[$t]\" value=\"".$msg['ID']."\"$checked>",
162 $italic . $bold . $flag . $fontstr . $senderName .
163 $fontstr_end . $flag_end . $bold_end . $italic_end,
168 $date_string = $msg['DATE_STRING'] . '';
169 if ($date_string == '') {
170 $date_string = _("Unknown date");
173 $bold . $flag . $fontstr . $date_string .
174 $fontstr_end . $flag_end . $bold_end,
179 case 4: /* subject */
181 if ($thread_sort_messages == 1) {
182 if (isset($indent_array[$msg['ID']])) {
183 $td_str .= str_repeat(" ",$indent_array[$msg['ID']]);
186 $td_str .= '<a href="read_body.php?mailbox='.$urlMailbox
187 . '&passed_id='. $msg["ID"]
188 . '&startMessage='.$start_msg.$searchstr.'"';
189 do_hook("subject_link");
190 if ($subject != $msg['SUBJECT']) {
191 $title = get_html_translation_table(HTML_SPECIALCHARS
);
192 $title = array_flip($title);
193 $title = strtr($msg['SUBJECT'], $title);
194 $title = str_replace('"', "''", $title);
195 $td_str .= " title=\"$title\"";
197 $td_str .= ">$flag$subject$flag_end</a>$bold_end";
198 echo html_tag( 'td', $td_str, 'left', $hlt_color );
202 $td_str = "<b><small>";
204 if (isset($msg['FLAG_ANSWERED']) && $msg['FLAG_ANSWERED'] == true) {
208 if ($msg['TYPE0'] == 'multipart') {
212 if ($default_use_priority) {
213 if ( ($msg['PRIORITY'] == 1) ||
($msg['PRIORITY'] == 2) ) {
214 $td_str .= "<font color=\"$color[1]\">!</font>";
217 if ($msg['PRIORITY'] == 5) {
218 $td_str .= "<font color=\"$color[8]\">?</font>";
222 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'] == true) {
223 $td_str .= "<font color=\"$color[1]\">D</font>";
229 $td_str .= '</small></b>';
238 $bold . $fontstr . show_readable_size($msg['SIZE']) .
239 $fontstr_end . $bold_end,
248 echo '</tr>' . "\n" . '<tr><td COLSPAN="' . $col . '" BGCOLOR="' .
249 $color[0] . '" HEIGHT="1"></td></tr>' . "\n";
255 function getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id) {
257 if ($start_msg +
($show_num - 1) < $num_msgs) {
258 $end_msg = $start_msg +
($show_num-1);
260 $end_msg = $num_msgs;
262 $id = array_slice($id, ($start_msg-1), ($end_msg));
264 $end = $start_msg +
$show_num - 1;
265 if ($num_msgs < $show_num) {
266 $end_loop = $num_msgs;
267 } else if ($end > $num_msgs) {
268 $end_loop = $num_msgs - $start_msg +
1;
270 $end_loop = $show_num;
272 return fillMessageArray($imapConnection,$id,$end_loop);
278 function getThreadMessages($imapConnection, $start_msg, $show_num, $num_msgs) {
279 $id = get_thread_sort($imapConnection);
280 return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
283 function getServerSortMessages($imapConnection, $start_msg, $show_num,
284 $num_msgs, $server_sort_order, $mbxresponse) {
285 $id = sqimap_get_sort_order($imapConnection, $server_sort_order,$mbxresponse);
286 return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
289 function getSelfSortMessages($imapConnection, $start_msg, $show_num,
290 $num_msgs, $sort, $mbxresponse) {
292 if ($num_msgs >= 1) {
293 $id = sqimap_get_php_sort_order ($imapConnection, $mbxresponse);
298 /* if it's not sorted */
299 if ($start_msg +
($show_num - 1) < $num_msgs) {
300 $end_msg = $start_msg +
($show_num - 1);
302 $end_msg = $num_msgs;
304 if ($end_msg < $start_msg) {
305 $start_msg = $start_msg - $show_num;
306 if ($start_msg < 1) {
310 $id = array_slice(array_reverse($id), ($start_msg-1), ($end_msg));
311 $end = $start_msg +
$show_num - 1;
312 if ($num_msgs < $show_num) {
313 $end_loop = $num_msgs;
314 } else if ($end > $num_msgs) {
315 $end_loop = $num_msgs - $start_msg +
1;
317 $end_loop = $show_num;
320 $msgs = fillMessageArray($imapConnection,$id,$end_loop);
328 * This function loops through a group of messages in the mailbox
329 * and shows them to the user.
331 function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
332 $start_msg, $sort, $color, $show_num,
333 $use_cache, $mode='') {
334 global $msgs, $msort, $auto_expunge, $thread_sort_messages, $language_align,
335 $allow_server_sort, $server_sort_order;
337 /* If autoexpunge is turned on, then do it now. */
338 $mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox);
340 /* If autoexpunge is turned on, then do it now. */
341 if ($auto_expunge == true) {
342 $exp_cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, false, '');
343 $mbxresponse['EXISTS'] = $mbxresponse['EXISTS'] - $exp_cnt;
344 $num_msgs = $mbxresponse['EXISTS'];
347 if ($mbxresponse['EXISTS'] > 0) {
348 /* if $start_msg is lower than $num_msgs, we probably deleted all messages
349 * in the last page. We need to re-adjust the start_msg
352 if($start_msg > $num_msgs) {
353 $start_msg -= $show_num;
359 /* This code and the next if() block check for
360 * server-side sorting methods. The $id array is
361 * formatted and $sort is set to 6 to disable
362 * SM internal sorting
365 if ($thread_sort_messages == 1) {
367 } elseif ($allow_server_sort == 1) {
368 $mode = 'serversort';
373 sqsession_unregister('msort');
374 sqsession_unregister('msgs');
377 $id = get_thread_sort($imapConnection);
378 $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
379 if ($msgs === false) {
380 echo '<b><small><center><font color=red>' .
381 _("Thread sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
382 '</center></small></b>';
383 $thread_sort_messages = 0;
384 $msort = $msgs = array();
391 $id = sqimap_get_sort_order($imapConnection, $sort, $mbxresponse);
392 $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
393 if ($msgs === false) {
394 echo '<b><small><center><font color=red>' .
395 _( "Server-side sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
396 '</center></small></b>';
397 $sort = $server_sort_order;
398 $allow_server_sort = FALSE;
399 $msort = $msgs = array();
408 $msgs = getSelfSortMessages($imapConnection, $start_msg, $show_num,
409 $num_msgs, $sort, $mbxresponse);
410 $msort = calc_msort($msgs, $sort);
414 sqsession_register($msort, 'msort');
415 sqsession_register($msgs, 'msgs');
416 } /* if exists > 0 */
418 $res = getEndMessage($start_msg, $show_num, $num_msgs);
419 $start_msg = $res[0];
422 $paginator_str = get_paginator_str($mailbox, $start_msg, $end_msg,
423 $num_msgs, $show_num, $sort);
425 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
427 do_hook('mailbox_index_before');
428 echo '<table dir="' . $language_align['dir'] . '" border="0" width="100%" cellpadding="0" cellspacing="0">';
431 mail_message_listing_beginning($imapConnection, $mailbox, $sort,
432 $msg_cnt_str, $paginator_str, $start_msg);
434 /* line between the button area and the list */
435 echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>';
438 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
440 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[5].'">';
442 printHeader($mailbox, $srt, $color, !$thread_sort_messages);
444 displayMessageArray($imapConnection, $num_msgs, $start_msg,
445 $msort, $mailbox, $sort, $color, $show_num,0,0);
446 echo '</td></tr></table></td></tr></table>';
448 mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color);
449 echo '</td></tr></table>';
452 function calc_msort($msgs, $sort) {
463 if (($sort == 0) ||
($sort == 1)) {
464 foreach ($msgs as $item) {
465 $msort[] = $item['TIME_STAMP'];
467 } elseif (($sort == 2) ||
($sort == 3)) {
468 foreach ($msgs as $item) {
469 $msort[] = $item['FROM-SORT'];
471 } elseif (($sort == 4) ||
($sort == 5)) {
472 foreach ($msgs as $item) {
473 $msort[] = $item['SUBJECT-SORT'];
488 function fillMessageArray($imapConnection, $id, $count) {
489 $msgs_list = sqimap_get_small_header_list($imapConnection, $id);
491 if (sizeof($msgs_list)) {
492 foreach ($msgs_list as $hdr) {
493 $unique_id[] = $hdr->uid
;
494 $from[] = $hdr->from
;
495 $date[] = $hdr->date
;
496 $subject[] = $hdr->subject
;
498 $priority[] = $hdr->priority
;
500 $size[] = $hdr->size
;
501 $type[] = $hdr->type0
;
502 $flag_deleted[] = $hdr->flag_deleted
;
503 $flag_answered[] = $hdr->flag_answered
;
504 $flag_seen[] = $hdr->flag_seen
;
505 $flag_flagged[] = $hdr->flag_flagged
;
509 for($j = 0; $j < $count; ++
$j) {
510 if (isset($date[$j])) {
511 $date[$j] = str_replace(' ', ' ', $date[$j]);
512 $tmpdate = explode(' ', trim($date[$j]));
514 $tmpdate = $date = array('', '', '', '', '', '');
516 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
517 $messages[$j]['DATE_STRING'] =
518 getDateString($messages[$j]['TIME_STAMP']);
519 $messages[$j]['ID'] = $unique_id[$j];
520 $messages[$j]['FROM'] = decodeHeader($from[$j]);
521 $messages[$j]['FROM-SORT'] =
522 strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
523 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
524 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
525 $messages[$j]['TO'] = decodeHeader($to[$j]);
526 $messages[$j]['PRIORITY'] = $priority[$j];
527 $messages[$j]['CC'] = $cc[$j];
528 $messages[$j]['SIZE'] = $size[$j];
529 $messages[$j]['TYPE0'] = $type[$j];
530 $messages[$j]['FLAG_DELETED'] = $flag_deleted[$j];
531 $messages[$j]['FLAG_ANSWERED'] = $flag_answered[$j];
532 $messages[$j]['FLAG_SEEN'] = $flag_seen[$j];
533 $messages[$j]['FLAG_FLAGGED'] = $flag_flagged[$j];
536 * fix SUBJECT-SORT to remove Re:
540 * TODO: i18n should be incorporated here. E.g. we catch the ones
541 * we know about, but also define in i18n what the localized
542 * "Re: " is for this or that locale.
544 if (preg_match("/^(vedr|sv|re|aw):\s*(.*)$/si",
545 $messages[$j]['SUBJECT-SORT'], $matches)){
546 $messages[$j]['SUBJECT-SORT'] = $matches[2];
553 /* Generic function to convert the msgs array into an HTML table. */
554 function displayMessageArray($imapConnection, $num_msgs, $start_msg,
555 $msort, $mailbox, $sort, $color,
556 $show_num, $where=0, $what=0) {
557 global $imapServerAddress, $use_mailbox_cache, $index_order,
558 $indent_array, $thread_sort_messages, $allow_server_sort,
559 $server_sort_order, $PHP_SELF;
561 $res = getEndMessage($start_msg, $show_num, $num_msgs);
562 $start_msg = $res[0];
565 $urlMailbox = urlencode($mailbox);
567 /* get indent level for subject display */
568 if ($thread_sort_messages == 1 && $num_msgs) {
569 $indent_array = get_parent_level($imapConnection);
572 $real_startMessage = $start_msg;
574 if ($end_msg - $start_msg < $show_num - 1) {
575 $end_msg = $end_msg - $start_msg +
1;
577 } else if ($start_msg > $show_num) {
578 $end_msg = $show_num;
582 $endVar = $end_msg +
1;
585 * Loop through and display the info for each message.
586 * ($t is used for the checkbox number)
590 /* messages display */
593 /* if there's no messages in this folder */
596 "<BR><b>" . _("THIS FOLDER IS EMPTY") . "</b><BR> ",
599 'COLSPAN="' . count($index_order) . '"'
602 } elseif ($start_msg == $end_msg) {
603 /* if there's only one message in the box, handle it differently. */
615 } while (isset ($key) && ($k < $i));
616 printMessageInfo($imapConnection, $t, true, $key, $mailbox,
617 $real_startMessage, $where, $what);
626 } while (isset ($key) && ($k < $i));
629 if (!$i ||
$i == $endVar-1) $not_last = false;
630 printMessageInfo($imapConnection, $t, $not_last, $key, $mailbox,
631 $real_startMessage, $where, $what);
636 } while ($i && $i < $endVar);
641 * Displays the standard message list header. To finish the table,
642 * you need to do a "</table></table>";
644 * $moveURL is the URL to submit the delete/move form to
645 * $mailbox is the current mailbox
646 * $sort is the current sorting method (-1 for no sorting available [searches])
647 * $Message is a message that is centered on top of the list
648 * $More is a second line that is left aligned
651 function mail_message_listing_beginning ($imapConnection,
652 $mailbox = '', $sort = -1,
654 $paginator = ' ',
656 global $color, $auto_expunge, $base_uri, $thread_sort_messages,
657 $allow_thread_sort, $allow_server_sort, $server_sort_order,
660 $php_self = $PHP_SELF;
661 /* fix for incorrect $PHP_SELF */
662 if (strpos($php_self, 'move_messages.php')) {
663 $php_self = str_replace('move_messages.php', 'right_main.php', $php_self);
665 $urlMailbox = urlencode($mailbox);
667 if (preg_match('/^(.+)\?.+$/',$php_self,$regs)) {
668 $source_url = $regs[1];
670 $source_url = $php_self;
676 $moveURL = "move_messages.php?msg=$msg&mailbox=$urlMailbox"
677 . "&startMessage=$start_msg";
679 * This is the beginning of the message list table.
680 * It wraps around all messages
682 echo "<FORM name=\"messageList\" method=post action=\"$moveURL\">\n"
683 . html_tag( 'table' ,
688 html_tag( 'td', $paginator, 'left' ) .
689 html_tag( 'td', $msg_cnt_str, 'right' )
691 , '', $color[4], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
694 , '', '', 'border="0" width="100%" cellpadding="1" cellspacing="0"' );
695 /* line between header and button area */
696 echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>';
699 echo html_tag( 'tr' ) . "\n"
700 . html_tag( 'td' ,'' , 'left', '', '' )
701 . html_tag( 'table' ,'' , '', $color[9], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
703 . html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
705 getSmallStringCell(_("Move Selected To"), 'left', 'nowrap') .
706 getSmallStringCell(_("Transform Selected Messages"), 'right')
708 . html_tag( 'tr' ) ."\n"
709 . html_tag( 'td', '', 'left', '', 'valign="middle" nowrap' );
710 getMbxList($imapConnection);
711 echo getButton('SUBMIT', 'moveButton',_("Move")) . "\n";
712 echo getButton('SUBMIT', 'attache',_("Forward")) . "\n";
715 . html_tag( 'td', '', 'right', '', 'nowrap' );
719 if (!$auto_expunge) {
720 echo getButton('SUBMIT', 'expungeButton',_("Expunge"))
721 .' ' . _("mailbox") . "\n";
724 echo getButton('SUBMIT', 'markRead',_("Read"));
725 echo getButton('SUBMIT', 'markUnread',_("Unread"));
726 echo getButton('SUBMIT', 'delete',_("Delete")) ." \n";
727 if (!strpos($php_self,'mailbox')) {
728 $location = $php_self.'?mailbox=INBOX&startMessage=1';
730 $location = $php_self;
732 echo '<INPUT TYPE="HIDDEN" NAME="location" VALUE="'.$location.'">';
736 /* draws thread sorting links */
737 if ($allow_thread_sort == TRUE) {
738 if ($thread_sort_messages == 1 ) {
740 $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> '
755 echo "</TABLE></td></tr></table></td></tr>\n";
757 do_hook('mailbox_form_before');
759 /* if using server sort we highjack the
760 * the $sort var and use $server_sort_order
761 * instead. but here we reset sort for a bit
764 if ($allow_server_sort == TRUE) {
765 $sort = $server_sort_order;
769 function mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color) {
771 /* space between list and footer */
772 echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'" COLSPAN="1">';
774 echo '</td></tr><tr><td>';
775 echo html_tag( 'table',
780 html_tag( 'td', $paginator_str ) .
781 html_tag( 'td', $msg_cnt_str, 'right' )
783 , '', $color[4], 'width="100%" border="0" cellpadding="1" cellspacing="0"' )
786 , '', $color[9], 'width="100%" border="0" cellpadding="1" cellspacing="0"' );
789 /* End of message-list table */
791 do_hook('mailbox_index_after');
795 function printHeader($mailbox, $sort, $color, $showsort=true) {
797 echo html_tag( 'tr' ,'' , 'center', $color[5] );
799 /* calculate the width of the subject column based on the
800 * widths of the other columns */
801 $widths = array(1=>1,2=>25,3=>5,4=>0,5=>1,6=>5);
803 foreach($index_order as $item) {
804 $subjectwidth -= $widths[$item];
807 foreach ($index_order as $item) {
809 case 1: /* checkbox */
811 echo html_tag( 'td' ,' ' , '', '', 'width="1%"' );
814 if (handleAsSent($mailbox)) {
815 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
816 . '<b>' . _("To") . '</b>';
818 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
819 . '<b>' . _("From") . '</b>';
822 ShowSortButton($sort, $mailbox, 2, 3);
827 echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
828 . '<b>' . _("Date") . '</b>';
830 ShowSortButton($sort, $mailbox, 0, 1);
834 case 4: /* subject */
835 echo html_tag( 'td' ,'' , 'left', '', 'width="'.$subjectwidth.'%"' )
836 . '<b>' . _("Subject") . '</b>';
838 ShowSortButton($sort, $mailbox, 4, 5);
843 echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%"' );
852 * This function shows the sort button. Isn't this a good comment?
854 function ShowSortButton($sort, $mailbox, $Up, $Down ) {
856 /* Figure out which image we want to use. */
857 if ($sort != $Up && $sort != $Down) {
858 $img = 'sort_none.png';
860 } elseif ($sort == $Up) {
861 $img = 'up_pointer.png';
864 $img = 'down_pointer.png';
868 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
869 $source_url = $regs[1];
871 $source_url = $PHP_SELF;
874 /* Now that we have everything figured out, show the actual button. */
875 echo ' <a href="' . $source_url .'?newsort=' . $which
876 . '&startMessage=1&mailbox=' . urlencode($mailbox)
877 . '"><IMG SRC="../images/' . $img
878 . '" BORDER=0 WIDTH=12 HEIGHT=10 ALT="sort"></a>';
881 function get_selectall_link($start_msg, $sort) {
882 global $checkall, $what, $where, $mailbox, $javascript_on;
883 global $PHP_SELF, $PG_SHOWNUM;
886 if ($javascript_on) {
887 $result = '<script language="JavaScript" type="text/javascript">'
889 . "function CheckAll() {\n"
890 . " for (var i = 0; i < document.messageList.elements.length; i++) {\n"
891 . " if(document.messageList.elements[i].type == 'checkbox'){\n"
892 . " document.messageList.elements[i].checked = "
893 . " !(document.messageList.elements[i].checked);\n"
898 . '</script><a href="#" onClick="CheckAll();">' . _("Toggle All")
901 if (strpos($PHP_SELF, "?")) {
902 $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($mailbox)
903 . "&startMessage=$start_msg&sort=$sort&checkall=";
905 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
906 . "&startMessage=$start_msg&sort=$sort&checkall=";
908 if (isset($checkall) && $checkall == '1') {
914 if (isset($where) && isset($what)) {
915 $result .= '&where=' . urlencode($where)
916 . '&what=' . urlencode($what);
920 if (isset($checkall) && ($checkall == '1')) {
921 $result .= _("Unselect All");
923 $result .= _("Select All");
928 /* Return our final result. */
933 * This function computes the "Viewing Messages..." string.
935 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
936 /* Compute the $msg_cnt_str. */
938 if ($start_msg < $end_msg) {
939 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"),
940 $start_msg, $end_msg, $num_msgs);
941 } else if ($start_msg == $end_msg) {
942 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
946 /* Return our result string. */
951 * Generate a paginator link.
953 function get_paginator_link($box, $start_msg, $use, $text) {
956 $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
957 . "&startMessage=$start_msg&mailbox=$box\" "
958 . "TARGET=\"right\">$text</A>";
961 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
962 $source_url = $regs[1];
964 $source_url = $PHP_SELF;
967 $result = '<A HREF="'. $source_url . "?use_mailbox_cache=$use"
968 . "&startMessage=$start_msg&mailbox=$box\" "
969 . "TARGET=\"right\">$text</A>";
975 * This function computes the paginator string.
977 function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
979 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
981 /* Initialize paginator string chunks. */
988 $box = urlencode($box);
990 /* Create simple strings that will be creating the paginator. */
991 $spc = ' '; /* This will be used as a space. */
992 $sep = '|'; /* This will be used as a seperator. */
994 /* Get some paginator preference values. */
995 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON
);
996 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
);
998 /* Make sure that our start message number is not too big. */
999 $start_msg = min($start_msg, $num_msgs);
1001 /* Decide whether or not we will use the mailbox cache. */
1002 /* Not sure why $use_mailbox_cache is even passed in. */
1009 /* Compute the starting message of the previous and next page group. */
1010 $next_grp = $start_msg +
$show_num;
1011 $prev_grp = $start_msg - $show_num;
1013 /* Compute the basic previous and next strings. */
1014 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
1015 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1016 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1017 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
1018 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1019 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
1020 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
1021 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
1022 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1025 /* Page selector block. Following code computes page links. */
1026 if ($pg_sel && ($num_msgs > $show_num)) {
1027 /* Most importantly, what is the current page!!! */
1028 $cur_pg = intval($start_msg / $show_num) +
1;
1030 /* Compute total # of pages and # of paginator page links. */
1031 $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
1032 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
1034 /* Compute the size of the four quarters of the page links. */
1036 /* If we can, just show all the pages. */
1037 if (($tot_pgs - 1) <= $pg_max) {
1038 $q1_pgs = $cur_pg - 1;
1039 $q2_pgs = $q3_pgs = 0;
1040 $q4_pgs = $tot_pgs - $cur_pg;
1042 /* Otherwise, compute some magic to choose the four quarters. */
1045 * Compute the magic base values. Added together,
1046 * these values will always equal to the $pag_pgs.
1047 * NOTE: These are DEFAULT values and do not take
1048 * the current page into account. That is below.
1050 $q1_pgs = floor($vis_pgs/4);
1051 $q2_pgs = round($vis_pgs/4, 0);
1052 $q3_pgs = ceil($vis_pgs/4);
1053 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
1055 /* Adjust if the first quarter contains the current page. */
1056 if (($cur_pg - $q1_pgs) < 1) {
1057 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) +
$q2_pgs;
1058 $q1_pgs = $cur_pg - 1;
1060 $q3_pgs +
= ceil($extra_pgs / 2);
1061 $q4_pgs +
= floor($extra_pgs / 2);
1063 /* Adjust if the first and second quarters intersect. */
1064 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
1065 $extra_pgs = $q2_pgs;
1066 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1067 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1068 $q3_pgs +
= ceil($extra_pgs / 2);
1069 $q4_pgs +
= floor($extra_pgs / 2);
1071 /* Adjust if the fourth quarter contains the current page. */
1072 } else if (($cur_pg +
$q4_pgs) >= $tot_pgs) {
1073 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) +
$q3_pgs;
1075 $q4_pgs = $tot_pgs - $cur_pg;
1076 $q1_pgs +
= floor($extra_pgs / 2);
1077 $q2_pgs +
= ceil($extra_pgs / 2);
1079 /* Adjust if the third and fourth quarter intersect. */
1080 } else if (($cur_pg +
$q3_pgs +
1) >= ($tot_pgs - $q4_pgs +
1)) {
1081 $extra_pgs = $q3_pgs;
1082 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1083 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1084 $q1_pgs +
= floor($extra_pgs / 2);
1085 $q2_pgs +
= ceil($extra_pgs / 2);
1090 * I am leaving this debug code here, commented out, because
1091 * it is a really nice way to see what the above code is doing.
1092 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
1093 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
1096 /* Print out the page links from the compute page quarters. */
1098 /* Start with the first quarter. */
1099 if (($q1_pgs == 0) && ($cur_pg > 1)) {
1100 $pg_str .= "...$spc";
1102 for ($pg = 1; $pg <= $q1_pgs; ++
$pg) {
1103 $start = (($pg-1) * $show_num) +
1;
1104 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1106 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
1107 $pg_str .= "...$spc";
1111 /* Continue with the second quarter. */
1112 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++
$pg) {
1113 $start = (($pg-1) * $show_num) +
1;
1114 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1117 /* Now print the current page. */
1118 $pg_str .= $cur_pg . $spc;
1120 /* Next comes the third quarter. */
1121 for ($pg = $cur_pg +
1; $pg <= $cur_pg +
$q3_pgs; ++
$pg) {
1122 $start = (($pg-1) * $show_num) +
1;
1123 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1126 /* And last, print the forth quarter page links. */
1127 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
1128 $pg_str .= "...$spc";
1130 if (($tot_pgs - $q4_pgs) > ($cur_pg +
$q3_pgs)) {
1131 $pg_str .= "...$spc";
1133 for ($pg = $tot_pgs - $q4_pgs +
1; $pg <= $tot_pgs; ++
$pg) {
1134 $start = (($pg-1) * $show_num) +
1;
1135 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1138 } else if ($PG_SHOWNUM == 999999) {
1139 $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
1140 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1141 . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc;
1144 /* If necessary, compute the 'show all' string. */
1145 if (($prv_str != '') ||
($nxt_str != '')) {
1146 $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
1147 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1148 . "TARGET=\"right\">" . _("Show All") . '</A>';
1151 /* Last but not least, get the value for the toggle all link. */
1152 $tgl_str = get_selectall_link($start_msg, $sort);
1154 /* Put all the pieces of the paginator string together. */
1156 * Hairy code... But let's leave it like it is since I am not certain
1157 * a different approach would be any easier to read. ;)
1160 $result .= ($prv_str != '' ?
$prv_str . $spc . $sep . $spc : '');
1161 $result .= ($nxt_str != '' ?
$nxt_str . $spc . $sep . $spc : '');
1162 $result .= ($pg_str != '' ?
$pg_str : '');
1163 $result .= ($all_str != '' ?
$sep . $spc . $all_str . $spc : '');
1164 $result .= ($result != '' ?
$sep . $spc . $tgl_str: $tgl_str);
1166 /* If the resulting string is blank, return a non-breaking space. */
1167 if ($result == '') {
1171 /* Return our final magical paginator string. */
1175 function processSubject($subject, $threadlevel = 0) {
1176 global $languages, $squirrelmail_language;
1177 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1179 return _("(no subject)");
1183 /* if this is threaded, substract two chars per indentlevel */
1184 if($threadlevel > 0 && $threadlevel <= 10)
1185 $trim_at -= (2*$threadlevel);
1187 if (strlen($subject) <= $trim_at)
1190 $ent_strlen = strlen($subject);
1191 $trim_val = $trim_at - 5;
1194 * see if this is entities-encoded string
1195 * If so, Iterate through the whole string, find out
1196 * the real number of characters, and if more
1197 * than 55, substr with an updated trim value.
1199 while ( (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1200 (($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false) ) {
1201 $trim_val +
= ($ent_loc_end-$ent_loc)+
1;
1202 $ent_strlen -= $ent_loc_end-$ent_loc;
1203 $ent_offset = $ent_loc_end+
1;
1206 if ($ent_strlen <= $trim_at){
1210 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
1211 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
1212 return $languages[$squirrelmail_language]['XTRA_CODE']('strimwidth', $subject, $trim_val);
1215 return substr($subject, 0, $trim_val) . '...';
1218 function getMbxList($imapConnection) {
1219 global $lastTargetMailbox;
1220 echo ' <small> <tt><select name="targetMailbox">';
1221 echo sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)) );
1222 echo ' </SELECT></TT> ';
1225 function getButton($type, $name, $value) {
1226 return '<INPUT TYPE="'.$type.'" NAME="'.$name.'" VALUE="'.$value . '">';
1229 function getSmallStringCell($string, $align) {
1230 return html_tag('td',
1231 '<small>' . $string . ': </small>',
1237 function getEndMessage($start_msg, $show_num, $num_msgs) {
1238 if ($start_msg +
($show_num - 1) < $num_msgs){
1239 $end_msg = $start_msg +
($show_num - 1);
1241 $end_msg = $num_msgs;
1244 if ($end_msg < $start_msg) {
1245 $start_msg = $start_msg - $show_num;
1246 if ($start_msg < 1) {
1250 return (array($start_msg,$end_msg));
1253 function handleAsSent($mailbox) {
1254 global $sent_folder, $draft_folder, $handleAsSent_result;
1256 /* First check if this is the sent or draft folder. */
1257 $handleAsSent_result = (($mailbox == $sent_folder)
1258 ||
($mailbox == $draft_folder));
1260 /* Then check the result of the handleAsSent hook. */
1261 do_hook('check_handleAsSent_result', $mailbox);
1263 /* And return the result. */
1264 return ($handleAsSent_result);