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(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, $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;
352 $num_msgs = $mbxresponse['EXISTS'];
355 if ($mbxresponse['EXISTS']>0) {
356 /* if $start_msg is lower than $num_msgs, we probably deleted all messages
357 * in the last page. We need to re-adjust the start_msg
360 if($start_msg > $num_msgs) {
361 $start_msg -= $show_num;
367 /* This code and the next if() block check for
368 * server-side sorting methods. The $id array is
369 * formatted and $sort is set to 6 to disable
370 * SM internal sorting
373 if ($thread_sort_messages == 1) {
375 } elseif ($allow_server_sort == 1) {
376 $mode = 'serversort';
383 session_unregister('msort');
384 session_unregister('msgs');
385 $msgs = getThreadMessages($imapConnection, $start_msg, $show_num,
387 if ($msgs === false) {
388 echo '<b><small><center><font color=red>' .
389 _("Thread sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
390 '</center></small></b>';
391 $thread_sort_messages = 0;
392 $msort = $msgs = array();
393 session_register('msort');
394 session_register('msgs');
398 session_register('msort');
399 session_register('msgs');
404 $msgs = getServerSortMessages($imapConnection, $start_msg, $show_num,
405 $num_msgs, $sort, $mbxresponse);
406 if ($msgs === false) {
407 echo '<b><small><center><font color=red>' .
408 _( "Server-side sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
409 '</center></small></b>';
410 $sort = $server_sort_order;
411 $allow_server_sort = FALSE;
412 $msort = $msgs = array();
413 session_register('msort');
414 session_register('msgs');
419 session_register('msort');
420 session_register('msgs');
425 session_unregister('msgs');
426 session_unregister('msort');
427 $msgs= getSelfSortMessages($imapConnection, $start_msg, $show_num,
428 $num_msgs, $sort, $mbxresponse);
429 $msort = calc_msort($msgs, $sort);
430 session_register('msort');
431 session_register('msgs');
435 } /* if exists > 0 */
437 $res = getEndMessage($start_msg, $show_num, $num_msgs);
438 $start_msg = $res[0];
441 $paginator_str = get_paginator_str($mailbox, $start_msg, $end_msg,
442 $num_msgs, $show_num, $sort);
444 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
446 do_hook('mailbox_index_before');
448 mail_message_listing_beginning($imapConnection, $mailbox, $sort,
449 $msg_cnt_str, $paginator_str, $start_msg);
452 echo '<table bgcolor="' . $color[0] . '" border="0" width="100%" cellpadding="1" cellspacing="0"><tr><td>';
453 printHeader($mailbox, $srt, $color, !$thread_sort_messages);
455 displayMessageArray($imapConnection, $num_msgs, $start_msg,
456 $msort, $mailbox, $sort, $color, $show_num,0,0);
458 mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color);
459 echo '</td></tr></table>';
462 * TODO: Switch to using $_SESSION[] whenever we ditch the 4.0.x series.
466 function calc_msort($msgs, $sort) {
476 if (($sort == 0) ||
($sort == 1)) {
477 $msort = array_cleave ($msgs, 'TIME_STAMP');
478 } elseif (($sort == 2) ||
($sort == 3)) {
479 $msort = array_cleave ($msgs, 'FROM-SORT');
480 } elseif (($sort == 4) ||
($sort == 5)) {
481 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
495 function fillMessageArray($imapConnection,$id,$count) {
496 $msgs_list = sqimap_get_small_header_list($imapConnection, $id);
498 if (sizeof($msgs_list)){
499 foreach ($msgs_list as $hdr) {
500 $unique_id[] = $hdr->uid
;
501 $from[] = $hdr->from
;
502 $date[] = $hdr->date
;
503 $subject[] = $hdr->subject
;
505 $priority[] = $hdr->priority
;
507 $size[] = $hdr->size
;
508 $type[] = $hdr->type0
;
509 $flag_deleted[] = $hdr->flag_deleted
;
510 $flag_answered[] = $hdr->flag_answered
;
511 $flag_seen[] = $hdr->flag_seen
;
512 $flag_flagged[] = $hdr->flag_flagged
;
517 while ($j < $count) {
519 if (isset($date[$j])) {
520 $date[$j] = str_replace(' ', ' ', $date[$j]);
521 $tmpdate = explode(' ', trim($date[$j]));
523 $tmpdate = $date = array('', '', '', '', '', '');
525 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
526 $messages[$j]['DATE_STRING'] =
527 getDateString($messages[$j]['TIME_STAMP']);
528 $messages[$j]['ID'] = $unique_id[$j];
529 $messages[$j]['FROM'] = decodeHeader($from[$j]);
530 $messages[$j]['FROM-SORT'] =
531 strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
532 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
533 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
534 $messages[$j]['TO'] = decodeHeader($to[$j]);
535 $messages[$j]['PRIORITY'] = $priority[$j];
536 $messages[$j]['CC'] = $cc[$j];
537 $messages[$j]['SIZE'] = $size[$j];
538 $messages[$j]['TYPE0'] = $type[$j];
539 $messages[$j]['FLAG_DELETED'] = $flag_deleted[$j];
540 $messages[$j]['FLAG_ANSWERED'] = $flag_answered[$j];
541 $messages[$j]['FLAG_SEEN'] = $flag_seen[$j];
542 $messages[$j]['FLAG_FLAGGED'] = $flag_flagged[$j];
546 * fix SUBJECT-SORT to remove Re:
550 * TODO: i18n should be incorporated here. E.g. we catch the ones
551 * we know about, but also define in i18n what the localized
552 * "Re: " is for this or that locale.
554 if (preg_match("/^(vedr|sv|re|aw):\s*(.*)$/si",
555 $messages[$j]['SUBJECT-SORT'], $matches)){
556 $messages[$j]['SUBJECT-SORT'] = $matches[2];
564 /* Generic function to convert the msgs array into an HTML table. */
565 function displayMessageArray($imapConnection, $num_msgs, $start_msg,
566 $msort, $mailbox, $sort, $color,
567 $show_num, $where=0, $what=0) {
568 global $imapServerAddress, $use_mailbox_cache,
569 $index_order, $checkall,
570 $indent_array, $thread_sort_messages, $allow_server_sort,
571 $server_sort_order, $PHP_SELF;
573 $res = getEndMessage($start_msg, $show_num, $num_msgs);
574 $start_msg = $res[0];
577 $urlMailbox = urlencode($mailbox);
579 /* get indent level for subject display */
580 if ($thread_sort_messages == 1 ) {
581 $indent_array = get_parent_level($imapConnection);
585 $real_startMessage = $start_msg;
587 if ($end_msg - $start_msg < $show_num - 1) {
588 $end_msg = $end_msg - $start_msg +
1;
590 } else if ($start_msg > $show_num) {
591 $end_msg = $show_num;
595 $endVar = $end_msg +
1;
598 * Loop through and display the info for each message.
599 * ($t is used for the checkbox number)
603 /* messages display */
605 if ($num_msgs == 0) {
606 /* if there's no messages in this folder */
609 "<BR><b>" . _("THIS FOLDER IS EMPTY") . "</b><BR> ",
612 'COLSPAN="' . count($index_order) . '"'
615 } elseif ($start_msg == $end_msg) {
616 /* if there's only one message in the box, handle it differently. */
628 } while (isset ($key) && ($k < $i));
629 printMessageInfo($imapConnection, $t, $i, $key, $mailbox,
630 $real_startMessage, $where, $what);
639 } while (isset ($key) && ($k < $i));
641 printMessageInfo($imapConnection, $t, $i, $key, $mailbox,
642 $real_startMessage, $where, $what);
647 } while ($i && $i < $endVar);
653 * Displays the standard message list header. To finish the table,
654 * you need to do a "</table></table>";
656 * $moveURL is the URL to submit the delete/move form to
657 * $mailbox is the current mailbox
658 * $sort is the current sorting method (-1 for no sorting available [searches])
659 * $Message is a message that is centered on top of the list
660 * $More is a second line that is left aligned
663 function mail_message_listing_beginning ($imapConnection,
664 $mailbox = '', $sort = -1,
666 $paginator = ' ',
668 global $color, $auto_expunge, $base_uri, $thread_sort_messages,
669 $allow_thread_sort, $allow_server_sort, $server_sort_order,
672 $urlMailbox = urlencode($mailbox);
674 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
675 $source_url = $regs[1];
677 $source_url = $PHP_SELF;
683 $moveURL = "move_messages.php?msg=$msg&mailbox=$urlMailbox"
684 . "&startMessage=$start_msg";
687 * This is the beginning of the message list table.
688 * It wraps around all messages
691 echo "<FORM name=\"messageList\" method=post action=\"$moveURL\">\n"
692 . html_tag( 'table' ,'' , '', '', 'border="0" width="100%" cellpadding="1" cellspacing="0"' ) .
697 html_tag( 'td', $paginator, 'left' ) .
698 html_tag( 'td', $msg_cnt_str, 'right' )
700 , '', $color[4], 'border="0" width="100%" cellpadding="2" cellspacing="0"' )
703 . html_tag( 'tr' ) . "\n"
704 . html_tag( 'td' ,'' , 'left', $color[0], '' )
705 . html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="0" cellspacing="0"' )
707 getSmallStringCell(_("Move Selected To"), 'left') .
708 getSmallStringCell(_("Transform Selected Messages"), 'right')
710 . html_tag( 'tr' ) ."\n"
711 . html_tag( 'td', '', 'left', '', 'valign="middle" nowrap' );
712 getMbxList($imapConnection);
713 echo getButton('SUBMIT', 'moveButton',_("Move")) . "\n";
714 echo getButton('SUBMIT', 'attache',_("Forward")) . "\n";
717 . 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");
742 elseif ($thread_sort_messages == 0) {
744 $thread_name = _("Thread View");
746 echo html_tag( 'tr' ,
748 ' <a href=' . $source_url . '?sort='
749 . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
750 . '&mailbox=' . urlencode($mailbox) . '><small>' . $thread_name
751 . '</a></small> '
760 do_hook('mailbox_form_before');
764 . html_tag( 'td' ,'' , '', $color[0], '' );
765 if ($GLOBALS['alt_index_colors']){
770 echo html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="2" cellspacing="'. $cellspacing .'"' );
772 /* if using server sort we highjack the
773 * the $sort var and use $server_sort_order
774 * instead. but here we reset sort for a bit
777 if ($allow_server_sort == TRUE) {
778 $sort = $server_sort_order;
782 function mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color) {
784 echo html_tag( 'table',
789 html_tag( 'td', $paginator_str ) .
790 html_tag( 'td', $msg_cnt_str, 'right' )
792 , '', $color[4], 'width="100%" cellpadding="1" cellspacing="1"' )
795 , '', $color[9], 'width="100%" cellpadding="1" cellspacing="1"' );
798 /* End of message-list table */
800 do_hook('mailbox_index_after');
805 function printHeader($mailbox, $sort, $color, $showsort=true) {
807 echo html_tag( 'table' ,'' , '', $color[4], 'border="0" width="100%" cellpadding="1" cellspacing="0"' );
808 echo html_tag( 'tr' ,'' , 'center', $color[5] );
809 for ($i=1; $i <= count($index_order); $i++
) {
810 switch ($index_order[$i]) {
811 case 1: /* checkbox */
813 echo html_tag( 'td' ,' ' , '', '', 'width="1%"' );
816 if (handleAsSent($mailbox)) {
817 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
818 . '<b>' . _("To") . '</b>';
820 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
821 . '<b>' . _("From") . '</b>';
824 ShowSortButton($sort, $mailbox, 2, 3);
829 echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
830 . '<b>' . _("Date") . '</b>';
832 ShowSortButton($sort, $mailbox, 0, 1);
836 case 4: /* subject */
837 echo html_tag( 'td' ,'' , 'left', '', '' )
838 . '<b>' . _("Subject") . '</b>';
840 ShowSortButton($sort, $mailbox, 4, 5);
845 echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%"' );
854 * This function shows the sort button. Isn't this a good comment?
856 function ShowSortButton($sort, $mailbox, $Up, $Down ) {
858 /* Figure out which image we want to use. */
859 if ($sort != $Up && $sort != $Down) {
860 $img = 'sort_none.png';
862 } elseif ($sort == $Up) {
863 $img = 'up_pointer.png';
866 $img = 'down_pointer.png';
870 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
871 $source_url = $regs[1];
873 $source_url = $PHP_SELF;
876 /* Now that we have everything figured out, show the actual button. */
877 echo ' <a href="' . $source_url .'?newsort=' . $which
878 . '&startMessage=1&mailbox=' . urlencode($mailbox)
879 . '"><IMG SRC="../images/' . $img
880 . '" BORDER=0 WIDTH=12 HEIGHT=10 ALT="sort"></a>';
883 function get_selectall_link($start_msg, $sort) {
884 global $checkall, $what, $where, $mailbox, $javascript_on;
885 global $PHP_SELF, $PG_SHOWNUM;
888 if ($javascript_on) {
890 '<script language="JavaScript" type="text/javascript">'
892 . "function CheckAll() {\n"
893 . " for (var i = 0; i < document.messageList.elements.length; i++) {\n"
894 . " if(document.messageList.elements[i].type == 'checkbox'){\n"
895 . " document.messageList.elements[i].checked = "
896 . " !(document.messageList.elements[i].checked);\n"
901 . '</script><a href="#" onClick="CheckAll();">' . _("Toggle All")
904 if (strpos($PHP_SELF, "?")) {
905 $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($mailbox)
906 . "&startMessage=$start_msg&sort=$sort&checkall=";
908 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
909 . "&startMessage=$start_msg&sort=$sort&checkall=";
911 if (isset($checkall) && $checkall == '1') {
917 if (isset($where) && isset($what)) {
918 $result .= '&where=' . urlencode($where)
919 . '&what=' . urlencode($what);
924 if (isset($checkall) && ($checkall == '1')) {
925 $result .= _("Unselect All");
927 $result .= _("Select All");
933 /* Return our final result. */
938 * This function computes the "Viewing Messages..." string.
940 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
941 /* Compute the $msg_cnt_str. */
943 if ($start_msg < $end_msg) {
944 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"),
945 $start_msg, $end_msg, $num_msgs);
946 } else if ($start_msg == $end_msg) {
947 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
951 /* Return our result string. */
956 * Generate a paginator link.
958 function get_paginator_link($box, $start_msg, $use, $text) {
961 $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
962 . "&startMessage=$start_msg&mailbox=$box\" "
963 . "TARGET=\"right\">$text</A>";
966 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
967 $source_url = $regs[1];
969 $source_url = $PHP_SELF;
972 $result = '<A HREF="'. $source_url . "?use_mailbox_cache=$use"
973 . "&startMessage=$start_msg&mailbox=$box\" "
974 . "TARGET=\"right\">$text</A>";
980 * This function computes the paginator string.
982 function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
984 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
986 /* Initialize paginator string chunks. */
993 $box = urlencode($box);
995 /* Create simple strings that will be creating the paginator. */
996 $spc = ' '; /* This will be used as a space. */
997 $sep = '|'; /* This will be used as a seperator. */
999 /* Get some paginator preference values. */
1000 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON
);
1001 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
);
1003 /* Make sure that our start message number is not too big. */
1004 $start_msg = min($start_msg, $num_msgs);
1006 /* Decide whether or not we will use the mailbox cache. */
1007 /* Not sure why $use_mailbox_cache is even passed in. */
1014 /* Compute the starting message of the previous and next page group. */
1015 $next_grp = $start_msg +
$show_num;
1016 $prev_grp = $start_msg - $show_num;
1018 /* Compute the basic previous and next strings. */
1019 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
1020 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1021 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1022 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
1023 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1024 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
1025 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
1026 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
1027 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1030 /* Page selector block. Following code computes page links. */
1031 if ($pg_sel && ($num_msgs > $show_num)) {
1032 /* Most importantly, what is the current page!!! */
1033 $cur_pg = intval($start_msg / $show_num) +
1;
1035 /* Compute total # of pages and # of paginator page links. */
1036 $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
1037 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
1039 /* Compute the size of the four quarters of the page links. */
1041 /* If we can, just show all the pages. */
1042 if (($tot_pgs - 1) <= $pg_max) {
1043 $q1_pgs = $cur_pg - 1;
1044 $q2_pgs = $q3_pgs = 0;
1045 $q4_pgs = $tot_pgs - $cur_pg;
1047 /* Otherwise, compute some magic to choose the four quarters. */
1050 * Compute the magic base values. Added together,
1051 * these values will always equal to the $pag_pgs.
1052 * NOTE: These are DEFAULT values and do not take
1053 * the current page into account. That is below.
1055 $q1_pgs = floor($vis_pgs/4);
1056 $q2_pgs = round($vis_pgs/4, 0);
1057 $q3_pgs = ceil($vis_pgs/4);
1058 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
1060 /* Adjust if the first quarter contains the current page. */
1061 if (($cur_pg - $q1_pgs) < 1) {
1062 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) +
$q2_pgs;
1063 $q1_pgs = $cur_pg - 1;
1065 $q3_pgs +
= ceil($extra_pgs / 2);
1066 $q4_pgs +
= floor($extra_pgs / 2);
1068 /* Adjust if the first and second quarters intersect. */
1069 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
1070 $extra_pgs = $q2_pgs;
1071 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1072 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1073 $q3_pgs +
= ceil($extra_pgs / 2);
1074 $q4_pgs +
= floor($extra_pgs / 2);
1076 /* Adjust if the fourth quarter contains the current page. */
1077 } else if (($cur_pg +
$q4_pgs) >= $tot_pgs) {
1078 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) +
$q3_pgs;
1080 $q4_pgs = $tot_pgs - $cur_pg;
1081 $q1_pgs +
= floor($extra_pgs / 2);
1082 $q2_pgs +
= ceil($extra_pgs / 2);
1084 /* Adjust if the third and fourth quarter intersect. */
1085 } else if (($cur_pg +
$q3_pgs +
1) >= ($tot_pgs - $q4_pgs +
1)) {
1086 $extra_pgs = $q3_pgs;
1087 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1088 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1089 $q1_pgs +
= floor($extra_pgs / 2);
1090 $q2_pgs +
= ceil($extra_pgs / 2);
1095 * I am leaving this debug code here, commented out, because
1096 * it is a really nice way to see what the above code is doing.
1097 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
1098 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
1101 /* Print out the page links from the compute page quarters. */
1103 /* Start with the first quarter. */
1104 if (($q1_pgs == 0) && ($cur_pg > 1)) {
1105 $pg_str .= "...$spc";
1107 for ($pg = 1; $pg <= $q1_pgs; ++
$pg) {
1108 $start = (($pg-1) * $show_num) +
1;
1109 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1111 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
1112 $pg_str .= "...$spc";
1116 /* Continue with the second quarter. */
1117 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++
$pg) {
1118 $start = (($pg-1) * $show_num) +
1;
1119 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1122 /* Now print the current page. */
1123 $pg_str .= $cur_pg . $spc;
1125 /* Next comes the third quarter. */
1126 for ($pg = $cur_pg +
1; $pg <= $cur_pg +
$q3_pgs; ++
$pg) {
1127 $start = (($pg-1) * $show_num) +
1;
1128 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1131 /* And last, print the forth quarter page links. */
1132 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
1133 $pg_str .= "...$spc";
1135 if (($tot_pgs - $q4_pgs) > ($cur_pg +
$q3_pgs)) {
1136 $pg_str .= "...$spc";
1138 for ($pg = $tot_pgs - $q4_pgs +
1; $pg <= $tot_pgs; ++
$pg) {
1139 $start = (($pg-1) * $show_num) +
1;
1140 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1143 } else if ($PG_SHOWNUM == 999999) {
1144 $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
1145 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1146 . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc;
1149 /* If necessary, compute the 'show all' string. */
1150 if (($prv_str != '') ||
($nxt_str != '')) {
1151 $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
1152 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1153 . "TARGET=\"right\">" . _("Show All") . '</A>';
1156 /* Last but not least, get the value for the toggle all link. */
1157 $tgl_str = get_selectall_link($start_msg, $sort);
1159 /* Put all the pieces of the paginator string together. */
1161 * Hairy code... But let's leave it like it is since I am not certain
1162 * a different approach would be any easier to read. ;)
1165 $result .= ($prv_str != '' ?
$prv_str . $spc . $sep . $spc : '');
1166 $result .= ($nxt_str != '' ?
$nxt_str . $spc . $sep . $spc : '');
1167 $result .= ($pg_str != '' ?
$pg_str : '');
1168 $result .= ($all_str != '' ?
$sep . $spc . $all_str . $spc : '');
1169 $result .= ($result != '' ?
$sep . $spc . $tgl_str: $tgl_str);
1171 /* If the resulting string is blank, return a non-breaking space. */
1172 if ($result == '') {
1176 /* Return our final magical paginator string. */
1180 function processSubject($subject) {
1181 global $languages, $squirrelmail_language;
1182 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1184 return _("(no subject)");
1186 if (strlen($subject) <= 55)
1189 $ent_strlen=strlen($subject);
1193 * see if this is entities-encoded string
1194 * If so, Iterate through the whole string, find out
1195 * the real number of characters, and if more
1196 * than 55, substr with an updated trim value.
1198 while ( (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1199 (($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false) ) {
1200 $trim_val +
= ($ent_loc_end-$ent_loc)+
1;
1201 $ent_strlen -= $ent_loc_end-$ent_loc;
1202 $ent_offset = $ent_loc_end+
1;
1205 if ($ent_strlen <= 55){
1209 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
1210 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
1211 return $languages[$squirrelmail_language]['XTRA_CODE']('strimwidth', $subject, $trim_val);
1214 return substr($subject, 0, $trim_val) . '...';
1217 function getMbxList($imapConnection) {
1218 global $lastTargetMailbox;
1219 echo ' <small> <tt><select name="targetMailbox">';
1220 $boxes = sqimap_mailbox_list($imapConnection);
1221 foreach ($boxes as $boxes_part) {
1222 if (!in_array('noselect', $boxes_part['flags'])) {
1223 $box = $boxes_part['unformatted'];
1224 $box2 = str_replace(' ', ' ', imap_utf7_decode_local($boxes_part['unformatted-disp']));
1225 if( $box2 == 'INBOX' ) {
1228 if ($lastTargetMailbox == $box) {
1229 echo " <OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
1232 echo " <OPTION VALUE=\"$box\">$box2</OPTION>\n";
1236 echo ' </SELECT></TT> ';
1239 function getButton($type, $name, $value) {
1240 return '<INPUT TYPE="'.$type.'" NAME="'.$name.'" VALUE="'.$value . '">';
1243 function getSmallStringCell($string, $align) {
1244 return html_tag( 'td',
1245 '<small>' . $string . ': </small>',
1251 function getEndMessage($start_msg, $show_num, $num_msgs) {
1252 if ($start_msg +
($show_num - 1) < $num_msgs){
1253 $end_msg = $start_msg +
($show_num - 1);
1255 $end_msg = $num_msgs;
1258 if ($end_msg < $start_msg) {
1259 $start_msg = $start_msg - $show_num;
1260 if ($start_msg < 1) {
1264 return (array($start_msg,$end_msg));
1267 function handleAsSent($mailbox) {
1268 global $sent_folder, $draft_folder, $handleAsSent_result;
1270 /* First check if this is the sent or draft folder. */
1271 $handleAsSent_result = (($mailbox == $sent_folder)
1272 ||
($mailbox == $draft_folder));
1274 /* Then check the result of the handleAsSent hook. */
1275 do_hook('check_handleAsSent_result', $mailbox);
1277 /* And return the result. */
1278 return ($handleAsSent_result);