2f14e7b13e64c7c629583e70c3f261e79966bf40
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');
21 * PG_SEL_MAX: default value for page_selector_max
22 * SUBJ_TRIM_AT: the length at which we trim off subjects
24 define('PG_SEL_MAX', 10);
25 define('SUBJ_TRIM_AT', 55);
27 function elapsed($start)
30 list($start2, $start1) = explode(" ", $start);
31 list($end2, $end1) = explode(" ", $end);
32 $diff1 = $end1 - $start1;
33 $diff2 = $end2 - $start2;
38 return $diff2 +
$diff1;
41 function printMessageInfo($imapConnection, $t, $not_last=true, $key, $mailbox,
42 $start_msg, $where, $what) {
44 $color, $msgs, $msort, $td_str, $msg,
45 $default_use_priority,
46 $message_highlight_list,
48 $indent_array, /* indent subject by */
49 $pos, /* Search postion (if any) */
50 $thread_sort_messages, /* thread sorting on/off */
51 $server_sort_order, /* sort value when using server-sorting */
53 $allow_server_sort, /* enable/disable server-side sorting */
54 $truncate_sender; /* number of characters for From/To field (<= 0 for unchanged) */
56 $color_string = $color[4];
58 if ($GLOBALS['alt_index_colors']) {
59 if (!isset($row_count)) {
64 if (!isset($color[12])) {
65 $color[12] = '#EAEAEA';
67 $color_string = $color[12];
72 if($mailbox == 'None') {
73 $boxes = sqimap_mailbox_list($imapConnection);
74 $mailbox = $boxes[0]['unformatted'];
77 $urlMailbox = urlencode($mailbox);
79 if (handleAsSent($mailbox)) {
80 $msg['FROM'] = $msg['TO'];
82 $msg['FROM'] = parseAddress($msg['FROM'],1);
85 * This is done in case you're looking into Sent folders,
86 * because you can have multiple receivers.
89 $senderNames = $msg['FROM'];
91 if (sizeof($senderNames)){
92 foreach ($senderNames as $senderNames_part) {
93 if ($senderName != '') {
96 if ($senderNames_part[1]) {
97 $senderName .= decodeHeader($senderNames_part[1]);
99 $senderName .= htmlspecialchars($senderNames_part[0]);
103 $senderName = str_replace(' ',' ',$senderName);
105 if ( $truncate_sender > 0 && strlen($senderName) > $truncate_sender ) {
106 $senderName = substr_replace($senderName, '... ', $truncate_sender);
109 echo html_tag( 'tr','','','','VALIGN="top"') . "\n";
111 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
112 $flag = "<font color=\"$color[2]\">";
113 $flag_end = '</font>';
118 if (!isset($msg['FLAG_SEEN']) ||
($msg['FLAG_SEEN'] == false)) {
125 if (handleAsSent($mailbox)) {
127 $italic_end = '</i>';
132 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
133 $fontstr = "<font color=\"$color[9]\">";
134 $fontstr_end = '</font>';
140 if ($where && $what) {
141 $searchstr = '&where='.$where.'&what='.$what;
146 if (is_array($message_highlight_list) && count($message_highlight_list)) {
147 $msg['TO'] = parseAddress($msg['TO']);
148 $msg['CC'] = parseAddress($msg['CC']);
149 foreach ($message_highlight_list as $message_highlight_list_part) {
150 if (trim($message_highlight_list_part['value']) != '') {
151 $high_val = strtolower($message_highlight_list_part['value']);
152 $match_type = strtoupper($message_highlight_list_part['match_type']);
153 if($match_type == 'TO_CC') {
154 $match = array('TO', 'CC');
156 $match = array($match_type);
158 foreach($match as $match_type) {
159 switch($match_type) {
163 foreach ($msg[$match_type] as $address) {
164 $address[0] = decodeHeader($address[0], true, false);
165 $address[1] = decodeHeader($address[1], true, false);
166 if (strstr('^^' . strtolower($address[0]), $high_val) ||
167 strstr('^^' . strtolower($address[1]), $high_val)) {
168 $hlt_color = $message_highlight_list_part['color'];
174 $headertest = strtolower(decodeHeader($msg[$match_type], true, false));
175 if (strstr('^^' . $headertest, $high_val)) {
176 $hlt_color = $message_highlight_list_part['color'];
186 if (!isset($hlt_color)) {
187 $hlt_color = $color_string;
189 $checked = ($checkall == 1) ?
' CHECKED' : '';
191 $msg['SUBJECT'] = decodeHeader($msg['SUBJECT']);
192 $subject = processSubject($msg['SUBJECT'], $indent_array[$msg['ID']]);
193 $subject = str_replace(' ',' ',$subject);
194 if (sizeof($index_order)) {
195 foreach ($index_order as $index_order_part) {
196 switch ($index_order_part) {
197 case 1: /* checkbox */
199 "<input type=checkbox name=\"msg[$t]\" value=\"".$msg['ID']."\"$checked>",
205 $italic . $bold . $flag . $fontstr . $senderName .
206 $fontstr_end . $flag_end . $bold_end . $italic_end,
211 $date_string = $msg['DATE_STRING'] . '';
212 if ($date_string == '') {
213 $date_string = _("Unknown date");
216 $bold . $flag . $fontstr . $date_string .
217 $fontstr_end . $flag_end . $bold_end,
222 case 4: /* subject */
224 if ($thread_sort_messages == 1) {
225 if (isset($indent_array[$msg['ID']])) {
226 $td_str .= str_repeat(" ",$indent_array[$msg['ID']]);
229 $td_str .= '<a href="read_body.php?mailbox='.$urlMailbox
230 . '&passed_id='. $msg["ID"]
231 . '&startMessage='.$start_msg.$searchstr.'"';
232 $td_str .= ' ' .concat_hook_function('subject_link', array($start_msg, $searchstr));
233 if ($subject != $msg['SUBJECT']) {
234 $title = get_html_translation_table(HTML_SPECIALCHARS
);
235 $title = array_flip($title);
236 $title = strtr($msg['SUBJECT'], $title);
237 $title = str_replace('"', "''", $title);
238 $td_str .= " title=\"$title\"";
240 $td_str .= ">$flag$subject$flag_end</a>$bold_end";
241 echo html_tag( 'td', $td_str, 'left', $hlt_color );
245 $td_str = "<b><small>";
247 if (isset($msg['FLAG_ANSWERED']) && $msg['FLAG_ANSWERED'] == true) {
251 if ($msg['TYPE0'] == 'multipart') {
255 if ($default_use_priority) {
256 if ( ($msg['PRIORITY'] == 1) ||
($msg['PRIORITY'] == 2) ) {
257 $td_str .= "<font color=\"$color[1]\">!</font>";
260 if ($msg['PRIORITY'] == 5) {
261 $td_str .= "<font color=\"$color[8]\">?</font>";
265 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'] == true) {
266 $td_str .= "<font color=\"$color[1]\">D</font>";
272 do_hook("msg_envelope");
273 $td_str .= '</small></b>';
282 $bold . $fontstr . show_readable_size($msg['SIZE']) .
283 $fontstr_end . $bold_end,
292 echo '</tr>' . "\n" . '<tr><td COLSPAN="' . $col . '" BGCOLOR="' .
293 $color[0] . '" HEIGHT="1"></td></tr>' . "\n";
299 function getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id) {
301 $id = array_slice($id, ($start_msg-1), $show_num);
302 $end = $start_msg +
$show_num - 1;
303 if ($num_msgs < $show_num) {
304 $end_loop = $num_msgs;
305 } else if ($end > $num_msgs) {
306 $end_loop = $num_msgs - $start_msg +
1;
308 $end_loop = $show_num;
310 return fillMessageArray($imapConnection,$id,$end_loop,$show_num);
316 function getThreadMessages($imapConnection, $start_msg, $show_num, $num_msgs) {
317 $id = get_thread_sort($imapConnection);
318 return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
321 function getServerSortMessages($imapConnection, $start_msg, $show_num,
322 $num_msgs, $server_sort_order, $mbxresponse) {
323 $id = sqimap_get_sort_order($imapConnection, $server_sort_order,$mbxresponse);
324 return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
327 function getSelfSortMessages($imapConnection, $start_msg, $show_num,
328 $num_msgs, $sort, $mbxresponse) {
330 if ($num_msgs >= 1) {
331 $id = sqimap_get_php_sort_order ($imapConnection, $mbxresponse);
335 /* set shownum to 999999 to fool sqimap_get_small_header_list
336 and rebuild the msgs_str to 1:* */
339 /* if it's not sorted */
340 if ($start_msg +
($show_num - 1) < $num_msgs) {
341 $end_msg = $start_msg +
($show_num - 1);
343 $end_msg = $num_msgs;
345 if ($end_msg < $start_msg) {
346 $start_msg = $start_msg - $show_num;
347 if ($start_msg < 1) {
351 $id = array_slice(array_reverse($id), ($start_msg-1), $show_num);
352 $end = $start_msg +
$show_num - 1;
353 if ($num_msgs < $show_num) {
354 $end_loop = $num_msgs;
355 } else if ($end > $num_msgs) {
356 $end_loop = $num_msgs - $start_msg +
1;
358 $end_loop = $show_num;
361 $msgs = fillMessageArray($imapConnection,$id,$end_loop, $show_num);
369 * This function loops through a group of messages in the mailbox
370 * and shows them to the user.
372 function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
373 $start_msg, $sort, $color, $show_num,
374 $use_cache, $mode='') {
375 global $msgs, $msort, $auto_expunge, $thread_sort_messages,
376 $allow_server_sort, $server_sort_order;
379 * For some reason, on PHP 4.3+, this being unset, and set in the session causes havoc
380 * so setting it to an empty array beforehand seems to clean up the issue, and stopping the
381 * "Your script possibly relies on a session side-effect which existed until PHP 4.2.3" error
384 if (!isset($msort)) {
392 //$start = microtime();
393 /* If autoexpunge is turned on, then do it now. */
394 $mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox);
396 /* If autoexpunge is turned on, then do it now. */
397 if ($auto_expunge == true) {
398 $exp_cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, false, '');
399 $mbxresponse['EXISTS'] = $mbxresponse['EXISTS'] - $exp_cnt;
400 $num_msgs = $mbxresponse['EXISTS'];
403 if ($mbxresponse['EXISTS'] > 0) {
404 /* if $start_msg is lower than $num_msgs, we probably deleted all messages
405 * in the last page. We need to re-adjust the start_msg
408 if($start_msg > $num_msgs) {
409 $start_msg -= $show_num;
415 /* This code and the next if() block check for
416 * server-side sorting methods. The $id array is
417 * formatted and $sort is set to 6 to disable
418 * SM internal sorting
421 if ($thread_sort_messages == 1) {
423 } elseif ($allow_server_sort == 1) {
424 $mode = 'serversort';
430 sqgetGlobalVar('msgs', $msgs, SQ_SESSION
);
431 sqgetGlobalVar('msort', $msort, SQ_SESSION
);
433 sqsession_unregister('msort');
434 sqsession_unregister('msgs'); }
437 $id = get_thread_sort($imapConnection);
438 $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
439 if ($msgs === false) {
440 echo '<b><small><center><font color=red>' .
441 _("Thread sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
442 '</center></small></b>';
443 $thread_sort_messages = 0;
444 $msort = $msgs = array();
451 $id = sqimap_get_sort_order($imapConnection, $sort, $mbxresponse);
452 $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
453 if ($msgs === false) {
454 echo '<b><small><center><font color=red>' .
455 _( "Server-side sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
456 '</center></small></b>';
457 $sort = $server_sort_order;
458 $allow_server_sort = FALSE;
459 $msort = $msgs = array();
468 $msgs = getSelfSortMessages($imapConnection, $start_msg, $show_num,
469 $num_msgs, $sort, $mbxresponse);
470 $msort = calc_msort($msgs, $sort);
474 sqsession_register($msort, 'msort');
475 sqsession_register($msgs, 'msgs');
477 } /* if exists > 0 */
479 $res = getEndMessage($start_msg, $show_num, $num_msgs);
480 $start_msg = $res[0];
483 $paginator_str = get_paginator_str($mailbox, $start_msg, $end_msg,
484 $num_msgs, $show_num, $sort);
486 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
488 do_hook('mailbox_index_before');
489 echo '<table border="0" width="100%" cellpadding="0" cellspacing="0">';
492 mail_message_listing_beginning($imapConnection, $mailbox, $sort,
493 $msg_cnt_str, $paginator_str, $start_msg);
495 /* line between the button area and the list */
496 echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>';
499 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
501 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[5].'">';
503 printHeader($mailbox, $srt, $color, !$thread_sort_messages);
505 displayMessageArray($imapConnection, $num_msgs, $start_msg,
506 $msort, $mailbox, $sort, $color, $show_num,0,0);
507 echo '</td></tr></table></td></tr></table>';
509 mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color);
510 echo '</td></tr></table>';
511 //$t = elapsed($start);
512 //echo("elapsed time = $t seconds\n");
515 function calc_msort($msgs, $sort) {
526 if (($sort == 0) ||
($sort == 1)) {
527 foreach ($msgs as $item) {
528 $msort[] = $item['TIME_STAMP'];
530 } elseif (($sort == 2) ||
($sort == 3)) {
531 foreach ($msgs as $item) {
532 $msort[] = $item['FROM-SORT'];
534 } elseif (($sort == 4) ||
($sort == 5)) {
535 foreach ($msgs as $item) {
536 $msort[] = $item['SUBJECT-SORT'];
551 function fillMessageArray($imapConnection, $id, $count, $show_num=false) {
552 return sqimap_get_small_header_list($imapConnection, $id, $show_num);
556 /* Generic function to convert the msgs array into an HTML table. */
557 function displayMessageArray($imapConnection, $num_msgs, $start_msg,
558 $msort, $mailbox, $sort, $color,
559 $show_num, $where=0, $what=0) {
560 global $imapServerAddress, $use_mailbox_cache, $index_order,
561 $indent_array, $thread_sort_messages, $allow_server_sort,
562 $server_sort_order, $PHP_SELF;
564 $res = getEndMessage($start_msg, $show_num, $num_msgs);
565 $start_msg = $res[0];
568 $urlMailbox = urlencode($mailbox);
570 /* get indent level for subject display */
571 if ($thread_sort_messages == 1 && $num_msgs) {
572 $indent_array = get_parent_level($imapConnection);
575 $real_startMessage = $start_msg;
577 if ($end_msg - $start_msg < $show_num - 1) {
578 $end_msg = $end_msg - $start_msg +
1;
580 } else if ($start_msg > $show_num) {
581 $end_msg = $show_num;
585 $endVar = $end_msg +
1;
588 * Loop through and display the info for each message.
589 * ($t is used for the checkbox number)
593 /* messages display */
596 /* if there's no messages in this folder */
599 "<BR><b>" . _("THIS FOLDER IS EMPTY") . "</b><BR> ",
602 'COLSPAN="' . count($index_order) . '"'
605 } elseif ($start_msg == $end_msg) {
606 /* if there's only one message in the box, handle it differently. */
618 } while (isset ($key) && ($k < $i));
619 printMessageInfo($imapConnection, $t, true, $key, $mailbox,
620 $real_startMessage, $where, $what);
629 } while (isset ($key) && ($k < $i));
632 if (!$i ||
$i == $endVar-1) $not_last = false;
633 printMessageInfo($imapConnection, $t, $not_last, $key, $mailbox,
634 $real_startMessage, $where, $what);
639 } while ($i && $i < $endVar);
644 * Displays the standard message list header. To finish the table,
645 * you need to do a "</table></table>";
647 * $moveURL is the URL to submit the delete/move form to
648 * $mailbox is the current mailbox
649 * $sort is the current sorting method (-1 for no sorting available [searches])
650 * $Message is a message that is centered on top of the list
651 * $More is a second line that is left aligned
654 function mail_message_listing_beginning ($imapConnection,
655 $mailbox = '', $sort = -1,
657 $paginator = ' ',
659 global $color, $auto_expunge, $base_uri, $thread_sort_messages,
660 $allow_thread_sort, $allow_server_sort, $server_sort_order,
663 $php_self = $PHP_SELF;
664 /* fix for incorrect $PHP_SELF */
665 if (strpos($php_self, 'move_messages.php')) {
666 $php_self = str_replace('move_messages.php', 'right_main.php', $php_self);
668 $urlMailbox = urlencode($mailbox);
670 if (preg_match('/^(.+)\?.+$/',$php_self,$regs)) {
671 $source_url = $regs[1];
673 $source_url = $php_self;
679 $moveFields = '<input type="hidden" name="msg" value="'.htmlspecialchars($msg).'">' .
680 '<input type="hidden" name="mailbox" value="'.htmlspecialchars($mailbox).'">' .
681 '<input type="hidden" name="startMessage" value="'.htmlspecialchars($start_msg).'">';
683 // $moveURL = "move_messages.php?msg=$msg&mailbox=$urlMailbox"
684 // . "&startMessage=$start_msg";
686 * This is the beginning of the message list table.
687 * It wraps around all messages
689 $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $mailbox);
690 $form_name = "FormMsgs" . $safe_name;
691 echo '<form name="' . $form_name . '" method="post" action="move_messages.php">' ."\n"
693 . html_tag( 'table' ,
698 html_tag( 'td', $paginator, 'left' ) .
699 html_tag( 'td', $msg_cnt_str, 'right' )
701 , '', $color[4], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
704 , '', '', 'border="0" width="100%" cellpadding="1" cellspacing="0"' );
705 /* line between header and button area */
706 echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>';
709 echo html_tag( 'tr' ) . "\n"
710 . html_tag( 'td' ,'' , 'left', '', '' )
711 . html_tag( 'table' ,'' , '', $color[9], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
713 . html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
715 getSmallStringCell(_("Move Selected To"), 'left', 'nowrap') .
716 getSmallStringCell(_("Transform Selected Messages"), 'right')
718 . html_tag( 'tr' ) ."\n"
719 . html_tag( 'td', '', 'left', '', 'valign="middle" nowrap' );
720 getMbxList($imapConnection);
721 echo getButton('SUBMIT', 'moveButton',_("Move")) . "\n";
722 echo getButton('SUBMIT', 'attache',_("Forward")) . "\n";
725 . html_tag( 'td', '', 'right', '', 'nowrap' );
729 if (!$auto_expunge) {
730 echo getButton('SUBMIT', 'expungeButton',_("Expunge"))
731 .' ' . _("mailbox") . "\n";
733 do_hook('mailbox_display_buttons');
734 echo getButton('SUBMIT', 'markRead',_("Read"));
735 echo getButton('SUBMIT', 'markUnread',_("Unread"));
736 echo getButton('SUBMIT', 'delete',_("Delete")) ." \n";
737 if (!strpos($php_self,'mailbox')) {
738 $location = $php_self.'?mailbox=INBOX&startMessage=1';
740 $location = $php_self;
742 echo '<INPUT TYPE="HIDDEN" NAME="location" VALUE="'.$location.'">';
746 /* draws thread sorting links */
747 if ($allow_thread_sort == TRUE) {
748 if ($thread_sort_messages == 1 ) {
750 $thread_name = _("Unthread View");
751 } elseif ($thread_sort_messages == 0) {
753 $thread_name = _("Thread View");
755 echo html_tag( 'tr' ,
757 ' <a href=' . $source_url . '?sort='
758 . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
759 . '&mailbox=' . urlencode($mailbox) . '><small>' . $thread_name
760 . '</a></small> '
761 , '', '', '' ) . html_tag( 'td', 'Bypass Trash<input type="checkbox" name="bypass_trash">','right','','')
766 echo "</TABLE></td></tr></table></td></tr>\n";
768 do_hook('mailbox_form_before');
770 /* if using server sort we highjack the
771 * the $sort var and use $server_sort_order
772 * instead. but here we reset sort for a bit
775 if ($allow_server_sort == TRUE) {
776 $sort = $server_sort_order;
780 function mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color) {
782 /* space between list and footer */
783 echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'" COLSPAN="1">';
785 echo '</td></tr><tr><td>';
786 echo html_tag( 'table',
791 html_tag( 'td', $paginator_str ) .
792 html_tag( 'td', $msg_cnt_str, 'right' )
794 , '', $color[4], 'width="100%" border="0" cellpadding="1" cellspacing="0"' )
797 , '', $color[9], 'width="100%" border="0" cellpadding="1" cellspacing="0"' );
800 /* End of message-list table */
802 do_hook('mailbox_index_after');
806 function printHeader($mailbox, $sort, $color, $showsort=true) {
808 echo html_tag( 'tr' ,'' , 'center', $color[5] );
810 /* calculate the width of the subject column based on the
811 * widths of the other columns */
812 $widths = array(1=>1,2=>25,3=>5,4=>0,5=>1,6=>5);
814 foreach($index_order as $item) {
815 $subjectwidth -= $widths[$item];
818 foreach ($index_order as $item) {
820 case 1: /* checkbox */
822 echo html_tag( 'td' ,' ' , '', '', 'width="1%"' );
825 if (handleAsSent($mailbox)) {
826 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
827 . '<b>' . _("To") . '</b>';
829 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
830 . '<b>' . _("From") . '</b>';
833 ShowSortButton($sort, $mailbox, 2, 3);
838 echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
839 . '<b>' . _("Date") . '</b>';
841 ShowSortButton($sort, $mailbox, 0, 1);
845 case 4: /* subject */
846 echo html_tag( 'td' ,'' , 'left', '', 'width="'.$subjectwidth.'%"' )
847 . '<b>' . _("Subject") . '</b>';
849 ShowSortButton($sort, $mailbox, 4, 5);
854 echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%" nowrap' );
863 * This function shows the sort button. Isn't this a good comment?
865 function ShowSortButton($sort, $mailbox, $Up, $Down ) {
867 /* Figure out which image we want to use. */
868 if ($sort != $Up && $sort != $Down) {
869 $img = 'sort_none.png';
871 } elseif ($sort == $Up) {
872 $img = 'up_pointer.png';
875 $img = 'down_pointer.png';
879 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
880 $source_url = $regs[1];
882 $source_url = $PHP_SELF;
885 /* Now that we have everything figured out, show the actual button. */
886 echo ' <a href="' . $source_url .'?newsort=' . $which
887 . '&startMessage=1&mailbox=' . urlencode($mailbox)
888 . '"><img src="../images/' . $img
889 . '" border="0" width="12" height="10" alt="sort" title="'
890 . _("Click here to change the sorting of the message list") .'"></a>';
893 function get_selectall_link($start_msg, $sort) {
894 global $checkall, $what, $where, $mailbox, $javascript_on;
895 global $PHP_SELF, $PG_SHOWNUM;
898 if ($javascript_on) {
899 $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $mailbox);
900 $func_name = "CheckAll" . $safe_name;
901 $form_name = "FormMsgs" . $safe_name;
902 $result = '<script language="JavaScript" type="text/javascript">'
904 . "function " . $func_name . "() {\n"
905 . " for (var i = 0; i < document." . $form_name . ".elements.length; i++) {\n"
906 . " if(document." . $form_name . ".elements[i].type == 'checkbox'){\n"
907 . " document." . $form_name . ".elements[i].checked = "
908 . " !(document." . $form_name . ".elements[i].checked);\n"
913 . '</script><a href="javascript:void(0)" onClick="' . $func_name . '();">' . _("Toggle All")
914 /* . '</script><a href="javascript:' . $func_name . '()">' . _("Toggle All")*/
917 if (strpos($PHP_SELF, "?")) {
918 $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($mailbox)
919 . "&startMessage=$start_msg&sort=$sort&checkall=";
921 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
922 . "&startMessage=$start_msg&sort=$sort&checkall=";
924 if (isset($checkall) && $checkall == '1') {
930 if (isset($where) && isset($what)) {
931 $result .= '&where=' . urlencode($where)
932 . '&what=' . urlencode($what);
936 if (isset($checkall) && ($checkall == '1')) {
937 $result .= _("Unselect All");
939 $result .= _("Select All");
944 /* Return our final result. */
949 * This function computes the "Viewing Messages..." string.
951 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
952 /* Compute the $msg_cnt_str. */
954 if ($start_msg < $end_msg) {
955 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"),
956 $start_msg, $end_msg, $num_msgs);
957 } else if ($start_msg == $end_msg) {
958 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
962 /* Return our result string. */
967 * Generate a paginator link.
969 function get_paginator_link($box, $start_msg, $use, $text) {
972 $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
973 . "&startMessage=$start_msg&mailbox=$box\" "
974 . "TARGET=\"right\">$text</A>";
977 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
978 $source_url = $regs[1];
980 $source_url = $PHP_SELF;
983 $result = '<A HREF="'. $source_url . "?use_mailbox_cache=$use"
984 . "&startMessage=$start_msg&mailbox=$box\" "
985 . "TARGET=\"right\">$text</A>";
991 * This function computes the paginator string.
993 function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
995 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
997 /* Initialize paginator string chunks. */
1004 $box = urlencode($box);
1006 /* Create simple strings that will be creating the paginator. */
1007 $spc = ' '; /* This will be used as a space. */
1008 $sep = '|'; /* This will be used as a seperator. */
1010 /* Get some paginator preference values. */
1011 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON
);
1012 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
);
1014 /* Make sure that our start message number is not too big. */
1015 $start_msg = min($start_msg, $num_msgs);
1017 /* Decide whether or not we will use the mailbox cache. */
1018 /* Not sure why $use_mailbox_cache is even passed in. */
1025 /* Compute the starting message of the previous and next page group. */
1026 $next_grp = $start_msg +
$show_num;
1027 $prev_grp = $start_msg - $show_num;
1029 /* Compute the basic previous and next strings. */
1030 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
1031 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1032 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1033 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
1034 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1035 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
1036 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
1037 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
1038 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1041 /* Page selector block. Following code computes page links. */
1042 if ($pg_sel && ($num_msgs > $show_num)) {
1043 /* Most importantly, what is the current page!!! */
1044 $cur_pg = intval($start_msg / $show_num) +
1;
1046 /* Compute total # of pages and # of paginator page links. */
1047 $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
1048 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
1050 /* Compute the size of the four quarters of the page links. */
1052 /* If we can, just show all the pages. */
1053 if (($tot_pgs - 1) <= $pg_max) {
1054 $q1_pgs = $cur_pg - 1;
1055 $q2_pgs = $q3_pgs = 0;
1056 $q4_pgs = $tot_pgs - $cur_pg;
1058 /* Otherwise, compute some magic to choose the four quarters. */
1061 * Compute the magic base values. Added together,
1062 * these values will always equal to the $pag_pgs.
1063 * NOTE: These are DEFAULT values and do not take
1064 * the current page into account. That is below.
1066 $q1_pgs = floor($vis_pgs/4);
1067 $q2_pgs = round($vis_pgs/4, 0);
1068 $q3_pgs = ceil($vis_pgs/4);
1069 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
1071 /* Adjust if the first quarter contains the current page. */
1072 if (($cur_pg - $q1_pgs) < 1) {
1073 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) +
$q2_pgs;
1074 $q1_pgs = $cur_pg - 1;
1076 $q3_pgs +
= ceil($extra_pgs / 2);
1077 $q4_pgs +
= floor($extra_pgs / 2);
1079 /* Adjust if the first and second quarters intersect. */
1080 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
1081 $extra_pgs = $q2_pgs;
1082 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1083 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1084 $q3_pgs +
= ceil($extra_pgs / 2);
1085 $q4_pgs +
= floor($extra_pgs / 2);
1087 /* Adjust if the fourth quarter contains the current page. */
1088 } else if (($cur_pg +
$q4_pgs) >= $tot_pgs) {
1089 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) +
$q3_pgs;
1091 $q4_pgs = $tot_pgs - $cur_pg;
1092 $q1_pgs +
= floor($extra_pgs / 2);
1093 $q2_pgs +
= ceil($extra_pgs / 2);
1095 /* Adjust if the third and fourth quarter intersect. */
1096 } else if (($cur_pg +
$q3_pgs +
1) >= ($tot_pgs - $q4_pgs +
1)) {
1097 $extra_pgs = $q3_pgs;
1098 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1099 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1100 $q1_pgs +
= floor($extra_pgs / 2);
1101 $q2_pgs +
= ceil($extra_pgs / 2);
1106 * I am leaving this debug code here, commented out, because
1107 * it is a really nice way to see what the above code is doing.
1108 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
1109 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
1112 /* Print out the page links from the compute page quarters. */
1114 /* Start with the first quarter. */
1115 if (($q1_pgs == 0) && ($cur_pg > 1)) {
1116 $pg_str .= "...$spc";
1118 for ($pg = 1; $pg <= $q1_pgs; ++
$pg) {
1119 $start = (($pg-1) * $show_num) +
1;
1120 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1122 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
1123 $pg_str .= "...$spc";
1127 /* Continue with the second quarter. */
1128 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++
$pg) {
1129 $start = (($pg-1) * $show_num) +
1;
1130 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1133 /* Now print the current page. */
1134 $pg_str .= $cur_pg . $spc;
1136 /* Next comes the third quarter. */
1137 for ($pg = $cur_pg +
1; $pg <= $cur_pg +
$q3_pgs; ++
$pg) {
1138 $start = (($pg-1) * $show_num) +
1;
1139 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1142 /* And last, print the forth quarter page links. */
1143 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
1144 $pg_str .= "...$spc";
1146 if (($tot_pgs - $q4_pgs) > ($cur_pg +
$q3_pgs)) {
1147 $pg_str .= "...$spc";
1149 for ($pg = $tot_pgs - $q4_pgs +
1; $pg <= $tot_pgs; ++
$pg) {
1150 $start = (($pg-1) * $show_num) +
1;
1151 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1154 } else if ($PG_SHOWNUM == 999999) {
1155 $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
1156 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1157 . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc;
1160 /* If necessary, compute the 'show all' string. */
1161 if (($prv_str != '') ||
($nxt_str != '')) {
1162 $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
1163 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1164 . "TARGET=\"right\">" . _("Show All") . '</A>';
1167 /* Last but not least, get the value for the toggle all link. */
1168 $tgl_str = get_selectall_link($start_msg, $sort);
1170 /* Put all the pieces of the paginator string together. */
1172 * Hairy code... But let's leave it like it is since I am not certain
1173 * a different approach would be any easier to read. ;)
1176 $result .= ($prv_str != '' ?
$prv_str . $spc . $sep . $spc : '');
1177 $result .= ($nxt_str != '' ?
$nxt_str . $spc . $sep . $spc : '');
1178 $result .= ($pg_str != '' ?
$pg_str : '');
1179 $result .= ($all_str != '' ?
$sep . $spc . $all_str . $spc : '');
1180 $result .= ($result != '' ?
$sep . $spc . $tgl_str: $tgl_str);
1182 /* If the resulting string is blank, return a non-breaking space. */
1183 if ($result == '') {
1187 /* Return our final magical paginator string. */
1191 function processSubject($subject, $threadlevel = 0) {
1192 global $languages, $squirrelmail_language;
1193 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1194 if ($subject == '') {
1195 return _("(no subject)");
1198 $trim_at = SUBJ_TRIM_AT
;
1200 /* if this is threaded, subtract two chars per indentlevel */
1201 if($threadlevel > 0 && $threadlevel <= 10) {
1202 $trim_at -= (2*$threadlevel);
1205 if (strlen($subject) <= $trim_at) {
1209 $ent_strlen = $orig_len = strlen($subject);
1210 $trim_val = $trim_at - 5;
1213 * see if this is entities-encoded string
1214 * If so, Iterate through the whole string, find out
1215 * the real number of characters, and if more
1216 * than 55, substr with an updated trim value.
1218 $step = $ent_loc = 0;
1219 while ( $ent_loc < $trim_val && (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1220 (($ent_loc_end = strpos($subject, ';', $ent_loc+
3)) !== false) ) {
1221 $trim_val +
= ($ent_loc_end-$ent_loc);
1222 $ent_offset = $ent_loc_end+
1;
1226 if (($trim_val > 50) && (strlen($subject) > ($trim_val))&& (strpos($subject,';',$trim_val) < ($trim_val +
6))) {
1227 $i = strpos($subject,';',$trim_val);
1229 $trim_val = strpos($subject,';',$trim_val);
1232 if ($ent_strlen <= $trim_at){
1236 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
1237 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
1238 return $languages[$squirrelmail_language]['XTRA_CODE']('strimwidth', $subject, $trim_val);
1241 // only print '...' when we're actually dropping part of the subject
1242 if(strlen($subject) <= $trim_val) {
1245 return substr($subject, 0, $trim_val) . '...';
1249 function getMbxList($imapConnection) {
1250 global $lastTargetMailbox;
1251 echo ' <small> <tt><select name="targetMailbox">';
1252 echo sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)) );
1253 echo ' </SELECT></TT> ';
1256 function getButton($type, $name, $value) {
1257 return '<INPUT TYPE="'.$type.'" NAME="'.$name.'" VALUE="'.$value . '">';
1260 function getSmallStringCell($string, $align) {
1261 return html_tag('td',
1262 '<small>' . $string . ': </small>',
1268 function getEndMessage($start_msg, $show_num, $num_msgs) {
1269 if ($start_msg +
($show_num - 1) < $num_msgs){
1270 $end_msg = $start_msg +
($show_num - 1);
1272 $end_msg = $num_msgs;
1275 if ($end_msg < $start_msg) {
1276 $start_msg = $start_msg - $show_num;
1277 if ($start_msg < 1) {
1281 return (array($start_msg,$end_msg));
1284 function handleAsSent($mailbox) {
1285 global $handleAsSent_result;
1287 /* First check if this is the sent or draft folder. */
1288 $handleAsSent_result = isSentMailbox($mailbox) ||
isDraftMailbox($mailbox);
1290 /* Then check the result of the handleAsSent hook. */
1291 do_hook('check_handleAsSent_result', $mailbox);
1293 /* And return the result. */
1294 return $handleAsSent_result;