6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This contains functions that display mailbox information, such as the
10 * table row that has sender, date, subject, etc...
15 require_once(SM_PATH
. 'functions/strings.php');
16 require_once(SM_PATH
. 'functions/html.php');
17 require_once(SM_PATH
. 'class/html.class.php');
18 require_once(SM_PATH
. 'functions/imap_mailbox.php');
20 /* Default value for page_selector_max. */
21 define('PG_SEL_MAX', 10);
23 function elapsed($start)
26 list($start2, $start1) = explode(" ", $start);
27 list($end2, $end1) = explode(" ", $end);
28 $diff1 = $end1 - $start1;
29 $diff2 = $end2 - $start2;
34 return $diff2 +
$diff1;
37 function printMessageInfo($imapConnection, $t, $not_last=true, $key, $mailbox,
38 $start_msg, $where, $what) {
40 $color, $msgs, $msort, $td_str, $msg,
41 $default_use_priority,
42 $message_highlight_list,
44 $indent_array, /* indent subject by */
45 $pos, /* Search postion (if any) */
46 $thread_sort_messages, /* thread sorting on/off */
47 $server_sort_order, /* sort value when using server-sorting */
49 $allow_server_sort; /* enable/disable server-side sorting */
50 $color_string = $color[4];
52 if ($GLOBALS['alt_index_colors']) {
53 if (!isset($row_count)) {
58 if (!isset($color[12])) {
59 $color[12] = '#EAEAEA';
61 $color_string = $color[12];
66 if($mailbox == 'None') {
67 $boxes = sqimap_mailbox_list($imapConnection);
68 $mailbox = $boxes[0]['unformatted'];
71 $urlMailbox = urlencode($mailbox);
73 if (handleAsSent($mailbox)) {
74 $msg['FROM'] = $msg['TO'];
77 * This is done in case you're looking into Sent folders,
78 * because you can have multiple receivers.
81 $senderNames = $msg['FROM'];
83 if (sizeof($senderNames)){
84 foreach ($senderNames as $senderNames_part) {
85 if ($senderName != '') {
88 if ($senderNames_part[1]) {
89 $senderName .= decodeHeader($senderNames_part[1]);
91 $senderName .= htmlspecialchars($senderNames_part[0]);
96 $subject_full = decodeHeader($msg['SUBJECT']);
97 $subject = processSubject($subject_full, $indent_array[$msg['ID']]);
99 echo html_tag( 'tr','','','','VALIGN="top"') . "\n";
101 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
102 $flag = "<font color=\"$color[2]\">";
103 $flag_end = '</font>';
108 if (!isset($msg['FLAG_SEEN']) ||
($msg['FLAG_SEEN'] == false)) {
115 if (handleAsSent($mailbox)) {
117 $italic_end = '</i>';
122 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
123 $fontstr = "<font color=\"$color[9]\">";
124 $fontstr_end = '</font>';
130 if ($where && $what) {
131 $searchstr = '&where='.$where.'&what='.$what;
136 * AAAAH! Make my eyes stop bleeding!
139 if (is_array($message_highlight_list) && count($message_highlight_list)){
140 foreach ($message_highlight_list as $message_highlight_list_part) {
141 if (trim($message_highlight_list_part['value']) != '') {
142 $high_val = strtolower($message_highlight_list_part['value']);
143 $match_type = strtoupper($message_highlight_list_part['match_type']);
144 if ($match_type == 'TO_CC') {
145 foreach ($msg['TO'] as $address) {
146 if (strstr('^^' . strtolower($address[0]), $high_val) ||
147 strstr('^^' . strtolower($address[1]), $high_val)) {
148 $hlt_color = $message_highlight_list_part['color'];
152 foreach ($msg['CC'] as $address) {
153 if( strstr('^^' . strtolower($address[0]), $high_val) ||
154 strstr('^^' . strtolower($address[1]), $high_val)) {
155 $hlt_color = $message_highlight_list_part['color'];
160 if (strstr('^^' . strtolower($msg[$match_type]), $high_val)) {
161 $hlt_color = $message_highlight_list_part['color'];
169 if (!isset($hlt_color)) {
170 $hlt_color = $color_string;
172 $checked = ($checkall == 1) ?
' CHECKED' : '';
174 if (sizeof($index_order)) {
175 foreach ($index_order as $index_order_part) {
176 switch ($index_order_part) {
177 case 1: /* checkbox */
179 "<input type=checkbox name=\"msg[$t]\" value=\"".$msg['ID']."\"$checked>",
185 $italic . $bold . $flag . $fontstr . $senderName .
186 $fontstr_end . $flag_end . $bold_end . $italic_end,
191 $date_string = $msg['DATE_STRING'] . '';
192 if ($date_string == '') {
193 $date_string = _("Unknown date");
196 $bold . $flag . $fontstr . $date_string .
197 $fontstr_end . $flag_end . $bold_end,
202 case 4: /* subject */
204 if ($thread_sort_messages == 1) {
205 if (isset($indent_array[$msg['ID']])) {
206 $td_str .= str_repeat(" ",$indent_array[$msg['ID']]);
209 $td_str .= '<a href="read_body.php?mailbox='.$urlMailbox
210 . '&passed_id='. $msg["ID"]
211 . '&startMessage='.$start_msg.$searchstr.'"';
212 do_hook("subject_link");
213 if ($subject != $subject_full) {
214 $title = get_html_translation_table(HTML_SPECIALCHARS
);
215 $title = array_flip($title);
216 $title = strtr($subject_full, $title);
217 $title = str_replace('"', "''", $title);
218 $td_str .= " title=\"$title\"";
220 $td_str .= ">$flag$subject$flag_end</a>$bold_end";
221 echo html_tag( 'td', $td_str, 'left', $hlt_color );
225 $td_str = "<b><small>";
227 if (isset($msg['FLAG_ANSWERED']) && $msg['FLAG_ANSWERED'] == true) {
231 if ($msg['TYPE0'] == 'multipart') {
235 if ($default_use_priority) {
236 if ( ($msg['PRIORITY'] == 1) ||
($msg['PRIORITY'] == 2) ) {
237 $td_str .= "<font color=\"$color[1]\">!</font>";
240 if ($msg['PRIORITY'] == 5) {
241 $td_str .= "<font color=\"$color[8]\">?</font>";
245 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'] == true) {
246 $td_str .= "<font color=\"$color[1]\">D</font>";
252 do_hook("msg_envelope");
253 $td_str .= '</small></b>';
262 $bold . $fontstr . show_readable_size($msg['SIZE']) .
263 $fontstr_end . $bold_end,
272 echo '</tr>' . "\n" . '<tr><td COLSPAN="' . $col . '" BGCOLOR="' .
273 $color[0] . '" HEIGHT="1"></td></tr>' . "\n";
279 function getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id) {
281 $id = array_slice($id, ($start_msg-1), $show_num);
282 $end = $start_msg +
$show_num - 1;
283 if ($num_msgs < $show_num) {
284 $end_loop = $num_msgs;
285 } else if ($end > $num_msgs) {
286 $end_loop = $num_msgs - $start_msg +
1;
288 $end_loop = $show_num;
290 return fillMessageArray($imapConnection,$id,$end_loop);
296 function getThreadMessages($imapConnection, $start_msg, $show_num, $num_msgs) {
297 $id = get_thread_sort($imapConnection);
298 return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
301 function getServerSortMessages($imapConnection, $start_msg, $show_num,
302 $num_msgs, $server_sort_order, $mbxresponse) {
303 $id = sqimap_get_sort_order($imapConnection, $server_sort_order,$mbxresponse);
304 return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
307 function getSelfSortMessages($imapConnection, $start_msg, $show_num,
308 $num_msgs, $sort, $mbxresponse) {
310 if ($num_msgs >= 1) {
311 $id = sqimap_get_php_sort_order ($imapConnection, $mbxresponse);
316 /* if it's not sorted */
317 if ($start_msg +
($show_num - 1) < $num_msgs) {
318 $end_msg = $start_msg +
($show_num - 1);
320 $end_msg = $num_msgs;
322 if ($end_msg < $start_msg) {
323 $start_msg = $start_msg - $show_num;
324 if ($start_msg < 1) {
328 $id = array_slice(array_reverse($id), ($start_msg-1), $show_num);
329 $end = $start_msg +
$show_num - 1;
330 if ($num_msgs < $show_num) {
331 $end_loop = $num_msgs;
332 } else if ($end > $num_msgs) {
333 $end_loop = $num_msgs - $start_msg +
1;
335 $end_loop = $show_num;
338 $msgs = fillMessageArray($imapConnection,$id,$end_loop);
346 * This function loops through a group of messages in the mailbox
347 * and shows them to the user.
349 function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
350 $start_msg, $sort, $color, $show_num,
351 $use_cache, $mode='') {
352 global $msgs, $msort, $auto_expunge, $thread_sort_messages,
353 $allow_server_sort, $server_sort_order;
356 * For some reason, on PHP 4.3+, this being unset, and set in the session causes havoc
357 * so setting it to an empty array beforehand seems to clean up the issue, and stopping the
358 * "Your script possibly relies on a session side-effect which existed until PHP 4.2.3" error
361 if (!isset($msort)) {
365 $start = microtime();
366 /* If autoexpunge is turned on, then do it now. */
367 $mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox);
369 /* If autoexpunge is turned on, then do it now. */
370 if ($auto_expunge == true) {
371 $exp_cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, false, '');
372 $mbxresponse['EXISTS'] = $mbxresponse['EXISTS'] - $exp_cnt;
373 $num_msgs = $mbxresponse['EXISTS'];
376 if ($mbxresponse['EXISTS'] > 0) {
377 /* if $start_msg is lower than $num_msgs, we probably deleted all messages
378 * in the last page. We need to re-adjust the start_msg
381 if($start_msg > $num_msgs) {
382 $start_msg -= $show_num;
388 /* This code and the next if() block check for
389 * server-side sorting methods. The $id array is
390 * formatted and $sort is set to 6 to disable
391 * SM internal sorting
394 if ($thread_sort_messages == 1) {
396 } elseif ($allow_server_sort == 1) {
397 $mode = 'serversort';
402 sqsession_unregister('msort');
403 sqsession_unregister('msgs');
406 $id = get_thread_sort($imapConnection);
407 $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
408 if ($msgs === false) {
409 echo '<b><small><center><font color=red>' .
410 _("Thread sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
411 '</center></small></b>';
412 $thread_sort_messages = 0;
413 $msort = $msgs = array();
420 $id = sqimap_get_sort_order($imapConnection, $sort, $mbxresponse);
421 $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
422 if ($msgs === false) {
423 echo '<b><small><center><font color=red>' .
424 _( "Server-side sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
425 '</center></small></b>';
426 $sort = $server_sort_order;
427 $allow_server_sort = FALSE;
428 $msort = $msgs = array();
437 $msgs = getSelfSortMessages($imapConnection, $start_msg, $show_num,
438 $num_msgs, $sort, $mbxresponse);
439 $msort = calc_msort($msgs, $sort);
443 sqsession_register($msort, 'msort');
444 sqsession_register($msgs, 'msgs');
445 } /* if exists > 0 */
447 $res = getEndMessage($start_msg, $show_num, $num_msgs);
448 $start_msg = $res[0];
451 $paginator_str = get_paginator_str($mailbox, $start_msg, $end_msg,
452 $num_msgs, $show_num, $sort);
454 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
456 do_hook('mailbox_index_before');
457 echo '<table border="0" width="100%" cellpadding="0" cellspacing="0">';
460 mail_message_listing_beginning($imapConnection, $mailbox, $sort,
461 $msg_cnt_str, $paginator_str, $start_msg);
463 /* line between the button area and the list */
464 echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>';
467 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
469 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[5].'">';
471 printHeader($mailbox, $srt, $color, !$thread_sort_messages);
473 displayMessageArray($imapConnection, $num_msgs, $start_msg,
474 $msort, $mailbox, $sort, $color, $show_num,0,0);
475 echo '</td></tr></table></td></tr></table>';
477 mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color);
478 echo '</td></tr></table>';
479 $t = elapsed($start);
480 //echo("elapsed time = $t seconds\n");
483 function calc_msort($msgs, $sort) {
494 if (($sort == 0) ||
($sort == 1)) {
495 foreach ($msgs as $item) {
496 $msort[] = $item['TIME_STAMP'];
498 } elseif (($sort == 2) ||
($sort == 3)) {
499 foreach ($msgs as $item) {
500 $msort[] = $item['FROM-SORT'];
502 } elseif (($sort == 4) ||
($sort == 5)) {
503 foreach ($msgs as $item) {
504 $msort[] = $item['SUBJECT-SORT'];
519 function fillMessageArray($imapConnection, $id, $count) {
520 return sqimap_get_small_header_list($imapConnection, $id);
524 /* Generic function to convert the msgs array into an HTML table. */
525 function displayMessageArray($imapConnection, $num_msgs, $start_msg,
526 $msort, $mailbox, $sort, $color,
527 $show_num, $where=0, $what=0) {
528 global $imapServerAddress, $use_mailbox_cache, $index_order,
529 $indent_array, $thread_sort_messages, $allow_server_sort,
530 $server_sort_order, $PHP_SELF;
532 $res = getEndMessage($start_msg, $show_num, $num_msgs);
533 $start_msg = $res[0];
536 $urlMailbox = urlencode($mailbox);
538 /* get indent level for subject display */
539 if ($thread_sort_messages == 1 && $num_msgs) {
540 $indent_array = get_parent_level($imapConnection);
543 $real_startMessage = $start_msg;
545 if ($end_msg - $start_msg < $show_num - 1) {
546 $end_msg = $end_msg - $start_msg +
1;
548 } else if ($start_msg > $show_num) {
549 $end_msg = $show_num;
553 $endVar = $end_msg +
1;
556 * Loop through and display the info for each message.
557 * ($t is used for the checkbox number)
561 /* messages display */
564 /* if there's no messages in this folder */
567 "<BR><b>" . _("THIS FOLDER IS EMPTY") . "</b><BR> ",
570 'COLSPAN="' . count($index_order) . '"'
573 } elseif ($start_msg == $end_msg) {
574 /* if there's only one message in the box, handle it differently. */
586 } while (isset ($key) && ($k < $i));
587 printMessageInfo($imapConnection, $t, true, $key, $mailbox,
588 $real_startMessage, $where, $what);
597 } while (isset ($key) && ($k < $i));
600 if (!$i ||
$i == $endVar-1) $not_last = false;
601 printMessageInfo($imapConnection, $t, $not_last, $key, $mailbox,
602 $real_startMessage, $where, $what);
607 } while ($i && $i < $endVar);
612 * Displays the standard message list header. To finish the table,
613 * you need to do a "</table></table>";
615 * $moveURL is the URL to submit the delete/move form to
616 * $mailbox is the current mailbox
617 * $sort is the current sorting method (-1 for no sorting available [searches])
618 * $Message is a message that is centered on top of the list
619 * $More is a second line that is left aligned
622 function mail_message_listing_beginning ($imapConnection,
623 $mailbox = '', $sort = -1,
625 $paginator = ' ',
627 global $color, $auto_expunge, $base_uri, $thread_sort_messages,
628 $allow_thread_sort, $allow_server_sort, $server_sort_order,
631 $php_self = $PHP_SELF;
632 /* fix for incorrect $PHP_SELF */
633 if (strpos($php_self, 'move_messages.php')) {
634 $php_self = str_replace('move_messages.php', 'right_main.php', $php_self);
636 $urlMailbox = urlencode($mailbox);
638 if (preg_match('/^(.+)\?.+$/',$php_self,$regs)) {
639 $source_url = $regs[1];
641 $source_url = $php_self;
647 $moveFields = '<input type="hidden" name="msg" value="'.htmlspecialchars($msg).'">' .
648 '<input type="hidden" name="mailbox" value="'.htmlspecialchars($mailbox).'">' .
649 '<input type="hidden" name="startMessage" value="'.htmlspecialchars($start_msg).'">';
651 // $moveURL = "move_messages.php?msg=$msg&mailbox=$urlMailbox"
652 // . "&startMessage=$start_msg";
654 * This is the beginning of the message list table.
655 * It wraps around all messages
657 echo '<form name="messageList" method="post" action="move_messages.php">' ."\n"
659 . html_tag( 'table' ,
664 html_tag( 'td', $paginator, 'left' ) .
665 html_tag( 'td', $msg_cnt_str, 'right' )
667 , '', $color[4], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
670 , '', '', 'border="0" width="100%" cellpadding="1" cellspacing="0"' );
671 /* line between header and button area */
672 echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>';
675 echo html_tag( 'tr' ) . "\n"
676 . html_tag( 'td' ,'' , 'left', '', '' )
677 . html_tag( 'table' ,'' , '', $color[9], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
679 . html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
681 getSmallStringCell(_("Move Selected To"), 'left', 'nowrap') .
682 getSmallStringCell(_("Transform Selected Messages"), 'right')
684 . html_tag( 'tr' ) ."\n"
685 . html_tag( 'td', '', 'left', '', 'valign="middle" nowrap' );
686 getMbxList($imapConnection);
687 echo getButton('SUBMIT', 'moveButton',_("Move")) . "\n";
688 echo getButton('SUBMIT', 'attache',_("Forward")) . "\n";
691 . html_tag( 'td', '', 'right', '', 'nowrap' );
695 if (!$auto_expunge) {
696 echo getButton('SUBMIT', 'expungeButton',_("Expunge"))
697 .' ' . _("mailbox") . "\n";
700 echo getButton('SUBMIT', 'markRead',_("Read"));
701 echo getButton('SUBMIT', 'markUnread',_("Unread"));
702 echo getButton('SUBMIT', 'delete',_("Delete")) ." \n";
703 if (!strpos($php_self,'mailbox')) {
704 $location = $php_self.'?mailbox=INBOX&startMessage=1';
706 $location = $php_self;
708 echo '<INPUT TYPE="HIDDEN" NAME="location" VALUE="'.$location.'">';
712 /* draws thread sorting links */
713 if ($allow_thread_sort == TRUE) {
714 if ($thread_sort_messages == 1 ) {
716 $thread_name = _("Unthread View");
717 } elseif ($thread_sort_messages == 0) {
719 $thread_name = _("Thread View");
721 echo html_tag( 'tr' ,
723 ' <a href=' . $source_url . '?sort='
724 . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
725 . '&mailbox=' . urlencode($mailbox) . '><small>' . $thread_name
726 . '</a></small> '
731 echo "</TABLE></td></tr></table></td></tr>\n";
733 do_hook('mailbox_form_before');
735 /* if using server sort we highjack the
736 * the $sort var and use $server_sort_order
737 * instead. but here we reset sort for a bit
740 if ($allow_server_sort == TRUE) {
741 $sort = $server_sort_order;
745 function mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color) {
747 /* space between list and footer */
748 echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'" COLSPAN="1">';
750 echo '</td></tr><tr><td>';
751 echo html_tag( 'table',
756 html_tag( 'td', $paginator_str ) .
757 html_tag( 'td', $msg_cnt_str, 'right' )
759 , '', $color[4], 'width="100%" border="0" cellpadding="1" cellspacing="0"' )
762 , '', $color[9], 'width="100%" border="0" cellpadding="1" cellspacing="0"' );
765 /* End of message-list table */
767 do_hook('mailbox_index_after');
771 function printHeader($mailbox, $sort, $color, $showsort=true) {
773 echo html_tag( 'tr' ,'' , 'center', $color[5] );
775 /* calculate the width of the subject column based on the
776 * widths of the other columns */
777 $widths = array(1=>1,2=>25,3=>5,4=>0,5=>1,6=>5);
779 foreach($index_order as $item) {
780 $subjectwidth -= $widths[$item];
783 foreach ($index_order as $item) {
785 case 1: /* checkbox */
787 echo html_tag( 'td' ,' ' , '', '', 'width="1%"' );
790 if (handleAsSent($mailbox)) {
791 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
792 . '<b>' . _("To") . '</b>';
794 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
795 . '<b>' . _("From") . '</b>';
798 ShowSortButton($sort, $mailbox, 2, 3);
803 echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
804 . '<b>' . _("Date") . '</b>';
806 ShowSortButton($sort, $mailbox, 0, 1);
810 case 4: /* subject */
811 echo html_tag( 'td' ,'' , 'left', '', 'width="'.$subjectwidth.'%"' )
812 . '<b>' . _("Subject") . '</b>';
814 ShowSortButton($sort, $mailbox, 4, 5);
819 echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%"' );
828 * This function shows the sort button. Isn't this a good comment?
830 function ShowSortButton($sort, $mailbox, $Up, $Down ) {
832 /* Figure out which image we want to use. */
833 if ($sort != $Up && $sort != $Down) {
834 $img = 'sort_none.png';
836 } elseif ($sort == $Up) {
837 $img = 'up_pointer.png';
840 $img = 'down_pointer.png';
844 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
845 $source_url = $regs[1];
847 $source_url = $PHP_SELF;
850 /* Now that we have everything figured out, show the actual button. */
851 echo ' <a href="' . $source_url .'?newsort=' . $which
852 . '&startMessage=1&mailbox=' . urlencode($mailbox)
853 . '"><IMG SRC="../images/' . $img
854 . '" BORDER=0 WIDTH=12 HEIGHT=10 ALT="sort"></a>';
857 function get_selectall_link($start_msg, $sort) {
858 global $checkall, $what, $where, $mailbox, $javascript_on;
859 global $PHP_SELF, $PG_SHOWNUM;
862 if ($javascript_on) {
863 $result = '<script language="JavaScript" type="text/javascript">'
865 . "function CheckAll() {\n"
866 . " for (var i = 0; i < document.messageList.elements.length; i++) {\n"
867 . " if(document.messageList.elements[i].type == 'checkbox'){\n"
868 . " document.messageList.elements[i].checked = "
869 . " !(document.messageList.elements[i].checked);\n"
874 . '</script><a href="#" onClick="CheckAll();">' . _("Toggle All")
877 if (strpos($PHP_SELF, "?")) {
878 $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($mailbox)
879 . "&startMessage=$start_msg&sort=$sort&checkall=";
881 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
882 . "&startMessage=$start_msg&sort=$sort&checkall=";
884 if (isset($checkall) && $checkall == '1') {
890 if (isset($where) && isset($what)) {
891 $result .= '&where=' . urlencode($where)
892 . '&what=' . urlencode($what);
896 if (isset($checkall) && ($checkall == '1')) {
897 $result .= _("Unselect All");
899 $result .= _("Select All");
904 /* Return our final result. */
909 * This function computes the "Viewing Messages..." string.
911 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
912 /* Compute the $msg_cnt_str. */
914 if ($start_msg < $end_msg) {
915 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"),
916 $start_msg, $end_msg, $num_msgs);
917 } else if ($start_msg == $end_msg) {
918 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
922 /* Return our result string. */
927 * Generate a paginator link.
929 function get_paginator_link($box, $start_msg, $use, $text) {
932 $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
933 . "&startMessage=$start_msg&mailbox=$box\" "
934 . "TARGET=\"right\">$text</A>";
937 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
938 $source_url = $regs[1];
940 $source_url = $PHP_SELF;
943 $result = '<A HREF="'. $source_url . "?use_mailbox_cache=$use"
944 . "&startMessage=$start_msg&mailbox=$box\" "
945 . "TARGET=\"right\">$text</A>";
951 * This function computes the paginator string.
953 function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
955 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
957 /* Initialize paginator string chunks. */
964 $box = urlencode($box);
966 /* Create simple strings that will be creating the paginator. */
967 $spc = ' '; /* This will be used as a space. */
968 $sep = '|'; /* This will be used as a seperator. */
970 /* Get some paginator preference values. */
971 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON
);
972 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
);
974 /* Make sure that our start message number is not too big. */
975 $start_msg = min($start_msg, $num_msgs);
977 /* Decide whether or not we will use the mailbox cache. */
978 /* Not sure why $use_mailbox_cache is even passed in. */
985 /* Compute the starting message of the previous and next page group. */
986 $next_grp = $start_msg +
$show_num;
987 $prev_grp = $start_msg - $show_num;
989 /* Compute the basic previous and next strings. */
990 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
991 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
992 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
993 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
994 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
995 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
996 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
997 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
998 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1001 /* Page selector block. Following code computes page links. */
1002 if ($pg_sel && ($num_msgs > $show_num)) {
1003 /* Most importantly, what is the current page!!! */
1004 $cur_pg = intval($start_msg / $show_num) +
1;
1006 /* Compute total # of pages and # of paginator page links. */
1007 $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
1008 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
1010 /* Compute the size of the four quarters of the page links. */
1012 /* If we can, just show all the pages. */
1013 if (($tot_pgs - 1) <= $pg_max) {
1014 $q1_pgs = $cur_pg - 1;
1015 $q2_pgs = $q3_pgs = 0;
1016 $q4_pgs = $tot_pgs - $cur_pg;
1018 /* Otherwise, compute some magic to choose the four quarters. */
1021 * Compute the magic base values. Added together,
1022 * these values will always equal to the $pag_pgs.
1023 * NOTE: These are DEFAULT values and do not take
1024 * the current page into account. That is below.
1026 $q1_pgs = floor($vis_pgs/4);
1027 $q2_pgs = round($vis_pgs/4, 0);
1028 $q3_pgs = ceil($vis_pgs/4);
1029 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
1031 /* Adjust if the first quarter contains the current page. */
1032 if (($cur_pg - $q1_pgs) < 1) {
1033 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) +
$q2_pgs;
1034 $q1_pgs = $cur_pg - 1;
1036 $q3_pgs +
= ceil($extra_pgs / 2);
1037 $q4_pgs +
= floor($extra_pgs / 2);
1039 /* Adjust if the first and second quarters intersect. */
1040 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
1041 $extra_pgs = $q2_pgs;
1042 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1043 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1044 $q3_pgs +
= ceil($extra_pgs / 2);
1045 $q4_pgs +
= floor($extra_pgs / 2);
1047 /* Adjust if the fourth quarter contains the current page. */
1048 } else if (($cur_pg +
$q4_pgs) >= $tot_pgs) {
1049 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) +
$q3_pgs;
1051 $q4_pgs = $tot_pgs - $cur_pg;
1052 $q1_pgs +
= floor($extra_pgs / 2);
1053 $q2_pgs +
= ceil($extra_pgs / 2);
1055 /* Adjust if the third and fourth quarter intersect. */
1056 } else if (($cur_pg +
$q3_pgs +
1) >= ($tot_pgs - $q4_pgs +
1)) {
1057 $extra_pgs = $q3_pgs;
1058 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1059 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1060 $q1_pgs +
= floor($extra_pgs / 2);
1061 $q2_pgs +
= ceil($extra_pgs / 2);
1066 * I am leaving this debug code here, commented out, because
1067 * it is a really nice way to see what the above code is doing.
1068 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
1069 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
1072 /* Print out the page links from the compute page quarters. */
1074 /* Start with the first quarter. */
1075 if (($q1_pgs == 0) && ($cur_pg > 1)) {
1076 $pg_str .= "...$spc";
1078 for ($pg = 1; $pg <= $q1_pgs; ++
$pg) {
1079 $start = (($pg-1) * $show_num) +
1;
1080 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1082 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
1083 $pg_str .= "...$spc";
1087 /* Continue with the second quarter. */
1088 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++
$pg) {
1089 $start = (($pg-1) * $show_num) +
1;
1090 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1093 /* Now print the current page. */
1094 $pg_str .= $cur_pg . $spc;
1096 /* Next comes the third quarter. */
1097 for ($pg = $cur_pg +
1; $pg <= $cur_pg +
$q3_pgs; ++
$pg) {
1098 $start = (($pg-1) * $show_num) +
1;
1099 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1102 /* And last, print the forth quarter page links. */
1103 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
1104 $pg_str .= "...$spc";
1106 if (($tot_pgs - $q4_pgs) > ($cur_pg +
$q3_pgs)) {
1107 $pg_str .= "...$spc";
1109 for ($pg = $tot_pgs - $q4_pgs +
1; $pg <= $tot_pgs; ++
$pg) {
1110 $start = (($pg-1) * $show_num) +
1;
1111 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1114 } else if ($PG_SHOWNUM == 999999) {
1115 $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
1116 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1117 . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc;
1120 /* If necessary, compute the 'show all' string. */
1121 if (($prv_str != '') ||
($nxt_str != '')) {
1122 $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
1123 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1124 . "TARGET=\"right\">" . _("Show All") . '</A>';
1127 /* Last but not least, get the value for the toggle all link. */
1128 $tgl_str = get_selectall_link($start_msg, $sort);
1130 /* Put all the pieces of the paginator string together. */
1132 * Hairy code... But let's leave it like it is since I am not certain
1133 * a different approach would be any easier to read. ;)
1136 $result .= ($prv_str != '' ?
$prv_str . $spc . $sep . $spc : '');
1137 $result .= ($nxt_str != '' ?
$nxt_str . $spc . $sep . $spc : '');
1138 $result .= ($pg_str != '' ?
$pg_str : '');
1139 $result .= ($all_str != '' ?
$sep . $spc . $all_str . $spc : '');
1140 $result .= ($result != '' ?
$sep . $spc . $tgl_str: $tgl_str);
1142 /* If the resulting string is blank, return a non-breaking space. */
1143 if ($result == '') {
1147 /* Return our final magical paginator string. */
1151 function processSubject($subject, $threadlevel = 0) {
1152 global $languages, $squirrelmail_language;
1153 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1155 return _("(no subject)");
1159 /* if this is threaded, subtract two chars per indentlevel */
1160 if($threadlevel > 0 && $threadlevel <= 10)
1161 $trim_at -= (2*$threadlevel);
1163 if (strlen($subject) <= $trim_at)
1166 $ent_strlen = $orig_len = strlen($subject);
1167 $trim_val = $trim_at - 5;
1170 * see if this is entities-encoded string
1171 * If so, Iterate through the whole string, find out
1172 * the real number of characters, and if more
1173 * than 55, substr with an updated trim value.
1175 $step = $ent_loc = 0;
1176 while ( $ent_loc < $trim_val && (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1177 (($ent_loc_end = strpos($subject, ';', $ent_loc+
3)) !== false) ) {
1178 $trim_val +
= ($ent_loc_end-$ent_loc);
1179 $ent_offset = $ent_loc_end+
1;
1183 if (($trim_val > 50) && (strlen($subject) > ($trim_val))&& (strpos($subject,';',$trim_val) < ($trim_val +
6))) {
1184 $i = strpos($subject,';',$trim_val);
1186 $trim_val = strpos($subject,';',$trim_val);
1189 if ($ent_strlen <= $trim_at){
1193 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
1194 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
1195 return $languages[$squirrelmail_language]['XTRA_CODE']('strimwidth', $subject, $trim_val);
1197 return substr($subject, 0, $trim_val) . '...';
1200 function getMbxList($imapConnection) {
1201 global $lastTargetMailbox;
1202 echo ' <small> <tt><select name="targetMailbox">';
1203 echo sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)) );
1204 echo ' </SELECT></TT> ';
1207 function getButton($type, $name, $value) {
1208 return '<INPUT TYPE="'.$type.'" NAME="'.$name.'" VALUE="'.$value . '">';
1211 function getSmallStringCell($string, $align) {
1212 return html_tag('td',
1213 '<small>' . $string . ': </small>',
1219 function getEndMessage($start_msg, $show_num, $num_msgs) {
1220 if ($start_msg +
($show_num - 1) < $num_msgs){
1221 $end_msg = $start_msg +
($show_num - 1);
1223 $end_msg = $num_msgs;
1226 if ($end_msg < $start_msg) {
1227 $start_msg = $start_msg - $show_num;
1228 if ($start_msg < 1) {
1232 return (array($start_msg,$end_msg));
1235 function handleAsSent($mailbox) {
1236 global $handleAsSent_result;
1238 /* First check if this is the sent or draft folder. */
1239 $handleAsSent_result = isSentMailbox($mailbox) ||
isDraftMailbox($mailbox);
1241 /* Then check the result of the handleAsSent hook. */
1242 do_hook('check_handleAsSent_result', $mailbox);
1244 /* And return the result. */
1245 return $handleAsSent_result;