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...
13 * @package squirrelmail
16 /** The standard includes.. */
17 require_once(SM_PATH
. 'functions/strings.php');
18 require_once(SM_PATH
. 'functions/html.php');
19 require_once(SM_PATH
. 'class/html.class.php');
20 require_once(SM_PATH
. 'functions/imap_mailbox.php');
21 require_once(SM_PATH
. 'functions/imap_messages.php');
22 require_once(SM_PATH
. 'functions/mime.php');
25 * default value for page_selector_max
27 define('PG_SEL_MAX', 10);
30 * @param mixed $start UNDOCUMENTED
32 function elapsed($start)
35 list($start2, $start1) = explode(" ", $start);
36 list($end2, $end1) = explode(" ", $end);
37 $diff1 = $end1 - $start1;
38 $diff2 = $end2 - $start2;
43 return $diff2 +
$diff1;
46 function printMessageInfo($imapConnection, $t, $not_last=true, $key, $mailbox,
47 $start_msg, $where, $what) {
49 $color, $msgs, $msort, $td_str, $msg,
50 $default_use_priority,
51 $message_highlight_list,
53 $indent_array, /* indent subject by */
54 $pos, /* Search postion (if any) */
55 $thread_sort_messages, /* thread sorting on/off */
56 $server_sort_order, /* sort value when using server-sorting */
58 $allow_server_sort, /* enable/disable server-side sorting */
59 $truncate_sender, /* number of characters for From/To field (<= 0 for unchanged) */
61 $show_recipient_instead; /* show recipient name instead of default identity */
63 $color_string = $color[4];
65 if ($GLOBALS['alt_index_colors']) {
66 if (!isset($row_count)) {
71 if (!isset($color[12])) {
72 $color[12] = '#EAEAEA';
74 $color_string = $color[12];
79 if($mailbox == 'None') {
80 $boxes = sqimap_mailbox_list($imapConnection);
81 $mailbox = $boxes[0]['unformatted'];
84 $urlMailbox = urlencode($mailbox);
86 $bSentFolder = handleAsSent($mailbox);
87 if ((!$bSentFolder) && ($show_recipient_instead)) {
88 // If the From address is the same as $email_address, then handle as Sent
89 $from_array = parseAddress($msg['FROM'], 1);
90 if (!isset($email_address)) {
91 global $datadir, $username;
92 $email_address = getPref($datadir, $username, 'email_address');
94 $bHandleAsSent = ((isset($from_array[0][0])) && ($from_array[0][0] == $email_address));
97 $bHandleAsSent = $bSentFolder;
98 // If this is a Sent message, display To address instead of From
100 $msg['FROM'] = $msg['TO'];
101 // Passing 1 below results in only 1 address being parsed, thus defeating the following code
102 $msg['FROM'] = parseAddress($msg['FROM']/*,1*/);
105 * This is done in case you're looking into Sent folders,
106 * because you can have multiple receivers.
108 $senderNames = $msg['FROM'];
111 if (sizeof($senderNames)){
112 foreach ($senderNames as $senderNames_part) {
113 if ($senderName != '') {
115 $senderAddress .= ', ';
117 $sender_address_part = htmlspecialchars($senderNames_part[0]);
118 $sender_name_part = str_replace(' ',' ', decodeHeader($senderNames_part[1]));
119 if ($sender_name_part) {
120 $senderName .= $sender_name_part;
121 $senderAddress .= $sender_name_part . ' <' . $sender_address_part . '>';
123 $senderName .= $sender_address_part;
124 $senderAddress .= $sender_address_part;
128 // If Sent, prefix with To: but only if not Sent folder
129 if ($bHandleAsSent ^
$bSentFolder) {
130 $senderName = _("To:") . ' ' . $senderName;
131 $senderAddress = _("To:") . ' ' . $senderAddress;
134 if ($truncate_sender > 0)
135 $senderName = truncateWithEntities($senderName, $truncate_sender);
137 echo html_tag( 'tr','','','','VALIGN="top"') . "\n";
139 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
140 $flag = "<font color=\"$color[2]\">";
141 $flag_end = '</font>';
146 if (!isset($msg['FLAG_SEEN']) ||
($msg['FLAG_SEEN'] == false)) {
153 if ($bHandleAsSent) {
155 $italic_end = '</i>';
160 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
161 $fontstr = "<font color=\"$color[9]\">";
162 $fontstr_end = '</font>';
168 if ($where && $what) {
169 $searchstr = '&where='.$where.'&what='.$what;
174 if (is_array($message_highlight_list) && count($message_highlight_list)) {
175 $msg['TO'] = parseAddress($msg['TO']);
176 $msg['CC'] = parseAddress($msg['CC']);
177 foreach ($message_highlight_list as $message_highlight_list_part) {
178 if (trim($message_highlight_list_part['value']) != '') {
179 $high_val = strtolower($message_highlight_list_part['value']);
180 $match_type = strtoupper($message_highlight_list_part['match_type']);
181 if($match_type == 'TO_CC') {
182 $match = array('TO', 'CC');
184 $match = array($match_type);
186 foreach($match as $match_type) {
187 switch($match_type) {
191 foreach ($msg[$match_type] as $address) {
192 $address[0] = decodeHeader($address[0], true, false);
193 $address[1] = decodeHeader($address[1], true, false);
194 if (strstr('^^' . strtolower($address[0]), $high_val) ||
195 strstr('^^' . strtolower($address[1]), $high_val)) {
196 $hlt_color = $message_highlight_list_part['color'];
202 $headertest = strtolower(decodeHeader($msg[$match_type], true, false));
203 if (strstr('^^' . $headertest, $high_val)) {
204 $hlt_color = $message_highlight_list_part['color'];
214 if (!isset($hlt_color)) {
215 $hlt_color = $color_string;
217 $checked = ($checkall == 1) ?
' CHECKED' : '';
219 $msg['SUBJECT'] = str_replace(' ', ' ', decodeHeader($msg['SUBJECT']));
220 $subject = processSubject($msg['SUBJECT'], $indent_array[$msg['ID']]);
221 if (sizeof($index_order)) {
222 foreach ($index_order as $index_order_part) {
223 switch ($index_order_part) {
224 case 1: /* checkbox */
226 "<input type=checkbox name=\"msg[$t]\" value=\"".$msg['ID']."\"$checked>",
231 if ($senderAddress != $senderName) {
232 $senderAddress = strtr($senderAddress, array_flip(get_html_translation_table(HTML_SPECIALCHARS
)));
233 $title = ' title="' . str_replace('"', "''", $senderAddress) . '"';
238 $italic . $bold . $flag . $fontstr . $senderName .
239 $fontstr_end . $flag_end . $bold_end . $italic_end,
241 $hlt_color, $title );
244 $date_string = $msg['DATE_STRING'] . '';
245 if ($date_string == '') {
246 $date_string = _("Unknown date");
249 $bold . $flag . $fontstr . $date_string .
250 $fontstr_end . $flag_end . $bold_end,
255 case 4: /* subject */
257 if ($thread_sort_messages == 1) {
258 if (isset($indent_array[$msg['ID']])) {
259 $td_str .= str_repeat(" ",$indent_array[$msg['ID']]);
262 $td_str .= '<a href="read_body.php?mailbox='.$urlMailbox
263 . '&passed_id='. $msg["ID"]
264 . '&startMessage='.$start_msg.$searchstr.'"';
265 $td_str .= ' ' .concat_hook_function('subject_link', array($start_msg, $searchstr));
266 if ($subject != $msg['SUBJECT']) {
267 $title = get_html_translation_table(HTML_SPECIALCHARS
);
268 $title = array_flip($title);
269 $title = strtr($msg['SUBJECT'], $title);
270 $title = str_replace('"', "''", $title);
271 $td_str .= " title=\"$title\"";
273 $td_str .= ">$flag$subject$flag_end</a>$bold_end";
274 echo html_tag( 'td', $td_str, 'left', $hlt_color );
278 $td_str = "<b><small>";
280 if (isset($msg['FLAG_ANSWERED']) && $msg['FLAG_ANSWERED'] == true) {
284 if ($msg['TYPE0'] == 'multipart') {
288 if ($default_use_priority) {
289 if ( ($msg['PRIORITY'] == 1) ||
($msg['PRIORITY'] == 2) ) {
290 $td_str .= "<font color=\"$color[1]\">!</font>";
293 if ($msg['PRIORITY'] == 5) {
294 $td_str .= "<font color=\"$color[8]\">?</font>";
298 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'] == true) {
299 $td_str .= "<font color=\"$color[1]\">D</font>";
305 do_hook("msg_envelope");
306 $td_str .= '</small></b>';
315 $bold . $fontstr . show_readable_size($msg['SIZE']) .
316 $fontstr_end . $bold_end,
325 echo '</tr>' . "\n" . '<tr><td COLSPAN="' . $col . '" BGCOLOR="' .
326 $color[0] . '" HEIGHT="1"></td></tr>' . "\n";
332 function getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id) {
334 $id = array_slice($id, ($start_msg-1), $show_num);
335 $end = $start_msg +
$show_num - 1;
336 if ($num_msgs < $show_num) {
337 $end_loop = $num_msgs;
338 } else if ($end > $num_msgs) {
339 $end_loop = $num_msgs - $start_msg +
1;
341 $end_loop = $show_num;
343 return fillMessageArray($imapConnection,$id,$end_loop,$show_num);
349 function getThreadMessages($imapConnection, $start_msg, $show_num, $num_msgs) {
350 $id = get_thread_sort($imapConnection);
351 return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
354 function getServerSortMessages($imapConnection, $start_msg, $show_num,
355 $num_msgs, $server_sort_order, $mbxresponse) {
356 $id = sqimap_get_sort_order($imapConnection, $server_sort_order,$mbxresponse);
357 return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
360 function getSelfSortMessages($imapConnection, $start_msg, $show_num,
361 $num_msgs, $sort, $mbxresponse) {
363 if ($num_msgs >= 1) {
364 $id = sqimap_get_php_sort_order ($imapConnection, $mbxresponse);
368 /* set shownum to 999999 to fool sqimap_get_small_header_list
369 and rebuild the msgs_str to 1:* */
372 /* if it's not sorted */
373 if ($start_msg +
($show_num - 1) < $num_msgs) {
374 $end_msg = $start_msg +
($show_num - 1);
376 $end_msg = $num_msgs;
378 if ($end_msg < $start_msg) {
379 $start_msg = $start_msg - $show_num;
380 if ($start_msg < 1) {
384 $id = array_slice(array_reverse($id), ($start_msg-1), $show_num);
385 $end = $start_msg +
$show_num - 1;
386 if ($num_msgs < $show_num) {
387 $end_loop = $num_msgs;
388 } else if ($end > $num_msgs) {
389 $end_loop = $num_msgs - $start_msg +
1;
391 $end_loop = $show_num;
394 $msgs = fillMessageArray($imapConnection,$id,$end_loop, $show_num);
402 * This function loops through a group of messages in the mailbox
403 * and shows them to the user.
405 function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
406 $start_msg, $sort, $color, $show_num,
407 $use_cache, $mode='') {
408 global $msgs, $msort, $auto_expunge, $thread_sort_messages,
409 $allow_server_sort, $server_sort_order;
412 * For some reason, on PHP 4.3+, this being unset, and set in the session causes havoc
413 * so setting it to an empty array beforehand seems to clean up the issue, and stopping the
414 * "Your script possibly relies on a session side-effect which existed until PHP 4.2.3" error
417 if (!isset($msort)) {
425 //$start = microtime();
426 /* If autoexpunge is turned on, then do it now. */
427 $mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox);
429 /* If autoexpunge is turned on, then do it now. */
430 if ($auto_expunge == true) {
431 $exp_cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, false, '');
432 $mbxresponse['EXISTS'] = $mbxresponse['EXISTS'] - $exp_cnt;
433 $num_msgs = $mbxresponse['EXISTS'];
436 if ($mbxresponse['EXISTS'] > 0) {
437 /* if $start_msg is lower than $num_msgs, we probably deleted all messages
438 * in the last page. We need to re-adjust the start_msg
441 if($start_msg > $num_msgs) {
442 $start_msg -= $show_num;
448 /* This code and the next if() block check for
449 * server-side sorting methods. The $id array is
450 * formatted and $sort is set to 6 to disable
451 * SM internal sorting
454 if ($thread_sort_messages == 1) {
456 } elseif ($allow_server_sort == 1) {
457 $mode = 'serversort';
463 sqgetGlobalVar('msgs', $msgs, SQ_SESSION
);
464 sqgetGlobalVar('msort', $msort, SQ_SESSION
);
466 sqsession_unregister('msort');
467 sqsession_unregister('msgs'); }
470 $id = get_thread_sort($imapConnection);
471 $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
472 if ($msgs === false) {
473 echo '<b><small><center><font color=red>' .
474 _("Thread sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
475 '</center></small></b>';
476 $thread_sort_messages = 0;
477 $msort = $msgs = array();
484 $id = sqimap_get_sort_order($imapConnection, $sort, $mbxresponse);
485 $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
486 if ($msgs === false) {
487 echo '<b><small><center><font color=red>' .
488 _( "Server-side sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
489 '</center></small></b>';
490 $sort = $server_sort_order;
491 $allow_server_sort = FALSE;
492 $msort = $msgs = array();
501 $msgs = getSelfSortMessages($imapConnection, $start_msg, $show_num,
502 $num_msgs, $sort, $mbxresponse);
503 $msort = calc_msort($msgs, $sort);
507 sqsession_register($msort, 'msort');
508 sqsession_register($msgs, 'msgs');
510 } /* if exists > 0 */
512 $res = getEndMessage($start_msg, $show_num, $num_msgs);
513 $start_msg = $res[0];
516 $paginator_str = get_paginator_str($mailbox, $start_msg, $end_msg,
517 $num_msgs, $show_num, $sort);
519 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
521 do_hook('mailbox_index_before');
522 echo '<table border="0" width="100%" cellpadding="0" cellspacing="0">';
525 mail_message_listing_beginning($imapConnection, $mailbox, $sort,
526 $msg_cnt_str, $paginator_str, $start_msg);
528 /* line between the button area and the list */
529 echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>';
532 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
534 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[5].'">';
536 printHeader($mailbox, $srt, $color, !$thread_sort_messages);
538 displayMessageArray($imapConnection, $num_msgs, $start_msg,
539 $msort, $mailbox, $sort, $color, $show_num,0,0);
540 echo '</td></tr></table></td></tr></table>';
542 mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color);
543 echo '</td></tr></table>';
544 //$t = elapsed($start);
545 //echo("elapsed time = $t seconds\n");
548 function calc_msort($msgs, $sort) {
559 if (($sort == 0) ||
($sort == 1)) {
560 foreach ($msgs as $item) {
561 $msort[] = $item['TIME_STAMP'];
563 } elseif (($sort == 2) ||
($sort == 3)) {
564 foreach ($msgs as $item) {
565 $msort[] = $item['FROM-SORT'];
567 } elseif (($sort == 4) ||
($sort == 5)) {
568 foreach ($msgs as $item) {
569 $msort[] = $item['SUBJECT-SORT'];
584 function fillMessageArray($imapConnection, $id, $count, $show_num=false) {
585 return sqimap_get_small_header_list($imapConnection, $id, $show_num);
589 /* Generic function to convert the msgs array into an HTML table. */
590 function displayMessageArray($imapConnection, $num_msgs, $start_msg,
591 $msort, $mailbox, $sort, $color,
592 $show_num, $where=0, $what=0) {
593 global $imapServerAddress, $use_mailbox_cache, $index_order,
594 $indent_array, $thread_sort_messages, $allow_server_sort,
595 $server_sort_order, $PHP_SELF;
597 $res = getEndMessage($start_msg, $show_num, $num_msgs);
598 $start_msg = $res[0];
601 $urlMailbox = urlencode($mailbox);
603 /* get indent level for subject display */
604 if ($thread_sort_messages == 1 && $num_msgs) {
605 $indent_array = get_parent_level($imapConnection);
608 $real_startMessage = $start_msg;
610 if ($end_msg - $start_msg < $show_num - 1) {
611 $end_msg = $end_msg - $start_msg +
1;
613 } else if ($start_msg > $show_num) {
614 $end_msg = $show_num;
618 $endVar = $end_msg +
1;
621 * Loop through and display the info for each message.
622 * ($t is used for the checkbox number)
626 /* messages display */
629 /* if there's no messages in this folder */
632 "<BR><b>" . _("THIS FOLDER IS EMPTY") . "</b><BR> ",
635 'COLSPAN="' . count($index_order) . '"'
638 } elseif ($start_msg == $end_msg) {
639 /* if there's only one message in the box, handle it differently. */
651 } while (isset ($key) && ($k < $i));
652 printMessageInfo($imapConnection, $t, true, $key, $mailbox,
653 $real_startMessage, $where, $what);
662 } while (isset ($key) && ($k < $i));
665 if (!$i ||
$i == $endVar-1) $not_last = false;
666 printMessageInfo($imapConnection, $t, $not_last, $key, $mailbox,
667 $real_startMessage, $where, $what);
672 } while ($i && $i < $endVar);
677 * Displays the standard message list header. To finish the table,
678 * you need to do a "</table></table>";
680 * $moveURL is the URL to submit the delete/move form to
681 * $mailbox is the current mailbox
682 * $sort is the current sorting method (-1 for no sorting available [searches])
683 * $Message is a message that is centered on top of the list
684 * $More is a second line that is left aligned
687 function mail_message_listing_beginning ($imapConnection,
688 $mailbox = '', $sort = -1,
690 $paginator = ' ',
692 global $color, $auto_expunge, $base_uri, $thread_sort_messages,
693 $allow_thread_sort, $allow_server_sort, $server_sort_order,
696 $php_self = $PHP_SELF;
697 /* fix for incorrect $PHP_SELF */
698 if (strpos($php_self, 'move_messages.php')) {
699 $php_self = str_replace('move_messages.php', 'right_main.php', $php_self);
701 $urlMailbox = urlencode($mailbox);
703 if (preg_match('/^(.+)\?.+$/',$php_self,$regs)) {
704 $source_url = $regs[1];
706 $source_url = $php_self;
712 $moveFields = '<input type="hidden" name="msg" value="'.htmlspecialchars($msg).'">' .
713 '<input type="hidden" name="mailbox" value="'.htmlspecialchars($mailbox).'">' .
714 '<input type="hidden" name="startMessage" value="'.htmlspecialchars($start_msg).'">';
716 // $moveURL = "move_messages.php?msg=$msg&mailbox=$urlMailbox"
717 // . "&startMessage=$start_msg";
719 * This is the beginning of the message list table.
720 * It wraps around all messages
722 $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $mailbox);
723 $form_name = "FormMsgs" . $safe_name;
724 echo '<form name="' . $form_name . '" method="post" action="move_messages.php">' ."\n"
726 . html_tag( 'table' ,
731 html_tag( 'td', $paginator, 'left' ) .
732 html_tag( 'td', $msg_cnt_str, 'right' )
734 , '', $color[4], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
737 , '', '', 'border="0" width="100%" cellpadding="1" cellspacing="0"' );
738 /* line between header and button area */
739 echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>';
742 echo html_tag( 'tr' ) . "\n"
743 . html_tag( 'td' ,'' , 'left', '', '' )
744 . html_tag( 'table' ,'' , '', $color[9], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
746 . html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
748 getSmallStringCell(_("Move Selected To"), 'left', 'nowrap') .
749 getSmallStringCell(_("Transform Selected Messages"), 'right')
751 . html_tag( 'tr' ) ."\n"
752 . html_tag( 'td', '', 'left', '', 'valign="middle" nowrap' );
753 getMbxList($imapConnection);
754 echo getButton('SUBMIT', 'moveButton',_("Move")) . "\n";
755 echo getButton('SUBMIT', 'attache',_("Forward")) . "\n";
758 . html_tag( 'td', '', 'right', '', 'nowrap' );
762 if (!$auto_expunge) {
763 echo getButton('SUBMIT', 'expungeButton',_("Expunge"))
764 .' ' . _("mailbox") . "\n";
766 do_hook('mailbox_display_buttons');
767 echo getButton('SUBMIT', 'markRead',_("Read"));
768 echo getButton('SUBMIT', 'markUnread',_("Unread"));
769 echo getButton('SUBMIT', 'delete',_("Delete")) ." \n";
770 if (!strpos($php_self,'mailbox')) {
771 $location = $php_self.'?mailbox=INBOX&startMessage=1';
773 $location = $php_self;
775 echo '<INPUT TYPE="HIDDEN" NAME="location" VALUE="'.$location.'">';
779 /* draws thread sorting links */
780 if ($allow_thread_sort == TRUE) {
781 if ($thread_sort_messages == 1 ) {
783 $thread_name = _("Unthread View");
784 } elseif ($thread_sort_messages == 0) {
786 $thread_name = _("Thread View");
788 echo html_tag( 'tr' ,
790 ' <a href=' . $source_url . '?sort='
791 . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
792 . '&mailbox=' . urlencode($mailbox) . '><small>' . $thread_name
793 . '</a></small> '
794 , '', '', '' ) . html_tag( 'td', _("Bypass Trash") . '<input type="checkbox" name="bypass_trash">','right','','')
799 echo "</TABLE></td></tr></table></td></tr>\n";
801 do_hook('mailbox_form_before');
803 /* if using server sort we highjack the
804 * the $sort var and use $server_sort_order
805 * instead. but here we reset sort for a bit
808 if ($allow_server_sort == TRUE) {
809 $sort = $server_sort_order;
813 function mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color) {
815 /* space between list and footer */
816 echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'" COLSPAN="1">';
818 echo '</td></tr><tr><td>';
819 echo html_tag( 'table',
824 html_tag( 'td', $paginator_str ) .
825 html_tag( 'td', $msg_cnt_str, 'right' )
827 , '', $color[4], 'width="100%" border="0" cellpadding="1" cellspacing="0"' )
830 , '', $color[9], 'width="100%" border="0" cellpadding="1" cellspacing="0"' );
833 /* End of message-list table */
835 do_hook('mailbox_index_after');
839 function printHeader($mailbox, $sort, $color, $showsort=true) {
841 echo html_tag( 'tr' ,'' , 'center', $color[5] );
843 /* calculate the width of the subject column based on the
844 * widths of the other columns */
845 $widths = array(1=>1,2=>25,3=>5,4=>0,5=>1,6=>5);
847 foreach($index_order as $item) {
848 $subjectwidth -= $widths[$item];
851 foreach ($index_order as $item) {
853 case 1: /* checkbox */
855 echo html_tag( 'td' ,' ' , '', '', 'width="1%"' );
858 if (handleAsSent($mailbox)) {
859 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
860 . '<b>' . _("To") . '</b>';
862 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
863 . '<b>' . _("From") . '</b>';
866 ShowSortButton($sort, $mailbox, 2, 3);
871 echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
872 . '<b>' . _("Date") . '</b>';
874 ShowSortButton($sort, $mailbox, 0, 1);
878 case 4: /* subject */
879 echo html_tag( 'td' ,'' , 'left', '', 'width="'.$subjectwidth.'%"' )
880 . '<b>' . _("Subject") . '</b>';
882 ShowSortButton($sort, $mailbox, 4, 5);
887 echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%" nowrap' );
896 * This function shows the sort button. Isn't this a good comment?
898 function ShowSortButton($sort, $mailbox, $Up, $Down ) {
900 /* Figure out which image we want to use. */
901 if ($sort != $Up && $sort != $Down) {
902 $img = 'sort_none.png';
904 } elseif ($sort == $Up) {
905 $img = 'up_pointer.png';
908 $img = 'down_pointer.png';
912 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
913 $source_url = $regs[1];
915 $source_url = $PHP_SELF;
918 /* Now that we have everything figured out, show the actual button. */
919 echo ' <a href="' . $source_url .'?newsort=' . $which
920 . '&startMessage=1&mailbox=' . urlencode($mailbox)
921 . '"><img src="../images/' . $img
922 . '" border="0" width="12" height="10" alt="sort" title="'
923 . _("Click here to change the sorting of the message list") .'"></a>';
926 function get_selectall_link($start_msg, $sort) {
927 global $checkall, $what, $where, $mailbox, $javascript_on;
928 global $PHP_SELF, $PG_SHOWNUM;
931 if ($javascript_on) {
932 $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $mailbox);
933 $func_name = "CheckAll" . $safe_name;
934 $form_name = "FormMsgs" . $safe_name;
935 $result = '<script language="JavaScript" type="text/javascript">'
937 . "function " . $func_name . "() {\n"
938 . " for (var i = 0; i < document." . $form_name . ".elements.length; i++) {\n"
939 . " if(document." . $form_name . ".elements[i].type == 'checkbox' && "
940 . "document." . $form_name . ".elements[i].name != 'bypass_trash'){\n"
941 . " document." . $form_name . ".elements[i].checked = "
942 . " !(document." . $form_name . ".elements[i].checked);\n"
947 . '</script><a href="javascript:void(0)" onClick="' . $func_name . '();">' . _("Toggle All")
948 /* . '</script><a href="javascript:' . $func_name . '()">' . _("Toggle All")*/
951 if (strpos($PHP_SELF, "?")) {
952 $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($mailbox)
953 . "&startMessage=$start_msg&sort=$sort&checkall=";
955 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
956 . "&startMessage=$start_msg&sort=$sort&checkall=";
958 if (isset($checkall) && $checkall == '1') {
964 if (isset($where) && isset($what)) {
965 $result .= '&where=' . urlencode($where)
966 . '&what=' . urlencode($what);
970 if (isset($checkall) && ($checkall == '1')) {
971 $result .= _("Unselect All");
973 $result .= _("Select All");
978 /* Return our final result. */
983 * This function computes the "Viewing Messages..." string.
985 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
986 /* Compute the $msg_cnt_str. */
988 if ($start_msg < $end_msg) {
989 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"),
990 $start_msg, $end_msg, $num_msgs);
991 } else if ($start_msg == $end_msg) {
992 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
996 /* Return our result string. */
1001 * Generate a paginator link.
1003 function get_paginator_link($box, $start_msg, $use, $text) {
1006 $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
1007 . "&startMessage=$start_msg&mailbox=$box\" "
1008 . "TARGET=\"right\">$text</A>";
1011 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
1012 $source_url = $regs[1];
1014 $source_url = $PHP_SELF;
1017 $result = '<A HREF="'. $source_url . "?use_mailbox_cache=$use"
1018 . "&startMessage=$start_msg&mailbox=$box\" "
1019 . "TARGET=\"right\">$text</A>";
1025 * This function computes the paginator string.
1027 function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
1029 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
1031 /* Initialize paginator string chunks. */
1038 $box = urlencode($box);
1040 /* Create simple strings that will be creating the paginator. */
1041 $spc = ' '; /* This will be used as a space. */
1042 $sep = '|'; /* This will be used as a seperator. */
1044 /* Get some paginator preference values. */
1045 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON
);
1046 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
);
1048 /* Make sure that our start message number is not too big. */
1049 $start_msg = min($start_msg, $num_msgs);
1051 /* Decide whether or not we will use the mailbox cache. */
1052 /* Not sure why $use_mailbox_cache is even passed in. */
1059 /* Compute the starting message of the previous and next page group. */
1060 $next_grp = $start_msg +
$show_num;
1061 $prev_grp = $start_msg - $show_num;
1063 /* Compute the basic previous and next strings. */
1064 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
1065 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1066 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1067 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
1068 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1069 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
1070 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
1071 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
1072 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1075 /* Page selector block. Following code computes page links. */
1076 if ($pg_sel && ($num_msgs > $show_num)) {
1077 /* Most importantly, what is the current page!!! */
1078 $cur_pg = intval($start_msg / $show_num) +
1;
1080 /* Compute total # of pages and # of paginator page links. */
1081 $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
1082 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
1084 /* Compute the size of the four quarters of the page links. */
1086 /* If we can, just show all the pages. */
1087 if (($tot_pgs - 1) <= $pg_max) {
1088 $q1_pgs = $cur_pg - 1;
1089 $q2_pgs = $q3_pgs = 0;
1090 $q4_pgs = $tot_pgs - $cur_pg;
1092 /* Otherwise, compute some magic to choose the four quarters. */
1095 * Compute the magic base values. Added together,
1096 * these values will always equal to the $pag_pgs.
1097 * NOTE: These are DEFAULT values and do not take
1098 * the current page into account. That is below.
1100 $q1_pgs = floor($vis_pgs/4);
1101 $q2_pgs = round($vis_pgs/4, 0);
1102 $q3_pgs = ceil($vis_pgs/4);
1103 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
1105 /* Adjust if the first quarter contains the current page. */
1106 if (($cur_pg - $q1_pgs) < 1) {
1107 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) +
$q2_pgs;
1108 $q1_pgs = $cur_pg - 1;
1110 $q3_pgs +
= ceil($extra_pgs / 2);
1111 $q4_pgs +
= floor($extra_pgs / 2);
1113 /* Adjust if the first and second quarters intersect. */
1114 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
1115 $extra_pgs = $q2_pgs;
1116 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 3/4);
1117 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 3/4);
1118 $q3_pgs +
= ceil($extra_pgs / 2);
1119 $q4_pgs +
= floor($extra_pgs / 2);
1121 /* Adjust if the fourth quarter contains the current page. */
1122 } else if (($cur_pg +
$q4_pgs) >= $tot_pgs) {
1123 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) +
$q3_pgs;
1125 $q4_pgs = $tot_pgs - $cur_pg;
1126 $q1_pgs +
= floor($extra_pgs / 2);
1127 $q2_pgs +
= ceil($extra_pgs / 2);
1129 /* Adjust if the third and fourth quarter intersect. */
1130 } else if (($cur_pg +
$q3_pgs +
1) >= ($tot_pgs - $q4_pgs +
1)) {
1131 $extra_pgs = $q3_pgs;
1132 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 3/4);
1133 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 3/4);
1134 $q1_pgs +
= floor($extra_pgs / 2);
1135 $q2_pgs +
= ceil($extra_pgs / 2);
1140 * I am leaving this debug code here, commented out, because
1141 * it is a really nice way to see what the above code is doing.
1142 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
1143 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
1146 /* Print out the page links from the compute page quarters. */
1148 /* Start with the first quarter. */
1149 if (($q1_pgs == 0) && ($cur_pg > 1)) {
1150 $pg_str .= "...$spc";
1152 for ($pg = 1; $pg <= $q1_pgs; ++
$pg) {
1153 $start = (($pg-1) * $show_num) +
1;
1154 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1156 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
1157 $pg_str .= "...$spc";
1161 /* Continue with the second quarter. */
1162 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++
$pg) {
1163 $start = (($pg-1) * $show_num) +
1;
1164 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1167 /* Now print the current page. */
1168 $pg_str .= $cur_pg . $spc;
1170 /* Next comes the third quarter. */
1171 for ($pg = $cur_pg +
1; $pg <= $cur_pg +
$q3_pgs; ++
$pg) {
1172 $start = (($pg-1) * $show_num) +
1;
1173 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1176 /* And last, print the forth quarter page links. */
1177 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
1178 $pg_str .= "...$spc";
1180 if (($tot_pgs - $q4_pgs) > ($cur_pg +
$q3_pgs)) {
1181 $pg_str .= "...$spc";
1183 for ($pg = $tot_pgs - $q4_pgs +
1; $pg <= $tot_pgs; ++
$pg) {
1184 $start = (($pg-1) * $show_num) +
1;
1185 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1188 } else if ($PG_SHOWNUM == 999999) {
1189 $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
1190 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1191 . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc;
1194 /* If necessary, compute the 'show all' string. */
1195 if (($prv_str != '') ||
($nxt_str != '')) {
1196 $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
1197 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1198 . "TARGET=\"right\">" . _("Show All") . '</A>';
1201 /* Last but not least, get the value for the toggle all link. */
1202 $tgl_str = get_selectall_link($start_msg, $sort);
1204 /* Put all the pieces of the paginator string together. */
1206 * Hairy code... But let's leave it like it is since I am not certain
1207 * a different approach would be any easier to read. ;)
1210 $result .= ($prv_str != '' ?
$prv_str . $spc . $sep . $spc : '');
1211 $result .= ($nxt_str != '' ?
$nxt_str . $spc . $sep . $spc : '');
1212 $result .= ($pg_str != '' ?
$pg_str : '');
1213 $result .= ($all_str != '' ?
$sep . $spc . $all_str . $spc : '');
1214 $result .= ($result != '' ?
$sep . $spc . $tgl_str: $tgl_str);
1216 /* If the resulting string is blank, return a non-breaking space. */
1217 if ($result == '') {
1221 /* Return our final magical paginator string. */
1225 function truncateWithEntities($subject, $trim_at)
1227 $ent_strlen = strlen($subject);
1228 if (($trim_at <= 0) ||
($ent_strlen <= $trim_at))
1231 global $languages, $squirrelmail_language;
1234 * see if this is entities-encoded string
1235 * If so, Iterate through the whole string, find out
1236 * the real number of characters, and if more
1237 * than $trim_at, substr with an updated trim value.
1239 $trim_val = $trim_at;
1242 while ( $ent_loc < $trim_val && (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1243 (($ent_loc_end = strpos($subject, ';', $ent_loc+
3)) !== false) ) {
1244 $trim_val +
= ($ent_loc_end-$ent_loc);
1245 $ent_offset = $ent_loc_end+
1;
1247 if (($trim_val > $trim_at) && ($ent_strlen > $trim_val) && (strpos($subject,';',$trim_val) < ($trim_val +
6))) {
1248 $i = strpos($subject,';',$trim_val);
1250 $trim_val = strpos($subject,';',$trim_val);
1253 // only print '...' when we're actually dropping part of the subject
1254 if ($ent_strlen <= $trim_val)
1257 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
1258 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
1259 return $languages[$squirrelmail_language]['XTRA_CODE']('strimwidth', $subject, $trim_val);
1262 return substr_replace($subject, '...', $trim_val);
1265 function processSubject($subject, $threadlevel = 0) {
1266 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1267 if ($subject == '') {
1268 return _("(no subject)");
1271 global $truncate_subject; /* number of characters for Subject field (<= 0 for unchanged) */
1272 $trim_at = $truncate_subject;
1274 /* if this is threaded, subtract two chars per indentlevel */
1275 if (($threadlevel > 0) && ($threadlevel <= 10))
1276 $trim_at -= (2*$threadlevel);
1278 return truncateWithEntities($subject, $trim_at);
1281 function getMbxList($imapConnection, $boxes = 0) {
1282 global $lastTargetMailbox;
1283 echo ' <small> <tt><select name="targetMailbox">';
1284 echo sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)), 0, $boxes);
1285 echo ' </SELECT></TT> ';
1288 function getButton($type, $name, $value) {
1289 return '<INPUT TYPE="'.$type.'" NAME="'.$name.'" VALUE="'.$value . '">';
1292 function getSmallStringCell($string, $align) {
1293 return html_tag('td',
1294 '<small>' . $string . ': </small>',
1300 function getEndMessage($start_msg, $show_num, $num_msgs) {
1301 if ($start_msg +
($show_num - 1) < $num_msgs){
1302 $end_msg = $start_msg +
($show_num - 1);
1304 $end_msg = $num_msgs;
1307 if ($end_msg < $start_msg) {
1308 $start_msg = $start_msg - $show_num;
1309 if ($start_msg < 1) {
1313 return (array($start_msg,$end_msg));
1316 // This should go in imap_mailbox.php
1317 function handleAsSent($mailbox) {
1318 global $handleAsSent_result;
1320 /* First check if this is the sent or draft folder. */
1321 $handleAsSent_result = isSentMailbox($mailbox) ||
isDraftMailbox($mailbox);
1323 /* Then check the result of the handleAsSent hook. */
1324 do_hook('check_handleAsSent_result', $mailbox);
1326 /* And return the result. */
1327 return $handleAsSent_result;