6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This contains functions that display mailbox information, such as the
10 * table row that has sender, date, subject, etc...
15 require_once(SM_PATH
. 'functions/strings.php');
16 require_once(SM_PATH
. 'functions/html.php');
17 require_once(SM_PATH
. 'class/html.class.php');
18 require_once(SM_PATH
. 'functions/imap_mailbox.php');
19 require_once(SM_PATH
. 'functions/imap_messages.php');
20 require_once(SM_PATH
. 'functions/mime.php');
23 * PG_SEL_MAX: default value for page_selector_max
24 * SUBJ_TRIM_AT: the length at which we trim off subjects
26 define('PG_SEL_MAX', 10);
27 define('SUBJ_TRIM_AT', 55);
29 function elapsed($start)
32 list($start2, $start1) = explode(" ", $start);
33 list($end2, $end1) = explode(" ", $end);
34 $diff1 = $end1 - $start1;
35 $diff2 = $end2 - $start2;
40 return $diff2 +
$diff1;
43 function printMessageInfo($imapConnection, $t, $not_last=true, $key, $mailbox,
44 $start_msg, $where, $what) {
46 $color, $msgs, $msort, $td_str, $msg,
47 $default_use_priority,
48 $message_highlight_list,
50 $indent_array, /* indent subject by */
51 $pos, /* Search postion (if any) */
52 $thread_sort_messages, /* thread sorting on/off */
53 $server_sort_order, /* sort value when using server-sorting */
55 $allow_server_sort, /* enable/disable server-side sorting */
56 $truncate_sender, /* number of characters for From/To field (<= 0 for unchanged) */
59 $color_string = $color[4];
61 if ($GLOBALS['alt_index_colors']) {
62 if (!isset($row_count)) {
67 if (!isset($color[12])) {
68 $color[12] = '#EAEAEA';
70 $color_string = $color[12];
75 if($mailbox == 'None') {
76 $boxes = sqimap_mailbox_list($imapConnection);
77 $mailbox = $boxes[0]['unformatted'];
80 $urlMailbox = urlencode($mailbox);
82 $bSentFolder = handleAsSent($mailbox);
83 // If the From address is the same as $email_address, then handle as Sent
84 $from_array = parseAddress($msg['FROM'], 1);
85 if (!isset($email_address)) {
86 global $datadir, $username;
87 $email_address = getPref($datadir, $username, 'email_address');
89 $bHandleAsSent = ($bSentFolder) ||
((isset($from_array[0][0])) && ($from_array[0][0] == $email_address));
90 // If this is a Sent message, display To address instead of From
92 $msg['FROM'] = $msg['TO'];
93 // Passing 1 below results in only 1 address being parsed, thus defeating the following code
94 $msg['FROM'] = parseAddress($msg['FROM']/*,1*/);
97 * This is done in case you're looking into Sent folders,
98 * because you can have multiple receivers.
100 $senderNames = $msg['FROM'];
103 if (sizeof($senderNames)){
104 foreach ($senderNames as $senderNames_part) {
105 if ($senderName != '') {
107 $senderAddress .= ', ';
109 $sender_address_part = htmlspecialchars($senderNames_part[0]);
110 $sender_name_part = str_replace(' ',' ', decodeHeader($senderNames_part[1]));
111 if ($sender_name_part) {
112 $senderName .= $sender_name_part;
113 $senderAddress .= $sender_name_part . ' <' . $sender_address_part . '>';
115 $senderName .= $sender_address_part;
116 $senderAddress .= $sender_address_part;
120 // If Sent, prefix with To: but only if not Sent folder
121 if ($bHandleAsSent ^
$bSentFolder) {
122 $senderName = _("To:") . ' ' . $senderName;
123 $senderAddress = _("To:") . ' ' . $senderAddress;
126 if ( $truncate_sender > 0 && strlen($senderName) > $truncate_sender ) {
127 $senderName = substr_replace($senderName, '... ', $truncate_sender);
130 echo html_tag( 'tr','','','','VALIGN="top"') . "\n";
132 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
133 $flag = "<font color=\"$color[2]\">";
134 $flag_end = '</font>';
139 if (!isset($msg['FLAG_SEEN']) ||
($msg['FLAG_SEEN'] == false)) {
146 if ($bHandleAsSent) {
148 $italic_end = '</i>';
153 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
154 $fontstr = "<font color=\"$color[9]\">";
155 $fontstr_end = '</font>';
161 if ($where && $what) {
162 $searchstr = '&where='.$where.'&what='.$what;
167 if (is_array($message_highlight_list) && count($message_highlight_list)) {
168 $msg['TO'] = parseAddress($msg['TO']);
169 $msg['CC'] = parseAddress($msg['CC']);
170 foreach ($message_highlight_list as $message_highlight_list_part) {
171 if (trim($message_highlight_list_part['value']) != '') {
172 $high_val = strtolower($message_highlight_list_part['value']);
173 $match_type = strtoupper($message_highlight_list_part['match_type']);
174 if($match_type == 'TO_CC') {
175 $match = array('TO', 'CC');
177 $match = array($match_type);
179 foreach($match as $match_type) {
180 switch($match_type) {
184 foreach ($msg[$match_type] as $address) {
185 $address[0] = decodeHeader($address[0], true, false);
186 $address[1] = decodeHeader($address[1], true, false);
187 if (strstr('^^' . strtolower($address[0]), $high_val) ||
188 strstr('^^' . strtolower($address[1]), $high_val)) {
189 $hlt_color = $message_highlight_list_part['color'];
195 $headertest = strtolower(decodeHeader($msg[$match_type], true, false));
196 if (strstr('^^' . $headertest, $high_val)) {
197 $hlt_color = $message_highlight_list_part['color'];
207 if (!isset($hlt_color)) {
208 $hlt_color = $color_string;
210 $checked = ($checkall == 1) ?
' CHECKED' : '';
212 $msg['SUBJECT'] = str_replace(' ', ' ', decodeHeader($msg['SUBJECT']));
213 $subject = processSubject($msg['SUBJECT'], $indent_array[$msg['ID']]);
214 if (sizeof($index_order)) {
215 foreach ($index_order as $index_order_part) {
216 switch ($index_order_part) {
217 case 1: /* checkbox */
219 "<input type=checkbox name=\"msg[$t]\" value=\"".$msg['ID']."\"$checked>",
224 if ($senderAddress != $senderName) {
225 $senderAddress = strtr($senderAddress, array_flip(get_html_translation_table(HTML_SPECIALCHARS
)));
226 $title = ' title="' . str_replace('"', "''", $senderAddress) . '"';
231 $italic . $bold . $flag . $fontstr . $senderName .
232 $fontstr_end . $flag_end . $bold_end . $italic_end,
234 $hlt_color, $title );
237 $date_string = $msg['DATE_STRING'] . '';
238 if ($date_string == '') {
239 $date_string = _("Unknown date");
242 $bold . $flag . $fontstr . $date_string .
243 $fontstr_end . $flag_end . $bold_end,
248 case 4: /* subject */
250 if ($thread_sort_messages == 1) {
251 if (isset($indent_array[$msg['ID']])) {
252 $td_str .= str_repeat(" ",$indent_array[$msg['ID']]);
255 $td_str .= '<a href="read_body.php?mailbox='.$urlMailbox
256 . '&passed_id='. $msg["ID"]
257 . '&startMessage='.$start_msg.$searchstr.'"';
258 $td_str .= ' ' .concat_hook_function('subject_link', array($start_msg, $searchstr));
259 if ($subject != $msg['SUBJECT']) {
260 $title = get_html_translation_table(HTML_SPECIALCHARS
);
261 $title = array_flip($title);
262 $title = strtr($msg['SUBJECT'], $title);
263 $title = str_replace('"', "''", $title);
264 $td_str .= " title=\"$title\"";
266 $td_str .= ">$flag$subject$flag_end</a>$bold_end";
267 echo html_tag( 'td', $td_str, 'left', $hlt_color );
271 $td_str = "<b><small>";
273 if (isset($msg['FLAG_ANSWERED']) && $msg['FLAG_ANSWERED'] == true) {
277 if ($msg['TYPE0'] == 'multipart') {
281 if ($default_use_priority) {
282 if ( ($msg['PRIORITY'] == 1) ||
($msg['PRIORITY'] == 2) ) {
283 $td_str .= "<font color=\"$color[1]\">!</font>";
286 if ($msg['PRIORITY'] == 5) {
287 $td_str .= "<font color=\"$color[8]\">?</font>";
291 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'] == true) {
292 $td_str .= "<font color=\"$color[1]\">D</font>";
298 do_hook("msg_envelope");
299 $td_str .= '</small></b>';
308 $bold . $fontstr . show_readable_size($msg['SIZE']) .
309 $fontstr_end . $bold_end,
318 echo '</tr>' . "\n" . '<tr><td COLSPAN="' . $col . '" BGCOLOR="' .
319 $color[0] . '" HEIGHT="1"></td></tr>' . "\n";
325 function getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id) {
327 $id = array_slice($id, ($start_msg-1), $show_num);
328 $end = $start_msg +
$show_num - 1;
329 if ($num_msgs < $show_num) {
330 $end_loop = $num_msgs;
331 } else if ($end > $num_msgs) {
332 $end_loop = $num_msgs - $start_msg +
1;
334 $end_loop = $show_num;
336 return fillMessageArray($imapConnection,$id,$end_loop,$show_num);
342 function getThreadMessages($imapConnection, $start_msg, $show_num, $num_msgs) {
343 $id = get_thread_sort($imapConnection);
344 return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
347 function getServerSortMessages($imapConnection, $start_msg, $show_num,
348 $num_msgs, $server_sort_order, $mbxresponse) {
349 $id = sqimap_get_sort_order($imapConnection, $server_sort_order,$mbxresponse);
350 return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
353 function getSelfSortMessages($imapConnection, $start_msg, $show_num,
354 $num_msgs, $sort, $mbxresponse) {
356 if ($num_msgs >= 1) {
357 $id = sqimap_get_php_sort_order ($imapConnection, $mbxresponse);
361 /* set shownum to 999999 to fool sqimap_get_small_header_list
362 and rebuild the msgs_str to 1:* */
365 /* if it's not sorted */
366 if ($start_msg +
($show_num - 1) < $num_msgs) {
367 $end_msg = $start_msg +
($show_num - 1);
369 $end_msg = $num_msgs;
371 if ($end_msg < $start_msg) {
372 $start_msg = $start_msg - $show_num;
373 if ($start_msg < 1) {
377 $id = array_slice(array_reverse($id), ($start_msg-1), $show_num);
378 $end = $start_msg +
$show_num - 1;
379 if ($num_msgs < $show_num) {
380 $end_loop = $num_msgs;
381 } else if ($end > $num_msgs) {
382 $end_loop = $num_msgs - $start_msg +
1;
384 $end_loop = $show_num;
387 $msgs = fillMessageArray($imapConnection,$id,$end_loop, $show_num);
395 * This function loops through a group of messages in the mailbox
396 * and shows them to the user.
398 function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
399 $start_msg, $sort, $color, $show_num,
400 $use_cache, $mode='') {
401 global $msgs, $msort, $auto_expunge, $thread_sort_messages,
402 $allow_server_sort, $server_sort_order;
405 * For some reason, on PHP 4.3+, this being unset, and set in the session causes havoc
406 * so setting it to an empty array beforehand seems to clean up the issue, and stopping the
407 * "Your script possibly relies on a session side-effect which existed until PHP 4.2.3" error
410 if (!isset($msort)) {
418 //$start = microtime();
419 /* If autoexpunge is turned on, then do it now. */
420 $mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox);
422 /* If autoexpunge is turned on, then do it now. */
423 if ($auto_expunge == true) {
424 $exp_cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, false, '');
425 $mbxresponse['EXISTS'] = $mbxresponse['EXISTS'] - $exp_cnt;
426 $num_msgs = $mbxresponse['EXISTS'];
429 if ($mbxresponse['EXISTS'] > 0) {
430 /* if $start_msg is lower than $num_msgs, we probably deleted all messages
431 * in the last page. We need to re-adjust the start_msg
434 if($start_msg > $num_msgs) {
435 $start_msg -= $show_num;
441 /* This code and the next if() block check for
442 * server-side sorting methods. The $id array is
443 * formatted and $sort is set to 6 to disable
444 * SM internal sorting
447 if ($thread_sort_messages == 1) {
449 } elseif ($allow_server_sort == 1) {
450 $mode = 'serversort';
456 sqgetGlobalVar('msgs', $msgs, SQ_SESSION
);
457 sqgetGlobalVar('msort', $msort, SQ_SESSION
);
459 sqsession_unregister('msort');
460 sqsession_unregister('msgs'); }
463 $id = get_thread_sort($imapConnection);
464 $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
465 if ($msgs === false) {
466 echo '<b><small><center><font color=red>' .
467 _("Thread sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
468 '</center></small></b>';
469 $thread_sort_messages = 0;
470 $msort = $msgs = array();
477 $id = sqimap_get_sort_order($imapConnection, $sort, $mbxresponse);
478 $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
479 if ($msgs === false) {
480 echo '<b><small><center><font color=red>' .
481 _( "Server-side sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
482 '</center></small></b>';
483 $sort = $server_sort_order;
484 $allow_server_sort = FALSE;
485 $msort = $msgs = array();
494 $msgs = getSelfSortMessages($imapConnection, $start_msg, $show_num,
495 $num_msgs, $sort, $mbxresponse);
496 $msort = calc_msort($msgs, $sort);
500 sqsession_register($msort, 'msort');
501 sqsession_register($msgs, 'msgs');
503 } /* if exists > 0 */
505 $res = getEndMessage($start_msg, $show_num, $num_msgs);
506 $start_msg = $res[0];
509 $paginator_str = get_paginator_str($mailbox, $start_msg, $end_msg,
510 $num_msgs, $show_num, $sort);
512 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
514 do_hook('mailbox_index_before');
515 echo '<table border="0" width="100%" cellpadding="0" cellspacing="0">';
518 mail_message_listing_beginning($imapConnection, $mailbox, $sort,
519 $msg_cnt_str, $paginator_str, $start_msg);
521 /* line between the button area and the list */
522 echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>';
525 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
527 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[5].'">';
529 printHeader($mailbox, $srt, $color, !$thread_sort_messages);
531 displayMessageArray($imapConnection, $num_msgs, $start_msg,
532 $msort, $mailbox, $sort, $color, $show_num,0,0);
533 echo '</td></tr></table></td></tr></table>';
535 mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color);
536 echo '</td></tr></table>';
537 //$t = elapsed($start);
538 //echo("elapsed time = $t seconds\n");
541 function calc_msort($msgs, $sort) {
552 if (($sort == 0) ||
($sort == 1)) {
553 foreach ($msgs as $item) {
554 $msort[] = $item['TIME_STAMP'];
556 } elseif (($sort == 2) ||
($sort == 3)) {
557 foreach ($msgs as $item) {
558 $msort[] = $item['FROM-SORT'];
560 } elseif (($sort == 4) ||
($sort == 5)) {
561 foreach ($msgs as $item) {
562 $msort[] = $item['SUBJECT-SORT'];
577 function fillMessageArray($imapConnection, $id, $count, $show_num=false) {
578 return sqimap_get_small_header_list($imapConnection, $id, $show_num);
582 /* Generic function to convert the msgs array into an HTML table. */
583 function displayMessageArray($imapConnection, $num_msgs, $start_msg,
584 $msort, $mailbox, $sort, $color,
585 $show_num, $where=0, $what=0) {
586 global $imapServerAddress, $use_mailbox_cache, $index_order,
587 $indent_array, $thread_sort_messages, $allow_server_sort,
588 $server_sort_order, $PHP_SELF;
590 $res = getEndMessage($start_msg, $show_num, $num_msgs);
591 $start_msg = $res[0];
594 $urlMailbox = urlencode($mailbox);
596 /* get indent level for subject display */
597 if ($thread_sort_messages == 1 && $num_msgs) {
598 $indent_array = get_parent_level($imapConnection);
601 $real_startMessage = $start_msg;
603 if ($end_msg - $start_msg < $show_num - 1) {
604 $end_msg = $end_msg - $start_msg +
1;
606 } else if ($start_msg > $show_num) {
607 $end_msg = $show_num;
611 $endVar = $end_msg +
1;
614 * Loop through and display the info for each message.
615 * ($t is used for the checkbox number)
619 /* messages display */
622 /* if there's no messages in this folder */
625 "<BR><b>" . _("THIS FOLDER IS EMPTY") . "</b><BR> ",
628 'COLSPAN="' . count($index_order) . '"'
631 } elseif ($start_msg == $end_msg) {
632 /* if there's only one message in the box, handle it differently. */
644 } while (isset ($key) && ($k < $i));
645 printMessageInfo($imapConnection, $t, true, $key, $mailbox,
646 $real_startMessage, $where, $what);
655 } while (isset ($key) && ($k < $i));
658 if (!$i ||
$i == $endVar-1) $not_last = false;
659 printMessageInfo($imapConnection, $t, $not_last, $key, $mailbox,
660 $real_startMessage, $where, $what);
665 } while ($i && $i < $endVar);
670 * Displays the standard message list header. To finish the table,
671 * you need to do a "</table></table>";
673 * $moveURL is the URL to submit the delete/move form to
674 * $mailbox is the current mailbox
675 * $sort is the current sorting method (-1 for no sorting available [searches])
676 * $Message is a message that is centered on top of the list
677 * $More is a second line that is left aligned
680 function mail_message_listing_beginning ($imapConnection,
681 $mailbox = '', $sort = -1,
683 $paginator = ' ',
685 global $color, $auto_expunge, $base_uri, $thread_sort_messages,
686 $allow_thread_sort, $allow_server_sort, $server_sort_order,
689 $php_self = $PHP_SELF;
690 /* fix for incorrect $PHP_SELF */
691 if (strpos($php_self, 'move_messages.php')) {
692 $php_self = str_replace('move_messages.php', 'right_main.php', $php_self);
694 $urlMailbox = urlencode($mailbox);
696 if (preg_match('/^(.+)\?.+$/',$php_self,$regs)) {
697 $source_url = $regs[1];
699 $source_url = $php_self;
705 $moveFields = '<input type="hidden" name="msg" value="'.htmlspecialchars($msg).'">' .
706 '<input type="hidden" name="mailbox" value="'.htmlspecialchars($mailbox).'">' .
707 '<input type="hidden" name="startMessage" value="'.htmlspecialchars($start_msg).'">';
709 // $moveURL = "move_messages.php?msg=$msg&mailbox=$urlMailbox"
710 // . "&startMessage=$start_msg";
712 * This is the beginning of the message list table.
713 * It wraps around all messages
715 $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $mailbox);
716 $form_name = "FormMsgs" . $safe_name;
717 echo '<form name="' . $form_name . '" method="post" action="move_messages.php">' ."\n"
719 . html_tag( 'table' ,
724 html_tag( 'td', $paginator, 'left' ) .
725 html_tag( 'td', $msg_cnt_str, 'right' )
727 , '', $color[4], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
730 , '', '', 'border="0" width="100%" cellpadding="1" cellspacing="0"' );
731 /* line between header and button area */
732 echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>';
735 echo html_tag( 'tr' ) . "\n"
736 . html_tag( 'td' ,'' , 'left', '', '' )
737 . html_tag( 'table' ,'' , '', $color[9], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
739 . html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
741 getSmallStringCell(_("Move Selected To"), 'left', 'nowrap') .
742 getSmallStringCell(_("Transform Selected Messages"), 'right')
744 . html_tag( 'tr' ) ."\n"
745 . html_tag( 'td', '', 'left', '', 'valign="middle" nowrap' );
746 getMbxList($imapConnection);
747 echo getButton('SUBMIT', 'moveButton',_("Move")) . "\n";
748 echo getButton('SUBMIT', 'attache',_("Forward")) . "\n";
751 . html_tag( 'td', '', 'right', '', 'nowrap' );
755 if (!$auto_expunge) {
756 echo getButton('SUBMIT', 'expungeButton',_("Expunge"))
757 .' ' . _("mailbox") . "\n";
759 do_hook('mailbox_display_buttons');
760 echo getButton('SUBMIT', 'markRead',_("Read"));
761 echo getButton('SUBMIT', 'markUnread',_("Unread"));
762 echo getButton('SUBMIT', 'delete',_("Delete")) ." \n";
763 if (!strpos($php_self,'mailbox')) {
764 $location = $php_self.'?mailbox=INBOX&startMessage=1';
766 $location = $php_self;
768 echo '<INPUT TYPE="HIDDEN" NAME="location" VALUE="'.$location.'">';
772 /* draws thread sorting links */
773 if ($allow_thread_sort == TRUE) {
774 if ($thread_sort_messages == 1 ) {
776 $thread_name = _("Unthread View");
777 } elseif ($thread_sort_messages == 0) {
779 $thread_name = _("Thread View");
781 echo html_tag( 'tr' ,
783 ' <a href=' . $source_url . '?sort='
784 . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
785 . '&mailbox=' . urlencode($mailbox) . '><small>' . $thread_name
786 . '</a></small> '
787 , '', '', '' ) . html_tag( 'td', _("Bypass Trash") . '<input type="checkbox" name="bypass_trash">','right','','')
792 echo "</TABLE></td></tr></table></td></tr>\n";
794 do_hook('mailbox_form_before');
796 /* if using server sort we highjack the
797 * the $sort var and use $server_sort_order
798 * instead. but here we reset sort for a bit
801 if ($allow_server_sort == TRUE) {
802 $sort = $server_sort_order;
806 function mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color) {
808 /* space between list and footer */
809 echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'" COLSPAN="1">';
811 echo '</td></tr><tr><td>';
812 echo html_tag( 'table',
817 html_tag( 'td', $paginator_str ) .
818 html_tag( 'td', $msg_cnt_str, 'right' )
820 , '', $color[4], 'width="100%" border="0" cellpadding="1" cellspacing="0"' )
823 , '', $color[9], 'width="100%" border="0" cellpadding="1" cellspacing="0"' );
826 /* End of message-list table */
828 do_hook('mailbox_index_after');
832 function printHeader($mailbox, $sort, $color, $showsort=true) {
834 echo html_tag( 'tr' ,'' , 'center', $color[5] );
836 /* calculate the width of the subject column based on the
837 * widths of the other columns */
838 $widths = array(1=>1,2=>25,3=>5,4=>0,5=>1,6=>5);
840 foreach($index_order as $item) {
841 $subjectwidth -= $widths[$item];
844 foreach ($index_order as $item) {
846 case 1: /* checkbox */
848 echo html_tag( 'td' ,' ' , '', '', 'width="1%"' );
851 if (handleAsSent($mailbox)) {
852 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
853 . '<b>' . _("To") . '</b>';
855 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
856 . '<b>' . _("From") . '</b>';
859 ShowSortButton($sort, $mailbox, 2, 3);
864 echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
865 . '<b>' . _("Date") . '</b>';
867 ShowSortButton($sort, $mailbox, 0, 1);
871 case 4: /* subject */
872 echo html_tag( 'td' ,'' , 'left', '', 'width="'.$subjectwidth.'%"' )
873 . '<b>' . _("Subject") . '</b>';
875 ShowSortButton($sort, $mailbox, 4, 5);
880 echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%" nowrap' );
889 * This function shows the sort button. Isn't this a good comment?
891 function ShowSortButton($sort, $mailbox, $Up, $Down ) {
893 /* Figure out which image we want to use. */
894 if ($sort != $Up && $sort != $Down) {
895 $img = 'sort_none.png';
897 } elseif ($sort == $Up) {
898 $img = 'up_pointer.png';
901 $img = 'down_pointer.png';
905 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
906 $source_url = $regs[1];
908 $source_url = $PHP_SELF;
911 /* Now that we have everything figured out, show the actual button. */
912 echo ' <a href="' . $source_url .'?newsort=' . $which
913 . '&startMessage=1&mailbox=' . urlencode($mailbox)
914 . '"><img src="../images/' . $img
915 . '" border="0" width="12" height="10" alt="sort" title="'
916 . _("Click here to change the sorting of the message list") .'"></a>';
919 function get_selectall_link($start_msg, $sort) {
920 global $checkall, $what, $where, $mailbox, $javascript_on;
921 global $PHP_SELF, $PG_SHOWNUM;
924 if ($javascript_on) {
925 $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $mailbox);
926 $func_name = "CheckAll" . $safe_name;
927 $form_name = "FormMsgs" . $safe_name;
928 $result = '<script language="JavaScript" type="text/javascript">'
930 . "function " . $func_name . "() {\n"
931 . " for (var i = 0; i < document." . $form_name . ".elements.length; i++) {\n"
932 . " if(document." . $form_name . ".elements[i].type == 'checkbox' && "
933 . "document." . $form_name . ".elements[i].name != 'bypass_trash'){\n"
934 . " document." . $form_name . ".elements[i].checked = "
935 . " !(document." . $form_name . ".elements[i].checked);\n"
940 . '</script><a href="javascript:void(0)" onClick="' . $func_name . '();">' . _("Toggle All")
941 /* . '</script><a href="javascript:' . $func_name . '()">' . _("Toggle All")*/
944 if (strpos($PHP_SELF, "?")) {
945 $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($mailbox)
946 . "&startMessage=$start_msg&sort=$sort&checkall=";
948 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
949 . "&startMessage=$start_msg&sort=$sort&checkall=";
951 if (isset($checkall) && $checkall == '1') {
957 if (isset($where) && isset($what)) {
958 $result .= '&where=' . urlencode($where)
959 . '&what=' . urlencode($what);
963 if (isset($checkall) && ($checkall == '1')) {
964 $result .= _("Unselect All");
966 $result .= _("Select All");
971 /* Return our final result. */
976 * This function computes the "Viewing Messages..." string.
978 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
979 /* Compute the $msg_cnt_str. */
981 if ($start_msg < $end_msg) {
982 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"),
983 $start_msg, $end_msg, $num_msgs);
984 } else if ($start_msg == $end_msg) {
985 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
989 /* Return our result string. */
994 * Generate a paginator link.
996 function get_paginator_link($box, $start_msg, $use, $text) {
999 $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
1000 . "&startMessage=$start_msg&mailbox=$box\" "
1001 . "TARGET=\"right\">$text</A>";
1004 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
1005 $source_url = $regs[1];
1007 $source_url = $PHP_SELF;
1010 $result = '<A HREF="'. $source_url . "?use_mailbox_cache=$use"
1011 . "&startMessage=$start_msg&mailbox=$box\" "
1012 . "TARGET=\"right\">$text</A>";
1018 * This function computes the paginator string.
1020 function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
1022 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
1024 /* Initialize paginator string chunks. */
1031 $box = urlencode($box);
1033 /* Create simple strings that will be creating the paginator. */
1034 $spc = ' '; /* This will be used as a space. */
1035 $sep = '|'; /* This will be used as a seperator. */
1037 /* Get some paginator preference values. */
1038 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON
);
1039 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
);
1041 /* Make sure that our start message number is not too big. */
1042 $start_msg = min($start_msg, $num_msgs);
1044 /* Decide whether or not we will use the mailbox cache. */
1045 /* Not sure why $use_mailbox_cache is even passed in. */
1052 /* Compute the starting message of the previous and next page group. */
1053 $next_grp = $start_msg +
$show_num;
1054 $prev_grp = $start_msg - $show_num;
1056 /* Compute the basic previous and next strings. */
1057 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
1058 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1059 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1060 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
1061 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1062 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
1063 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
1064 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
1065 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1068 /* Page selector block. Following code computes page links. */
1069 if ($pg_sel && ($num_msgs > $show_num)) {
1070 /* Most importantly, what is the current page!!! */
1071 $cur_pg = intval($start_msg / $show_num) +
1;
1073 /* Compute total # of pages and # of paginator page links. */
1074 $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
1075 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
1077 /* Compute the size of the four quarters of the page links. */
1079 /* If we can, just show all the pages. */
1080 if (($tot_pgs - 1) <= $pg_max) {
1081 $q1_pgs = $cur_pg - 1;
1082 $q2_pgs = $q3_pgs = 0;
1083 $q4_pgs = $tot_pgs - $cur_pg;
1085 /* Otherwise, compute some magic to choose the four quarters. */
1088 * Compute the magic base values. Added together,
1089 * these values will always equal to the $pag_pgs.
1090 * NOTE: These are DEFAULT values and do not take
1091 * the current page into account. That is below.
1093 $q1_pgs = floor($vis_pgs/4);
1094 $q2_pgs = round($vis_pgs/4, 0);
1095 $q3_pgs = ceil($vis_pgs/4);
1096 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
1098 /* Adjust if the first quarter contains the current page. */
1099 if (($cur_pg - $q1_pgs) < 1) {
1100 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) +
$q2_pgs;
1101 $q1_pgs = $cur_pg - 1;
1103 $q3_pgs +
= ceil($extra_pgs / 2);
1104 $q4_pgs +
= floor($extra_pgs / 2);
1106 /* Adjust if the first and second quarters intersect. */
1107 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
1108 $extra_pgs = $q2_pgs;
1109 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1110 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1111 $q3_pgs +
= ceil($extra_pgs / 2);
1112 $q4_pgs +
= floor($extra_pgs / 2);
1114 /* Adjust if the fourth quarter contains the current page. */
1115 } else if (($cur_pg +
$q4_pgs) >= $tot_pgs) {
1116 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) +
$q3_pgs;
1118 $q4_pgs = $tot_pgs - $cur_pg;
1119 $q1_pgs +
= floor($extra_pgs / 2);
1120 $q2_pgs +
= ceil($extra_pgs / 2);
1122 /* Adjust if the third and fourth quarter intersect. */
1123 } else if (($cur_pg +
$q3_pgs +
1) >= ($tot_pgs - $q4_pgs +
1)) {
1124 $extra_pgs = $q3_pgs;
1125 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1126 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1127 $q1_pgs +
= floor($extra_pgs / 2);
1128 $q2_pgs +
= ceil($extra_pgs / 2);
1133 * I am leaving this debug code here, commented out, because
1134 * it is a really nice way to see what the above code is doing.
1135 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
1136 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
1139 /* Print out the page links from the compute page quarters. */
1141 /* Start with the first quarter. */
1142 if (($q1_pgs == 0) && ($cur_pg > 1)) {
1143 $pg_str .= "...$spc";
1145 for ($pg = 1; $pg <= $q1_pgs; ++
$pg) {
1146 $start = (($pg-1) * $show_num) +
1;
1147 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1149 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
1150 $pg_str .= "...$spc";
1154 /* Continue with the second quarter. */
1155 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++
$pg) {
1156 $start = (($pg-1) * $show_num) +
1;
1157 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1160 /* Now print the current page. */
1161 $pg_str .= $cur_pg . $spc;
1163 /* Next comes the third quarter. */
1164 for ($pg = $cur_pg +
1; $pg <= $cur_pg +
$q3_pgs; ++
$pg) {
1165 $start = (($pg-1) * $show_num) +
1;
1166 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1169 /* And last, print the forth quarter page links. */
1170 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
1171 $pg_str .= "...$spc";
1173 if (($tot_pgs - $q4_pgs) > ($cur_pg +
$q3_pgs)) {
1174 $pg_str .= "...$spc";
1176 for ($pg = $tot_pgs - $q4_pgs +
1; $pg <= $tot_pgs; ++
$pg) {
1177 $start = (($pg-1) * $show_num) +
1;
1178 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1181 } else if ($PG_SHOWNUM == 999999) {
1182 $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
1183 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1184 . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc;
1187 /* If necessary, compute the 'show all' string. */
1188 if (($prv_str != '') ||
($nxt_str != '')) {
1189 $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
1190 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1191 . "TARGET=\"right\">" . _("Show All") . '</A>';
1194 /* Last but not least, get the value for the toggle all link. */
1195 $tgl_str = get_selectall_link($start_msg, $sort);
1197 /* Put all the pieces of the paginator string together. */
1199 * Hairy code... But let's leave it like it is since I am not certain
1200 * a different approach would be any easier to read. ;)
1203 $result .= ($prv_str != '' ?
$prv_str . $spc . $sep . $spc : '');
1204 $result .= ($nxt_str != '' ?
$nxt_str . $spc . $sep . $spc : '');
1205 $result .= ($pg_str != '' ?
$pg_str : '');
1206 $result .= ($all_str != '' ?
$sep . $spc . $all_str . $spc : '');
1207 $result .= ($result != '' ?
$sep . $spc . $tgl_str: $tgl_str);
1209 /* If the resulting string is blank, return a non-breaking space. */
1210 if ($result == '') {
1214 /* Return our final magical paginator string. */
1218 function processSubject($subject, $threadlevel = 0) {
1219 global $languages, $squirrelmail_language;
1220 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1221 if ($subject == '') {
1222 return _("(no subject)");
1225 $trim_at = SUBJ_TRIM_AT
;
1227 /* if this is threaded, subtract two chars per indentlevel */
1228 if($threadlevel > 0 && $threadlevel <= 10) {
1229 $trim_at -= (2*$threadlevel);
1232 if (strlen($subject) <= $trim_at) {
1236 $ent_strlen = $orig_len = strlen($subject);
1237 $trim_val = $trim_at - 5;
1240 * see if this is entities-encoded string
1241 * If so, Iterate through the whole string, find out
1242 * the real number of characters, and if more
1243 * than 55, substr with an updated trim value.
1245 $step = $ent_loc = 0;
1246 while ( $ent_loc < $trim_val && (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1247 (($ent_loc_end = strpos($subject, ';', $ent_loc+
3)) !== false) ) {
1248 $trim_val +
= ($ent_loc_end-$ent_loc);
1249 $ent_offset = $ent_loc_end+
1;
1253 if (($trim_val > 50) && (strlen($subject) > ($trim_val))&& (strpos($subject,';',$trim_val) < ($trim_val +
6))) {
1254 $i = strpos($subject,';',$trim_val);
1256 $trim_val = strpos($subject,';',$trim_val);
1259 if ($ent_strlen <= $trim_at){
1263 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
1264 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
1265 return $languages[$squirrelmail_language]['XTRA_CODE']('strimwidth', $subject, $trim_val);
1268 // only print '...' when we're actually dropping part of the subject
1269 if(strlen($subject) <= $trim_val) {
1272 return substr($subject, 0, $trim_val) . '...';
1276 function getMbxList($imapConnection, $boxes = 0) {
1277 global $lastTargetMailbox;
1278 echo ' <small> <tt><select name="targetMailbox">';
1279 echo sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)), 0, $boxes);
1280 echo ' </SELECT></TT> ';
1283 function getButton($type, $name, $value) {
1284 return '<INPUT TYPE="'.$type.'" NAME="'.$name.'" VALUE="'.$value . '">';
1287 function getSmallStringCell($string, $align) {
1288 return html_tag('td',
1289 '<small>' . $string . ': </small>',
1295 function getEndMessage($start_msg, $show_num, $num_msgs) {
1296 if ($start_msg +
($show_num - 1) < $num_msgs){
1297 $end_msg = $start_msg +
($show_num - 1);
1299 $end_msg = $num_msgs;
1302 if ($end_msg < $start_msg) {
1303 $start_msg = $start_msg - $show_num;
1304 if ($start_msg < 1) {
1308 return (array($start_msg,$end_msg));
1311 function handleAsSent($mailbox) {
1312 global $handleAsSent_result;
1314 /* First check if this is the sent or draft folder. */
1315 $handleAsSent_result = isSentMailbox($mailbox) ||
isDraftMailbox($mailbox);
1317 /* Then check the result of the handleAsSent hook. */
1318 do_hook('check_handleAsSent_result', $mailbox);
1320 /* And return the result. */
1321 return $handleAsSent_result;