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 $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;
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>';
236 $bold . $fontstr . show_readable_size($msg['SIZE']) .
237 $fontstr_end . $bold_end,
245 echo '</tr>'."\n".'<tr><td colspan="'.$col.'" BGCOLOR="'.
246 $color[0].'" HEIGHT="1"></td></tr>'."\n";
249 function getThreadMessages($imapConnection, $start_msg, $show_num, $num_msgs) {
250 $id = get_thread_sort($imapConnection);
252 if ($start_msg +
($show_num - 1) < $num_msgs) {
253 $end_msg = $start_msg +
($show_num-1);
255 $end_msg = $num_msgs;
257 $id = array_slice($id, ($start_msg-1), ($end_msg));
259 $end = $start_msg +
$show_num - 1;
260 if ($num_msgs < $show_num) {
261 $end_loop = $num_msgs;
262 } else if ($end > $num_msgs) {
263 $end_loop = $num_msgs - $start_msg +
1;
265 $end_loop = $show_num;
267 return fillMessageArray($imapConnection,$id,$end_loop);
273 function getServerSortMessages($imapConnection, $start_msg, $show_num,
274 $num_msgs, $server_sort_order, $mbxresponse) {
275 $id = sqimap_get_sort_order($imapConnection, $server_sort_order,$mbxresponse);
277 if ($start_msg +
($show_num - 1) < $num_msgs) {
278 $end_msg = $start_msg +
($show_num-1);
280 $end_msg = $num_msgs;
282 $id = array_slice($id, ($start_msg-1), ($end_msg));
284 $end = $start_msg +
$show_num - 1;
285 if ($num_msgs < $show_num) {
286 $end_loop = $num_msgs;
287 } else if ($end > $num_msgs) {
288 $end_loop = $num_msgs - $start_msg +
1;
290 $end_loop = $show_num;
292 return fillMessageArray($imapConnection,$id,$end_loop);
298 function getSelfSortMessages($imapConnection, $start_msg, $show_num,
299 $num_msgs, $sort, $mbxresponse) {
301 if ($num_msgs >= 1) {
302 $id = sqimap_get_php_sort_order ($imapConnection, $mbxresponse);
307 /* if it's not sorted */
308 if ($start_msg +
($show_num - 1) < $num_msgs) {
309 $end_msg = $start_msg +
($show_num - 1);
311 $end_msg = $num_msgs;
313 if ($end_msg < $start_msg) {
314 $start_msg = $start_msg - $show_num;
315 if ($start_msg < 1) {
319 $id = array_slice(array_reverse($id), ($start_msg-1), ($end_msg));
320 $end = $start_msg +
$show_num - 1;
321 if ($num_msgs < $show_num) {
322 $end_loop = $num_msgs;
323 } else if ($end > $num_msgs) {
324 $end_loop = $num_msgs - $start_msg +
1;
326 $end_loop = $show_num;
329 $msgs = fillMessageArray($imapConnection,$id,$end_loop);
337 * This function loops through a group of messages in the mailbox
338 * and shows them to the user.
340 function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
341 $start_msg, $sort, $color, $show_num,
342 $use_cache, $mode='') {
343 global $msgs, $msort, $auto_expunge, $thread_sort_messages,
344 $allow_server_sort, $server_sort_order;
346 /* If autoexpunge is turned on, then do it now. */
347 $mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox);
349 /* If autoexpunge is turned on, then do it now. */
350 if ($auto_expunge == true) {
351 $exp_cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, false, '');
352 $mbxresponse['EXISTS'] = $mbxresponse['EXISTS'] - $exp_cnt;
353 $num_msgs = $mbxresponse['EXISTS'];
356 if ($mbxresponse['EXISTS'] > 0) {
357 /* if $start_msg is lower than $num_msgs, we probably deleted all messages
358 * in the last page. We need to re-adjust the start_msg
361 if($start_msg > $num_msgs) {
362 $start_msg -= $show_num;
368 /* This code and the next if() block check for
369 * server-side sorting methods. The $id array is
370 * formatted and $sort is set to 6 to disable
371 * SM internal sorting
374 if ($thread_sort_messages == 1) {
376 } elseif ($allow_server_sort == 1) {
377 $mode = 'serversort';
384 sqsession_unregister('msort');
385 sqsession_unregister('msgs');
386 $msgs = getThreadMessages($imapConnection, $start_msg, $show_num,
388 if ($msgs === false) {
389 echo '<b><small><center><font color=red>' .
390 _("Thread sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
391 '</center></small></b>';
392 $thread_sort_messages = 0;
393 $msort = $msgs = array();
394 sqsession_register($msort, 'msort');
395 sqsession_register($msgs, 'msgs');
399 sqsession_register($msort, 'msort');
400 sqsession_register($msgs, '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 sqsession_register($msort, 'msort');
414 sqsession_register($msgs, 'msgs');
419 sqsession_register($msort, 'msort');
420 sqsession_register($msgs, 'msgs');
425 sqsession_unregister('msgs');
426 sqsession_unregister('msort');
427 $msgs = getSelfSortMessages($imapConnection, $start_msg, $show_num,
428 $num_msgs, $sort, $mbxresponse);
429 $msort = calc_msort($msgs, $sort);
430 sqsession_register($msort, 'msort');
431 sqsession_register($msgs, '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
;
516 for($j = 0; $j < $count; ++
$j) {
517 if (isset($date[$j])) {
518 $date[$j] = str_replace(' ', ' ', $date[$j]);
519 $tmpdate = explode(' ', trim($date[$j]));
521 $tmpdate = $date = array('', '', '', '', '', '');
523 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
524 $messages[$j]['DATE_STRING'] =
525 getDateString($messages[$j]['TIME_STAMP']);
526 $messages[$j]['ID'] = $unique_id[$j];
527 $messages[$j]['FROM'] = decodeHeader($from[$j]);
528 $messages[$j]['FROM-SORT'] =
529 strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
530 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
531 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
532 $messages[$j]['TO'] = decodeHeader($to[$j]);
533 $messages[$j]['PRIORITY'] = $priority[$j];
534 $messages[$j]['CC'] = $cc[$j];
535 $messages[$j]['SIZE'] = $size[$j];
536 $messages[$j]['TYPE0'] = $type[$j];
537 $messages[$j]['FLAG_DELETED'] = $flag_deleted[$j];
538 $messages[$j]['FLAG_ANSWERED'] = $flag_answered[$j];
539 $messages[$j]['FLAG_SEEN'] = $flag_seen[$j];
540 $messages[$j]['FLAG_FLAGGED'] = $flag_flagged[$j];
543 * fix SUBJECT-SORT to remove Re:
547 * TODO: i18n should be incorporated here. E.g. we catch the ones
548 * we know about, but also define in i18n what the localized
549 * "Re: " is for this or that locale.
551 if (preg_match("/^(vedr|sv|re|aw):\s*(.*)$/si",
552 $messages[$j]['SUBJECT-SORT'], $matches)){
553 $messages[$j]['SUBJECT-SORT'] = $matches[2];
560 /* Generic function to convert the msgs array into an HTML table. */
561 function displayMessageArray($imapConnection, $num_msgs, $start_msg,
562 $msort, $mailbox, $sort, $color,
563 $show_num, $where=0, $what=0) {
564 global $imapServerAddress, $use_mailbox_cache,
565 $index_order, $checkall,
566 $indent_array, $thread_sort_messages, $allow_server_sort,
567 $server_sort_order, $PHP_SELF;
569 $res = getEndMessage($start_msg, $show_num, $num_msgs);
570 $start_msg = $res[0];
573 $urlMailbox = urlencode($mailbox);
575 /* get indent level for subject display */
576 if ($thread_sort_messages == 1 ) {
577 $indent_array = get_parent_level($imapConnection);
580 $real_startMessage = $start_msg;
582 if ($end_msg - $start_msg < $show_num - 1) {
583 $end_msg = $end_msg - $start_msg +
1;
585 } else if ($start_msg > $show_num) {
586 $end_msg = $show_num;
590 $endVar = $end_msg +
1;
593 * Loop through and display the info for each message.
594 * ($t is used for the checkbox number)
598 /* messages display */
600 if ($num_msgs == 0) {
601 /* if there's no messages in this folder */
604 "<BR><b>" . _("THIS FOLDER IS EMPTY") . "</b><BR> ",
607 'COLSPAN="' . count($index_order) . '"'
610 } elseif ($start_msg == $end_msg) {
611 /* if there's only one message in the box, handle it differently. */
623 } while (isset ($key) && ($k < $i));
624 printMessageInfo($imapConnection, $t, $i, $key, $mailbox,
625 $real_startMessage, $where, $what);
634 } while (isset ($key) && ($k < $i));
636 printMessageInfo($imapConnection, $t, $i, $key, $mailbox,
637 $real_startMessage, $where, $what);
642 } while ($i && $i < $endVar);
648 * Displays the standard message list header. To finish the table,
649 * you need to do a "</table></table>";
651 * $moveURL is the URL to submit the delete/move form to
652 * $mailbox is the current mailbox
653 * $sort is the current sorting method (-1 for no sorting available [searches])
654 * $Message is a message that is centered on top of the list
655 * $More is a second line that is left aligned
658 function mail_message_listing_beginning ($imapConnection,
659 $mailbox = '', $sort = -1,
661 $paginator = ' ',
663 global $color, $auto_expunge, $base_uri, $thread_sort_messages,
664 $allow_thread_sort, $allow_server_sort, $server_sort_order,
667 $php_self = $PHP_SELF;
668 /* fix for incorrect $PHP_SELF */
669 if (strpos($php_self, 'move_messages.php')) {
670 $php_self = str_replace('move_messages.php', 'right_main.php', $php_self);
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";
686 * This is the beginning of the message list table.
687 * It wraps around all messages
690 echo "<FORM name=\"messageList\" method=post action=\"$moveURL\">\n"
691 . html_tag( 'table' ,'' , '', '', 'border="0" width="100%" cellpadding="1" cellspacing="0"' ) .
696 html_tag( 'td', $paginator, 'left' ) .
697 html_tag( 'td', $msg_cnt_str, 'right' )
699 , '', $color[4], 'border="0" width="100%" cellpadding="2" cellspacing="0"' )
702 . html_tag( 'tr' ) . "\n"
703 . html_tag( 'td' ,'' , 'left', $color[0], '' )
704 . html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="0" cellspacing="0"' )
706 getSmallStringCell(' ' . _("Move Selected To"), 'left') .
707 getSmallStringCell(_("Transform Selected Messages"), 'right')
709 . html_tag( 'tr' ) ."\n"
710 . html_tag( 'td', '', 'left', '', 'valign="middle" nowrap' );
711 getMbxList($imapConnection);
712 echo getButton('SUBMIT', 'moveButton',_("Move")) . "\n";
713 echo getButton('SUBMIT', 'attache',_("Forward")) . "\n";
716 . html_tag( 'td', '', 'right', '', 'nowrap' );
718 if (!$auto_expunge) {
719 echo getButton('SUBMIT', 'expungeButton',_("Expunge"))
720 .' ' . _("mailbox") . "\n";
723 echo getButton('SUBMIT', 'markRead',_("Read"));
724 echo getButton('SUBMIT', 'markUnread',_("Unread"));
725 echo getButton('SUBMIT', 'delete',_("Delete")) ." \n";
726 if (!strpos($php_self,'mailbox')) {
727 $location = $php_self.'?mailbox=INBOX&startMessage=1';
729 $location = $php_self;
731 echo '<INPUT TYPE="HIDDEN" NAME="location" VALUE="'.$location.'">';
735 /* draws thread sorting links */
736 if ($allow_thread_sort == TRUE) {
737 if ($thread_sort_messages == 1 ) {
739 $thread_name = _("Unthread View");
740 } elseif ($thread_sort_messages == 0) {
742 $thread_name = _("Thread View");
744 echo html_tag( 'tr' ,
746 ' <a href=' . $source_url . '?sort='
747 . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
748 . '&mailbox=' . urlencode($mailbox) . '><small>' . $thread_name
749 . '</a></small> '
757 do_hook('mailbox_form_before');
761 . html_tag( 'td' ,'' , '', $color[0], '' );
763 /* if using server sort we highjack the
764 * the $sort var and use $server_sort_order
765 * instead. but here we reset sort for a bit
768 if ($allow_server_sort == TRUE) {
769 $sort = $server_sort_order;
773 function mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color) {
775 echo html_tag( 'table',
780 html_tag( 'td', $paginator_str ) .
781 html_tag( 'td', $msg_cnt_str, 'right' )
783 , '', $color[4], 'width="100%" cellpadding="1" cellspacing="1"' )
786 , '', $color[9], 'width="100%" cellpadding="1" cellspacing="1"' );
789 /* End of message-list table */
791 do_hook('mailbox_index_after');
795 function printHeader($mailbox, $sort, $color, $showsort=true) {
797 echo html_tag( 'table' ,'' , '', $color[4], 'border="0" width="100%" cellpadding="1" cellspacing="0"' );
798 echo html_tag( 'tr' ,'' , 'center', $color[5] );
799 for ($i = 1; $i <= count($index_order); $i++
) {
800 switch ($index_order[$i]) {
801 case 1: /* checkbox */
803 echo html_tag( 'td' ,' ' , '', '', 'width="1%"' );
806 if (handleAsSent($mailbox)) {
807 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
808 . '<b>' . _("To") . '</b>';
810 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
811 . '<b>' . _("From") . '</b>';
814 ShowSortButton($sort, $mailbox, 2, 3);
819 echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
820 . '<b>' . _("Date") . '</b>';
822 ShowSortButton($sort, $mailbox, 0, 1);
826 case 4: /* subject */
827 echo html_tag( 'td' ,'' , 'left', '', '' )
828 . '<b>' . _("Subject") . '</b>';
830 ShowSortButton($sort, $mailbox, 4, 5);
835 echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%"' );
844 * This function shows the sort button. Isn't this a good comment?
846 function ShowSortButton($sort, $mailbox, $Up, $Down ) {
848 /* Figure out which image we want to use. */
849 if ($sort != $Up && $sort != $Down) {
850 $img = 'sort_none.png';
852 } elseif ($sort == $Up) {
853 $img = 'up_pointer.png';
856 $img = 'down_pointer.png';
860 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
861 $source_url = $regs[1];
863 $source_url = $PHP_SELF;
866 /* Now that we have everything figured out, show the actual button. */
867 echo ' <a href="' . $source_url .'?newsort=' . $which
868 . '&startMessage=1&mailbox=' . urlencode($mailbox)
869 . '"><IMG SRC="../images/' . $img
870 . '" BORDER=0 WIDTH=12 HEIGHT=10 ALT="sort"></a>';
873 function get_selectall_link($start_msg, $sort) {
874 global $checkall, $what, $where, $mailbox, $javascript_on;
875 global $PHP_SELF, $PG_SHOWNUM;
878 if ($javascript_on) {
879 $result = '<script language="JavaScript" type="text/javascript">'
881 . "function CheckAll() {\n"
882 . " for (var i = 0; i < document.messageList.elements.length; i++) {\n"
883 . " if(document.messageList.elements[i].type == 'checkbox'){\n"
884 . " document.messageList.elements[i].checked = "
885 . " !(document.messageList.elements[i].checked);\n"
890 . '</script><a href="#" onClick="CheckAll();">' . _("Toggle All")
893 if (strpos($PHP_SELF, "?")) {
894 $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($mailbox)
895 . "&startMessage=$start_msg&sort=$sort&checkall=";
897 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
898 . "&startMessage=$start_msg&sort=$sort&checkall=";
900 if (isset($checkall) && $checkall == '1') {
906 if (isset($where) && isset($what)) {
907 $result .= '&where=' . urlencode($where)
908 . '&what=' . urlencode($what);
912 if (isset($checkall) && ($checkall == '1')) {
913 $result .= _("Unselect All");
915 $result .= _("Select All");
920 /* Return our final result. */
925 * This function computes the "Viewing Messages..." string.
927 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
928 /* Compute the $msg_cnt_str. */
930 if ($start_msg < $end_msg) {
931 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"),
932 $start_msg, $end_msg, $num_msgs);
933 } else if ($start_msg == $end_msg) {
934 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
938 /* Return our result string. */
943 * Generate a paginator link.
945 function get_paginator_link($box, $start_msg, $use, $text) {
948 $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
949 . "&startMessage=$start_msg&mailbox=$box\" "
950 . "TARGET=\"right\">$text</A>";
953 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
954 $source_url = $regs[1];
956 $source_url = $PHP_SELF;
959 $result = '<A HREF="'. $source_url . "?use_mailbox_cache=$use"
960 . "&startMessage=$start_msg&mailbox=$box\" "
961 . "TARGET=\"right\">$text</A>";
967 * This function computes the paginator string.
969 function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
971 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
973 /* Initialize paginator string chunks. */
980 $box = urlencode($box);
982 /* Create simple strings that will be creating the paginator. */
983 $spc = ' '; /* This will be used as a space. */
984 $sep = '|'; /* This will be used as a seperator. */
986 /* Get some paginator preference values. */
987 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON
);
988 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
);
990 /* Make sure that our start message number is not too big. */
991 $start_msg = min($start_msg, $num_msgs);
993 /* Decide whether or not we will use the mailbox cache. */
994 /* Not sure why $use_mailbox_cache is even passed in. */
1001 /* Compute the starting message of the previous and next page group. */
1002 $next_grp = $start_msg +
$show_num;
1003 $prev_grp = $start_msg - $show_num;
1005 /* Compute the basic previous and next strings. */
1006 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
1007 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1008 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1009 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
1010 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1011 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
1012 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
1013 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
1014 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1017 /* Page selector block. Following code computes page links. */
1018 if ($pg_sel && ($num_msgs > $show_num)) {
1019 /* Most importantly, what is the current page!!! */
1020 $cur_pg = intval($start_msg / $show_num) +
1;
1022 /* Compute total # of pages and # of paginator page links. */
1023 $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
1024 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
1026 /* Compute the size of the four quarters of the page links. */
1028 /* If we can, just show all the pages. */
1029 if (($tot_pgs - 1) <= $pg_max) {
1030 $q1_pgs = $cur_pg - 1;
1031 $q2_pgs = $q3_pgs = 0;
1032 $q4_pgs = $tot_pgs - $cur_pg;
1034 /* Otherwise, compute some magic to choose the four quarters. */
1037 * Compute the magic base values. Added together,
1038 * these values will always equal to the $pag_pgs.
1039 * NOTE: These are DEFAULT values and do not take
1040 * the current page into account. That is below.
1042 $q1_pgs = floor($vis_pgs/4);
1043 $q2_pgs = round($vis_pgs/4, 0);
1044 $q3_pgs = ceil($vis_pgs/4);
1045 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
1047 /* Adjust if the first quarter contains the current page. */
1048 if (($cur_pg - $q1_pgs) < 1) {
1049 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) +
$q2_pgs;
1050 $q1_pgs = $cur_pg - 1;
1052 $q3_pgs +
= ceil($extra_pgs / 2);
1053 $q4_pgs +
= floor($extra_pgs / 2);
1055 /* Adjust if the first and second quarters intersect. */
1056 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
1057 $extra_pgs = $q2_pgs;
1058 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1059 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1060 $q3_pgs +
= ceil($extra_pgs / 2);
1061 $q4_pgs +
= floor($extra_pgs / 2);
1063 /* Adjust if the fourth quarter contains the current page. */
1064 } else if (($cur_pg +
$q4_pgs) >= $tot_pgs) {
1065 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) +
$q3_pgs;
1067 $q4_pgs = $tot_pgs - $cur_pg;
1068 $q1_pgs +
= floor($extra_pgs / 2);
1069 $q2_pgs +
= ceil($extra_pgs / 2);
1071 /* Adjust if the third and fourth quarter intersect. */
1072 } else if (($cur_pg +
$q3_pgs +
1) >= ($tot_pgs - $q4_pgs +
1)) {
1073 $extra_pgs = $q3_pgs;
1074 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1075 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1076 $q1_pgs +
= floor($extra_pgs / 2);
1077 $q2_pgs +
= ceil($extra_pgs / 2);
1082 * I am leaving this debug code here, commented out, because
1083 * it is a really nice way to see what the above code is doing.
1084 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
1085 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
1088 /* Print out the page links from the compute page quarters. */
1090 /* Start with the first quarter. */
1091 if (($q1_pgs == 0) && ($cur_pg > 1)) {
1092 $pg_str .= "...$spc";
1094 for ($pg = 1; $pg <= $q1_pgs; ++
$pg) {
1095 $start = (($pg-1) * $show_num) +
1;
1096 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1098 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
1099 $pg_str .= "...$spc";
1103 /* Continue with the second quarter. */
1104 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++
$pg) {
1105 $start = (($pg-1) * $show_num) +
1;
1106 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1109 /* Now print the current page. */
1110 $pg_str .= $cur_pg . $spc;
1112 /* Next comes the third quarter. */
1113 for ($pg = $cur_pg +
1; $pg <= $cur_pg +
$q3_pgs; ++
$pg) {
1114 $start = (($pg-1) * $show_num) +
1;
1115 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1118 /* And last, print the forth quarter page links. */
1119 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
1120 $pg_str .= "...$spc";
1122 if (($tot_pgs - $q4_pgs) > ($cur_pg +
$q3_pgs)) {
1123 $pg_str .= "...$spc";
1125 for ($pg = $tot_pgs - $q4_pgs +
1; $pg <= $tot_pgs; ++
$pg) {
1126 $start = (($pg-1) * $show_num) +
1;
1127 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1130 } else if ($PG_SHOWNUM == 999999) {
1131 $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
1132 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1133 . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc;
1136 /* If necessary, compute the 'show all' string. */
1137 if (($prv_str != '') ||
($nxt_str != '')) {
1138 $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
1139 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1140 . "TARGET=\"right\">" . _("Show All") . '</A>';
1143 /* Last but not least, get the value for the toggle all link. */
1144 $tgl_str = get_selectall_link($start_msg, $sort);
1146 /* Put all the pieces of the paginator string together. */
1148 * Hairy code... But let's leave it like it is since I am not certain
1149 * a different approach would be any easier to read. ;)
1152 $result .= ($prv_str != '' ?
$prv_str . $spc . $sep . $spc : '');
1153 $result .= ($nxt_str != '' ?
$nxt_str . $spc . $sep . $spc : '');
1154 $result .= ($pg_str != '' ?
$pg_str : '');
1155 $result .= ($all_str != '' ?
$sep . $spc . $all_str . $spc : '');
1156 $result .= ($result != '' ?
$sep . $spc . $tgl_str: $tgl_str);
1158 /* If the resulting string is blank, return a non-breaking space. */
1159 if ($result == '') {
1163 /* Return our final magical paginator string. */
1167 function processSubject($subject) {
1168 global $languages, $squirrelmail_language;
1169 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1171 return _("(no subject)");
1173 if (strlen($subject) <= 55)
1176 $ent_strlen = strlen($subject);
1180 * see if this is entities-encoded string
1181 * If so, Iterate through the whole string, find out
1182 * the real number of characters, and if more
1183 * than 55, substr with an updated trim value.
1185 while ( (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1186 (($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false) ) {
1187 $trim_val +
= ($ent_loc_end-$ent_loc)+
1;
1188 $ent_strlen -= $ent_loc_end-$ent_loc;
1189 $ent_offset = $ent_loc_end+
1;
1192 if ($ent_strlen <= 55){
1196 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
1197 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
1198 return $languages[$squirrelmail_language]['XTRA_CODE']('strimwidth', $subject, $trim_val);
1201 return substr($subject, 0, $trim_val) . '...';
1204 function getMbxList($imapConnection) {
1205 global $lastTargetMailbox;
1206 echo ' <small> <tt><select name="targetMailbox">';
1207 $boxes = sqimap_mailbox_list($imapConnection);
1208 foreach ($boxes as $boxes_part) {
1209 if (!in_array('noselect', $boxes_part['flags'])) {
1210 $box = $boxes_part['unformatted'];
1211 $box2 = str_replace(' ', ' ', imap_utf7_decode_local($boxes_part['unformatted-disp']));
1212 if($box2 == 'INBOX') {
1215 if ($lastTargetMailbox == $box) {
1216 echo " <OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
1218 echo " <OPTION VALUE=\"$box\">$box2</OPTION>\n";
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);