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) */
58 $color_string = $color[4];
60 if ($GLOBALS['alt_index_colors']) {
61 if (!isset($row_count)) {
66 if (!isset($color[12])) {
67 $color[12] = '#EAEAEA';
69 $color_string = $color[12];
74 if($mailbox == 'None') {
75 $boxes = sqimap_mailbox_list($imapConnection);
76 $mailbox = $boxes[0]['unformatted'];
79 $urlMailbox = urlencode($mailbox);
81 if (handleAsSent($mailbox)) {
82 $msg['FROM'] = $msg['TO'];
84 $msg['FROM'] = parseAddress($msg['FROM'],1);
87 * This is done in case you're looking into Sent folders,
88 * because you can have multiple receivers.
91 $senderNames = $msg['FROM'];
94 if (sizeof($senderNames)){
95 foreach ($senderNames as $senderNames_part) {
96 if ($senderName != '') {
98 $senderAddress .= ', ';
100 $sender_address_part = htmlspecialchars($senderNames_part[0]);
101 $sender_name_part = decodeHeader($senderNames_part[1]);
102 if ($sender_name_part) {
103 $senderName .= $sender_name_part;
104 $senderAddress .= $sender_name_part . ' <' . $sender_address_part . '>';
106 $senderName .= $sender_address_part;
107 $senderAddress .= $sender_address_part;
111 $senderName = str_replace(' ',' ',$senderName);
113 if ( $truncate_sender > 0 && strlen($senderName) > $truncate_sender ) {
114 $senderName = substr_replace($senderName, '... ', $truncate_sender);
117 echo html_tag( 'tr','','','','VALIGN="top"') . "\n";
119 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
120 $flag = "<font color=\"$color[2]\">";
121 $flag_end = '</font>';
126 if (!isset($msg['FLAG_SEEN']) ||
($msg['FLAG_SEEN'] == false)) {
133 if (handleAsSent($mailbox)) {
135 $italic_end = '</i>';
140 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
141 $fontstr = "<font color=\"$color[9]\">";
142 $fontstr_end = '</font>';
148 if ($where && $what) {
149 $searchstr = '&where='.$where.'&what='.$what;
154 if (is_array($message_highlight_list) && count($message_highlight_list)) {
155 $msg['TO'] = parseAddress($msg['TO']);
156 $msg['CC'] = parseAddress($msg['CC']);
157 foreach ($message_highlight_list as $message_highlight_list_part) {
158 if (trim($message_highlight_list_part['value']) != '') {
159 $high_val = strtolower($message_highlight_list_part['value']);
160 $match_type = strtoupper($message_highlight_list_part['match_type']);
161 if($match_type == 'TO_CC') {
162 $match = array('TO', 'CC');
164 $match = array($match_type);
166 foreach($match as $match_type) {
167 switch($match_type) {
171 foreach ($msg[$match_type] as $address) {
172 $address[0] = decodeHeader($address[0], true, false);
173 $address[1] = decodeHeader($address[1], true, false);
174 if (strstr('^^' . strtolower($address[0]), $high_val) ||
175 strstr('^^' . strtolower($address[1]), $high_val)) {
176 $hlt_color = $message_highlight_list_part['color'];
182 $headertest = strtolower(decodeHeader($msg[$match_type], true, false));
183 if (strstr('^^' . $headertest, $high_val)) {
184 $hlt_color = $message_highlight_list_part['color'];
194 if (!isset($hlt_color)) {
195 $hlt_color = $color_string;
197 $checked = ($checkall == 1) ?
' CHECKED' : '';
199 $msg['SUBJECT'] = str_replace(' ', ' ', decodeHeader($msg['SUBJECT']));
200 $subject = processSubject($msg['SUBJECT'], $indent_array[$msg['ID']]);
201 if (sizeof($index_order)) {
202 foreach ($index_order as $index_order_part) {
203 switch ($index_order_part) {
204 case 1: /* checkbox */
206 "<input type=checkbox name=\"msg[$t]\" value=\"".$msg['ID']."\"$checked>",
211 if ($senderAddress != $senderName) {
212 $senderAddress = strtr($senderAddress, array_flip(get_html_translation_table(HTML_SPECIALCHARS
)));
213 $title = ' title="' . str_replace('"', "''", $senderAddress) . '"';
218 $italic . $bold . $flag . $fontstr . $senderName .
219 $fontstr_end . $flag_end . $bold_end . $italic_end,
221 $hlt_color, $title );
224 $date_string = $msg['DATE_STRING'] . '';
225 if ($date_string == '') {
226 $date_string = _("Unknown date");
229 $bold . $flag . $fontstr . $date_string .
230 $fontstr_end . $flag_end . $bold_end,
235 case 4: /* subject */
237 if ($thread_sort_messages == 1) {
238 if (isset($indent_array[$msg['ID']])) {
239 $td_str .= str_repeat(" ",$indent_array[$msg['ID']]);
242 $td_str .= '<a href="read_body.php?mailbox='.$urlMailbox
243 . '&passed_id='. $msg["ID"]
244 . '&startMessage='.$start_msg.$searchstr.'"';
245 $td_str .= ' ' .concat_hook_function('subject_link', array($start_msg, $searchstr));
246 if ($subject != $msg['SUBJECT']) {
247 $title = get_html_translation_table(HTML_SPECIALCHARS
);
248 $title = array_flip($title);
249 $title = strtr($msg['SUBJECT'], $title);
250 $title = str_replace('"', "''", $title);
251 $td_str .= " title=\"$title\"";
253 $td_str .= ">$flag$subject$flag_end</a>$bold_end";
254 echo html_tag( 'td', $td_str, 'left', $hlt_color );
258 $td_str = "<b><small>";
260 if (isset($msg['FLAG_ANSWERED']) && $msg['FLAG_ANSWERED'] == true) {
264 if ($msg['TYPE0'] == 'multipart') {
268 if ($default_use_priority) {
269 if ( ($msg['PRIORITY'] == 1) ||
($msg['PRIORITY'] == 2) ) {
270 $td_str .= "<font color=\"$color[1]\">!</font>";
273 if ($msg['PRIORITY'] == 5) {
274 $td_str .= "<font color=\"$color[8]\">?</font>";
278 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'] == true) {
279 $td_str .= "<font color=\"$color[1]\">D</font>";
285 do_hook("msg_envelope");
286 $td_str .= '</small></b>';
295 $bold . $fontstr . show_readable_size($msg['SIZE']) .
296 $fontstr_end . $bold_end,
305 echo '</tr>' . "\n" . '<tr><td COLSPAN="' . $col . '" BGCOLOR="' .
306 $color[0] . '" HEIGHT="1"></td></tr>' . "\n";
312 function getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id) {
314 $id = array_slice($id, ($start_msg-1), $show_num);
315 $end = $start_msg +
$show_num - 1;
316 if ($num_msgs < $show_num) {
317 $end_loop = $num_msgs;
318 } else if ($end > $num_msgs) {
319 $end_loop = $num_msgs - $start_msg +
1;
321 $end_loop = $show_num;
323 return fillMessageArray($imapConnection,$id,$end_loop,$show_num);
329 function getThreadMessages($imapConnection, $start_msg, $show_num, $num_msgs) {
330 $id = get_thread_sort($imapConnection);
331 return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
334 function getServerSortMessages($imapConnection, $start_msg, $show_num,
335 $num_msgs, $server_sort_order, $mbxresponse) {
336 $id = sqimap_get_sort_order($imapConnection, $server_sort_order,$mbxresponse);
337 return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
340 function getSelfSortMessages($imapConnection, $start_msg, $show_num,
341 $num_msgs, $sort, $mbxresponse) {
343 if ($num_msgs >= 1) {
344 $id = sqimap_get_php_sort_order ($imapConnection, $mbxresponse);
348 /* set shownum to 999999 to fool sqimap_get_small_header_list
349 and rebuild the msgs_str to 1:* */
352 /* if it's not sorted */
353 if ($start_msg +
($show_num - 1) < $num_msgs) {
354 $end_msg = $start_msg +
($show_num - 1);
356 $end_msg = $num_msgs;
358 if ($end_msg < $start_msg) {
359 $start_msg = $start_msg - $show_num;
360 if ($start_msg < 1) {
364 $id = array_slice(array_reverse($id), ($start_msg-1), $show_num);
365 $end = $start_msg +
$show_num - 1;
366 if ($num_msgs < $show_num) {
367 $end_loop = $num_msgs;
368 } else if ($end > $num_msgs) {
369 $end_loop = $num_msgs - $start_msg +
1;
371 $end_loop = $show_num;
374 $msgs = fillMessageArray($imapConnection,$id,$end_loop, $show_num);
382 * This function loops through a group of messages in the mailbox
383 * and shows them to the user.
385 function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
386 $start_msg, $sort, $color, $show_num,
387 $use_cache, $mode='') {
388 global $msgs, $msort, $auto_expunge, $thread_sort_messages,
389 $allow_server_sort, $server_sort_order;
392 * For some reason, on PHP 4.3+, this being unset, and set in the session causes havoc
393 * so setting it to an empty array beforehand seems to clean up the issue, and stopping the
394 * "Your script possibly relies on a session side-effect which existed until PHP 4.2.3" error
397 if (!isset($msort)) {
405 //$start = microtime();
406 /* If autoexpunge is turned on, then do it now. */
407 $mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox);
409 /* If autoexpunge is turned on, then do it now. */
410 if ($auto_expunge == true) {
411 $exp_cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, false, '');
412 $mbxresponse['EXISTS'] = $mbxresponse['EXISTS'] - $exp_cnt;
413 $num_msgs = $mbxresponse['EXISTS'];
416 if ($mbxresponse['EXISTS'] > 0) {
417 /* if $start_msg is lower than $num_msgs, we probably deleted all messages
418 * in the last page. We need to re-adjust the start_msg
421 if($start_msg > $num_msgs) {
422 $start_msg -= $show_num;
428 /* This code and the next if() block check for
429 * server-side sorting methods. The $id array is
430 * formatted and $sort is set to 6 to disable
431 * SM internal sorting
434 if ($thread_sort_messages == 1) {
436 } elseif ($allow_server_sort == 1) {
437 $mode = 'serversort';
443 sqgetGlobalVar('msgs', $msgs, SQ_SESSION
);
444 sqgetGlobalVar('msort', $msort, SQ_SESSION
);
446 sqsession_unregister('msort');
447 sqsession_unregister('msgs'); }
450 $id = get_thread_sort($imapConnection);
451 $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
452 if ($msgs === false) {
453 echo '<b><small><center><font color=red>' .
454 _("Thread sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
455 '</center></small></b>';
456 $thread_sort_messages = 0;
457 $msort = $msgs = array();
464 $id = sqimap_get_sort_order($imapConnection, $sort, $mbxresponse);
465 $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
466 if ($msgs === false) {
467 echo '<b><small><center><font color=red>' .
468 _( "Server-side sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
469 '</center></small></b>';
470 $sort = $server_sort_order;
471 $allow_server_sort = FALSE;
472 $msort = $msgs = array();
481 $msgs = getSelfSortMessages($imapConnection, $start_msg, $show_num,
482 $num_msgs, $sort, $mbxresponse);
483 $msort = calc_msort($msgs, $sort);
487 sqsession_register($msort, 'msort');
488 sqsession_register($msgs, 'msgs');
490 } /* if exists > 0 */
492 $res = getEndMessage($start_msg, $show_num, $num_msgs);
493 $start_msg = $res[0];
496 $paginator_str = get_paginator_str($mailbox, $start_msg, $end_msg,
497 $num_msgs, $show_num, $sort);
499 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
501 do_hook('mailbox_index_before');
502 echo '<table border="0" width="100%" cellpadding="0" cellspacing="0">';
505 mail_message_listing_beginning($imapConnection, $mailbox, $sort,
506 $msg_cnt_str, $paginator_str, $start_msg);
508 /* line between the button area and the list */
509 echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>';
512 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
514 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[5].'">';
516 printHeader($mailbox, $srt, $color, !$thread_sort_messages);
518 displayMessageArray($imapConnection, $num_msgs, $start_msg,
519 $msort, $mailbox, $sort, $color, $show_num,0,0);
520 echo '</td></tr></table></td></tr></table>';
522 mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color);
523 echo '</td></tr></table>';
524 //$t = elapsed($start);
525 //echo("elapsed time = $t seconds\n");
528 function calc_msort($msgs, $sort) {
539 if (($sort == 0) ||
($sort == 1)) {
540 foreach ($msgs as $item) {
541 $msort[] = $item['TIME_STAMP'];
543 } elseif (($sort == 2) ||
($sort == 3)) {
544 foreach ($msgs as $item) {
545 $msort[] = $item['FROM-SORT'];
547 } elseif (($sort == 4) ||
($sort == 5)) {
548 foreach ($msgs as $item) {
549 $msort[] = $item['SUBJECT-SORT'];
564 function fillMessageArray($imapConnection, $id, $count, $show_num=false) {
565 return sqimap_get_small_header_list($imapConnection, $id, $show_num);
569 /* Generic function to convert the msgs array into an HTML table. */
570 function displayMessageArray($imapConnection, $num_msgs, $start_msg,
571 $msort, $mailbox, $sort, $color,
572 $show_num, $where=0, $what=0) {
573 global $imapServerAddress, $use_mailbox_cache, $index_order,
574 $indent_array, $thread_sort_messages, $allow_server_sort,
575 $server_sort_order, $PHP_SELF;
577 $res = getEndMessage($start_msg, $show_num, $num_msgs);
578 $start_msg = $res[0];
581 $urlMailbox = urlencode($mailbox);
583 /* get indent level for subject display */
584 if ($thread_sort_messages == 1 && $num_msgs) {
585 $indent_array = get_parent_level($imapConnection);
588 $real_startMessage = $start_msg;
590 if ($end_msg - $start_msg < $show_num - 1) {
591 $end_msg = $end_msg - $start_msg +
1;
593 } else if ($start_msg > $show_num) {
594 $end_msg = $show_num;
598 $endVar = $end_msg +
1;
601 * Loop through and display the info for each message.
602 * ($t is used for the checkbox number)
606 /* messages display */
609 /* if there's no messages in this folder */
612 "<BR><b>" . _("THIS FOLDER IS EMPTY") . "</b><BR> ",
615 'COLSPAN="' . count($index_order) . '"'
618 } elseif ($start_msg == $end_msg) {
619 /* if there's only one message in the box, handle it differently. */
631 } while (isset ($key) && ($k < $i));
632 printMessageInfo($imapConnection, $t, true, $key, $mailbox,
633 $real_startMessage, $where, $what);
642 } while (isset ($key) && ($k < $i));
645 if (!$i ||
$i == $endVar-1) $not_last = false;
646 printMessageInfo($imapConnection, $t, $not_last, $key, $mailbox,
647 $real_startMessage, $where, $what);
652 } while ($i && $i < $endVar);
657 * Displays the standard message list header. To finish the table,
658 * you need to do a "</table></table>";
660 * $moveURL is the URL to submit the delete/move form to
661 * $mailbox is the current mailbox
662 * $sort is the current sorting method (-1 for no sorting available [searches])
663 * $Message is a message that is centered on top of the list
664 * $More is a second line that is left aligned
667 function mail_message_listing_beginning ($imapConnection,
668 $mailbox = '', $sort = -1,
670 $paginator = ' ',
672 global $color, $auto_expunge, $base_uri, $thread_sort_messages,
673 $allow_thread_sort, $allow_server_sort, $server_sort_order,
676 $php_self = $PHP_SELF;
677 /* fix for incorrect $PHP_SELF */
678 if (strpos($php_self, 'move_messages.php')) {
679 $php_self = str_replace('move_messages.php', 'right_main.php', $php_self);
681 $urlMailbox = urlencode($mailbox);
683 if (preg_match('/^(.+)\?.+$/',$php_self,$regs)) {
684 $source_url = $regs[1];
686 $source_url = $php_self;
692 $moveFields = '<input type="hidden" name="msg" value="'.htmlspecialchars($msg).'">' .
693 '<input type="hidden" name="mailbox" value="'.htmlspecialchars($mailbox).'">' .
694 '<input type="hidden" name="startMessage" value="'.htmlspecialchars($start_msg).'">';
696 // $moveURL = "move_messages.php?msg=$msg&mailbox=$urlMailbox"
697 // . "&startMessage=$start_msg";
699 * This is the beginning of the message list table.
700 * It wraps around all messages
702 $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $mailbox);
703 $form_name = "FormMsgs" . $safe_name;
704 echo '<form name="' . $form_name . '" method="post" action="move_messages.php">' ."\n"
706 . html_tag( 'table' ,
711 html_tag( 'td', $paginator, 'left' ) .
712 html_tag( 'td', $msg_cnt_str, 'right' )
714 , '', $color[4], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
717 , '', '', 'border="0" width="100%" cellpadding="1" cellspacing="0"' );
718 /* line between header and button area */
719 echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>';
722 echo html_tag( 'tr' ) . "\n"
723 . html_tag( 'td' ,'' , 'left', '', '' )
724 . html_tag( 'table' ,'' , '', $color[9], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
726 . html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
728 getSmallStringCell(_("Move Selected To"), 'left', 'nowrap') .
729 getSmallStringCell(_("Transform Selected Messages"), 'right')
731 . html_tag( 'tr' ) ."\n"
732 . html_tag( 'td', '', 'left', '', 'valign="middle" nowrap' );
733 getMbxList($imapConnection);
734 echo getButton('SUBMIT', 'moveButton',_("Move")) . "\n";
735 echo getButton('SUBMIT', 'attache',_("Forward")) . "\n";
738 . html_tag( 'td', '', 'right', '', 'nowrap' );
742 if (!$auto_expunge) {
743 echo getButton('SUBMIT', 'expungeButton',_("Expunge"))
744 .' ' . _("mailbox") . "\n";
746 do_hook('mailbox_display_buttons');
747 echo getButton('SUBMIT', 'markRead',_("Read"));
748 echo getButton('SUBMIT', 'markUnread',_("Unread"));
749 echo getButton('SUBMIT', 'delete',_("Delete")) ." \n";
750 if (!strpos($php_self,'mailbox')) {
751 $location = $php_self.'?mailbox=INBOX&startMessage=1';
753 $location = $php_self;
755 echo '<INPUT TYPE="HIDDEN" NAME="location" VALUE="'.$location.'">';
759 /* draws thread sorting links */
760 if ($allow_thread_sort == TRUE) {
761 if ($thread_sort_messages == 1 ) {
763 $thread_name = _("Unthread View");
764 } elseif ($thread_sort_messages == 0) {
766 $thread_name = _("Thread View");
768 echo html_tag( 'tr' ,
770 ' <a href=' . $source_url . '?sort='
771 . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
772 . '&mailbox=' . urlencode($mailbox) . '><small>' . $thread_name
773 . '</a></small> '
774 , '', '', '' ) . html_tag( 'td', _("Bypass Trash") . '<input type="checkbox" name="bypass_trash">','right','','')
779 echo "</TABLE></td></tr></table></td></tr>\n";
781 do_hook('mailbox_form_before');
783 /* if using server sort we highjack the
784 * the $sort var and use $server_sort_order
785 * instead. but here we reset sort for a bit
788 if ($allow_server_sort == TRUE) {
789 $sort = $server_sort_order;
793 function mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color) {
795 /* space between list and footer */
796 echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'" COLSPAN="1">';
798 echo '</td></tr><tr><td>';
799 echo html_tag( 'table',
804 html_tag( 'td', $paginator_str ) .
805 html_tag( 'td', $msg_cnt_str, 'right' )
807 , '', $color[4], 'width="100%" border="0" cellpadding="1" cellspacing="0"' )
810 , '', $color[9], 'width="100%" border="0" cellpadding="1" cellspacing="0"' );
813 /* End of message-list table */
815 do_hook('mailbox_index_after');
819 function printHeader($mailbox, $sort, $color, $showsort=true) {
821 echo html_tag( 'tr' ,'' , 'center', $color[5] );
823 /* calculate the width of the subject column based on the
824 * widths of the other columns */
825 $widths = array(1=>1,2=>25,3=>5,4=>0,5=>1,6=>5);
827 foreach($index_order as $item) {
828 $subjectwidth -= $widths[$item];
831 foreach ($index_order as $item) {
833 case 1: /* checkbox */
835 echo html_tag( 'td' ,' ' , '', '', 'width="1%"' );
838 if (handleAsSent($mailbox)) {
839 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
840 . '<b>' . _("To") . '</b>';
842 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
843 . '<b>' . _("From") . '</b>';
846 ShowSortButton($sort, $mailbox, 2, 3);
851 echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
852 . '<b>' . _("Date") . '</b>';
854 ShowSortButton($sort, $mailbox, 0, 1);
858 case 4: /* subject */
859 echo html_tag( 'td' ,'' , 'left', '', 'width="'.$subjectwidth.'%"' )
860 . '<b>' . _("Subject") . '</b>';
862 ShowSortButton($sort, $mailbox, 4, 5);
867 echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%" nowrap' );
876 * This function shows the sort button. Isn't this a good comment?
878 function ShowSortButton($sort, $mailbox, $Up, $Down ) {
880 /* Figure out which image we want to use. */
881 if ($sort != $Up && $sort != $Down) {
882 $img = 'sort_none.png';
884 } elseif ($sort == $Up) {
885 $img = 'up_pointer.png';
888 $img = 'down_pointer.png';
892 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
893 $source_url = $regs[1];
895 $source_url = $PHP_SELF;
898 /* Now that we have everything figured out, show the actual button. */
899 echo ' <a href="' . $source_url .'?newsort=' . $which
900 . '&startMessage=1&mailbox=' . urlencode($mailbox)
901 . '"><img src="../images/' . $img
902 . '" border="0" width="12" height="10" alt="sort" title="'
903 . _("Click here to change the sorting of the message list") .'"></a>';
906 function get_selectall_link($start_msg, $sort) {
907 global $checkall, $what, $where, $mailbox, $javascript_on;
908 global $PHP_SELF, $PG_SHOWNUM;
911 if ($javascript_on) {
912 $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $mailbox);
913 $func_name = "CheckAll" . $safe_name;
914 $form_name = "FormMsgs" . $safe_name;
915 $result = '<script language="JavaScript" type="text/javascript">'
917 . "function " . $func_name . "() {\n"
918 . " for (var i = 0; i < document." . $form_name . ".elements.length; i++) {\n"
919 . " if(document." . $form_name . ".elements[i].type == 'checkbox' && "
920 . "document." . $form_name . ".elements[i].name != 'bypass_trash'){\n"
921 . " document." . $form_name . ".elements[i].checked = "
922 . " !(document." . $form_name . ".elements[i].checked);\n"
927 . '</script><a href="javascript:void(0)" onClick="' . $func_name . '();">' . _("Toggle All")
928 /* . '</script><a href="javascript:' . $func_name . '()">' . _("Toggle All")*/
931 if (strpos($PHP_SELF, "?")) {
932 $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($mailbox)
933 . "&startMessage=$start_msg&sort=$sort&checkall=";
935 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
936 . "&startMessage=$start_msg&sort=$sort&checkall=";
938 if (isset($checkall) && $checkall == '1') {
944 if (isset($where) && isset($what)) {
945 $result .= '&where=' . urlencode($where)
946 . '&what=' . urlencode($what);
950 if (isset($checkall) && ($checkall == '1')) {
951 $result .= _("Unselect All");
953 $result .= _("Select All");
958 /* Return our final result. */
963 * This function computes the "Viewing Messages..." string.
965 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
966 /* Compute the $msg_cnt_str. */
968 if ($start_msg < $end_msg) {
969 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"),
970 $start_msg, $end_msg, $num_msgs);
971 } else if ($start_msg == $end_msg) {
972 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
976 /* Return our result string. */
981 * Generate a paginator link.
983 function get_paginator_link($box, $start_msg, $use, $text) {
986 $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
987 . "&startMessage=$start_msg&mailbox=$box\" "
988 . "TARGET=\"right\">$text</A>";
991 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
992 $source_url = $regs[1];
994 $source_url = $PHP_SELF;
997 $result = '<A HREF="'. $source_url . "?use_mailbox_cache=$use"
998 . "&startMessage=$start_msg&mailbox=$box\" "
999 . "TARGET=\"right\">$text</A>";
1005 * This function computes the paginator string.
1007 function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
1009 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
1011 /* Initialize paginator string chunks. */
1018 $box = urlencode($box);
1020 /* Create simple strings that will be creating the paginator. */
1021 $spc = ' '; /* This will be used as a space. */
1022 $sep = '|'; /* This will be used as a seperator. */
1024 /* Get some paginator preference values. */
1025 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON
);
1026 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
);
1028 /* Make sure that our start message number is not too big. */
1029 $start_msg = min($start_msg, $num_msgs);
1031 /* Decide whether or not we will use the mailbox cache. */
1032 /* Not sure why $use_mailbox_cache is even passed in. */
1039 /* Compute the starting message of the previous and next page group. */
1040 $next_grp = $start_msg +
$show_num;
1041 $prev_grp = $start_msg - $show_num;
1043 /* Compute the basic previous and next strings. */
1044 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
1045 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1046 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1047 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
1048 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1049 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
1050 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
1051 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
1052 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1055 /* Page selector block. Following code computes page links. */
1056 if ($pg_sel && ($num_msgs > $show_num)) {
1057 /* Most importantly, what is the current page!!! */
1058 $cur_pg = intval($start_msg / $show_num) +
1;
1060 /* Compute total # of pages and # of paginator page links. */
1061 $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
1062 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
1064 /* Compute the size of the four quarters of the page links. */
1066 /* If we can, just show all the pages. */
1067 if (($tot_pgs - 1) <= $pg_max) {
1068 $q1_pgs = $cur_pg - 1;
1069 $q2_pgs = $q3_pgs = 0;
1070 $q4_pgs = $tot_pgs - $cur_pg;
1072 /* Otherwise, compute some magic to choose the four quarters. */
1075 * Compute the magic base values. Added together,
1076 * these values will always equal to the $pag_pgs.
1077 * NOTE: These are DEFAULT values and do not take
1078 * the current page into account. That is below.
1080 $q1_pgs = floor($vis_pgs/4);
1081 $q2_pgs = round($vis_pgs/4, 0);
1082 $q3_pgs = ceil($vis_pgs/4);
1083 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
1085 /* Adjust if the first quarter contains the current page. */
1086 if (($cur_pg - $q1_pgs) < 1) {
1087 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) +
$q2_pgs;
1088 $q1_pgs = $cur_pg - 1;
1090 $q3_pgs +
= ceil($extra_pgs / 2);
1091 $q4_pgs +
= floor($extra_pgs / 2);
1093 /* Adjust if the first and second quarters intersect. */
1094 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
1095 $extra_pgs = $q2_pgs;
1096 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1097 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1098 $q3_pgs +
= ceil($extra_pgs / 2);
1099 $q4_pgs +
= floor($extra_pgs / 2);
1101 /* Adjust if the fourth quarter contains the current page. */
1102 } else if (($cur_pg +
$q4_pgs) >= $tot_pgs) {
1103 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) +
$q3_pgs;
1105 $q4_pgs = $tot_pgs - $cur_pg;
1106 $q1_pgs +
= floor($extra_pgs / 2);
1107 $q2_pgs +
= ceil($extra_pgs / 2);
1109 /* Adjust if the third and fourth quarter intersect. */
1110 } else if (($cur_pg +
$q3_pgs +
1) >= ($tot_pgs - $q4_pgs +
1)) {
1111 $extra_pgs = $q3_pgs;
1112 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1113 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1114 $q1_pgs +
= floor($extra_pgs / 2);
1115 $q2_pgs +
= ceil($extra_pgs / 2);
1120 * I am leaving this debug code here, commented out, because
1121 * it is a really nice way to see what the above code is doing.
1122 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
1123 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
1126 /* Print out the page links from the compute page quarters. */
1128 /* Start with the first quarter. */
1129 if (($q1_pgs == 0) && ($cur_pg > 1)) {
1130 $pg_str .= "...$spc";
1132 for ($pg = 1; $pg <= $q1_pgs; ++
$pg) {
1133 $start = (($pg-1) * $show_num) +
1;
1134 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1136 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
1137 $pg_str .= "...$spc";
1141 /* Continue with the second quarter. */
1142 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++
$pg) {
1143 $start = (($pg-1) * $show_num) +
1;
1144 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1147 /* Now print the current page. */
1148 $pg_str .= $cur_pg . $spc;
1150 /* Next comes the third quarter. */
1151 for ($pg = $cur_pg +
1; $pg <= $cur_pg +
$q3_pgs; ++
$pg) {
1152 $start = (($pg-1) * $show_num) +
1;
1153 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1156 /* And last, print the forth quarter page links. */
1157 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
1158 $pg_str .= "...$spc";
1160 if (($tot_pgs - $q4_pgs) > ($cur_pg +
$q3_pgs)) {
1161 $pg_str .= "...$spc";
1163 for ($pg = $tot_pgs - $q4_pgs +
1; $pg <= $tot_pgs; ++
$pg) {
1164 $start = (($pg-1) * $show_num) +
1;
1165 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1168 } else if ($PG_SHOWNUM == 999999) {
1169 $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
1170 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1171 . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc;
1174 /* If necessary, compute the 'show all' string. */
1175 if (($prv_str != '') ||
($nxt_str != '')) {
1176 $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
1177 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1178 . "TARGET=\"right\">" . _("Show All") . '</A>';
1181 /* Last but not least, get the value for the toggle all link. */
1182 $tgl_str = get_selectall_link($start_msg, $sort);
1184 /* Put all the pieces of the paginator string together. */
1186 * Hairy code... But let's leave it like it is since I am not certain
1187 * a different approach would be any easier to read. ;)
1190 $result .= ($prv_str != '' ?
$prv_str . $spc . $sep . $spc : '');
1191 $result .= ($nxt_str != '' ?
$nxt_str . $spc . $sep . $spc : '');
1192 $result .= ($pg_str != '' ?
$pg_str : '');
1193 $result .= ($all_str != '' ?
$sep . $spc . $all_str . $spc : '');
1194 $result .= ($result != '' ?
$sep . $spc . $tgl_str: $tgl_str);
1196 /* If the resulting string is blank, return a non-breaking space. */
1197 if ($result == '') {
1201 /* Return our final magical paginator string. */
1205 function processSubject($subject, $threadlevel = 0) {
1206 global $languages, $squirrelmail_language;
1207 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1208 if ($subject == '') {
1209 return _("(no subject)");
1212 $trim_at = SUBJ_TRIM_AT
;
1214 /* if this is threaded, subtract two chars per indentlevel */
1215 if($threadlevel > 0 && $threadlevel <= 10) {
1216 $trim_at -= (2*$threadlevel);
1219 if (strlen($subject) <= $trim_at) {
1223 $ent_strlen = $orig_len = strlen($subject);
1224 $trim_val = $trim_at - 5;
1227 * see if this is entities-encoded string
1228 * If so, Iterate through the whole string, find out
1229 * the real number of characters, and if more
1230 * than 55, substr with an updated trim value.
1232 $step = $ent_loc = 0;
1233 while ( $ent_loc < $trim_val && (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1234 (($ent_loc_end = strpos($subject, ';', $ent_loc+
3)) !== false) ) {
1235 $trim_val +
= ($ent_loc_end-$ent_loc);
1236 $ent_offset = $ent_loc_end+
1;
1240 if (($trim_val > 50) && (strlen($subject) > ($trim_val))&& (strpos($subject,';',$trim_val) < ($trim_val +
6))) {
1241 $i = strpos($subject,';',$trim_val);
1243 $trim_val = strpos($subject,';',$trim_val);
1246 if ($ent_strlen <= $trim_at){
1250 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
1251 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
1252 return $languages[$squirrelmail_language]['XTRA_CODE']('strimwidth', $subject, $trim_val);
1255 // only print '...' when we're actually dropping part of the subject
1256 if(strlen($subject) <= $trim_val) {
1259 return substr($subject, 0, $trim_val) . '...';
1263 function getMbxList($imapConnection, $boxes = 0) {
1264 global $lastTargetMailbox;
1265 echo ' <small> <tt><select name="targetMailbox">';
1266 echo sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)), 0, $boxes);
1267 echo ' </SELECT></TT> ';
1270 function getButton($type, $name, $value) {
1271 return '<INPUT TYPE="'.$type.'" NAME="'.$name.'" VALUE="'.$value . '">';
1274 function getSmallStringCell($string, $align) {
1275 return html_tag('td',
1276 '<small>' . $string . ': </small>',
1282 function getEndMessage($start_msg, $show_num, $num_msgs) {
1283 if ($start_msg +
($show_num - 1) < $num_msgs){
1284 $end_msg = $start_msg +
($show_num - 1);
1286 $end_msg = $num_msgs;
1289 if ($end_msg < $start_msg) {
1290 $start_msg = $start_msg - $show_num;
1291 if ($start_msg < 1) {
1295 return (array($start_msg,$end_msg));
1298 function handleAsSent($mailbox) {
1299 global $handleAsSent_result;
1301 /* First check if this is the sent or draft folder. */
1302 $handleAsSent_result = isSentMailbox($mailbox) ||
isDraftMailbox($mailbox);
1304 /* Then check the result of the handleAsSent hook. */
1305 do_hook('check_handleAsSent_result', $mailbox);
1307 /* And return the result. */
1308 return $handleAsSent_result;