706fbddc74eb2ca26304baca9b51b0aaae703b0c
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', 50);
29 function elapsed($start)
32 list($start2, $start1) = explode(" ", $start);
33 list($end2, $end1) = explode(" ", $end);
34 $diff1 = $end1 - $start1;
35 $diff2 = $end2 - $start2;
40 return $diff2 +
$diff1;
43 function printMessageInfo($imapConnection, $t, $not_last=true, $key, $mailbox,
44 $start_msg, $where, $what) {
46 $color, $msgs, $msort, $td_str, $msg,
47 $default_use_priority,
48 $message_highlight_list,
50 $indent_array, /* indent subject by */
51 $pos, /* Search postion (if any) */
52 $thread_sort_messages, /* thread sorting on/off */
53 $server_sort_order, /* sort value when using server-sorting */
55 $allow_server_sort, /* enable/disable server-side sorting */
56 $truncate_sender, /* number of characters for From/To field (<= 0 for unchanged) */
59 $color_string = $color[4];
61 if ($GLOBALS['alt_index_colors']) {
62 if (!isset($row_count)) {
67 if (!isset($color[12])) {
68 $color[12] = '#EAEAEA';
70 $color_string = $color[12];
75 if($mailbox == 'None') {
76 $boxes = sqimap_mailbox_list($imapConnection);
77 $mailbox = $boxes[0]['unformatted'];
80 $urlMailbox = urlencode($mailbox);
82 $bSentFolder = handleAsSent($mailbox);
83 // If the From address is the same as $email_address, then handle as Sent
84 $from_array = parseAddress($msg['FROM'], 1);
85 if (!isset($email_address)) {
86 global $datadir, $username;
87 $email_address = getPref($datadir, $username, 'email_address');
89 $bHandleAsSent = ($bSentFolder) ||
((isset($from_array[0][0])) && ($from_array[0][0] == $email_address));
90 // If this is a Sent message, display To address instead of From
92 $msg['FROM'] = $msg['TO'];
93 // Passing 1 below results in only 1 address being parsed, thus defeating the following code
94 $msg['FROM'] = parseAddress($msg['FROM']/*,1*/);
97 * This is done in case you're looking into Sent folders,
98 * because you can have multiple receivers.
100 $senderNames = $msg['FROM'];
103 if (sizeof($senderNames)){
104 foreach ($senderNames as $senderNames_part) {
105 if ($senderName != '') {
107 $senderAddress .= ', ';
109 $sender_address_part = htmlspecialchars($senderNames_part[0]);
110 $sender_name_part = str_replace(' ',' ', decodeHeader($senderNames_part[1]));
111 if ($sender_name_part) {
112 $senderName .= $sender_name_part;
113 $senderAddress .= $sender_name_part . ' <' . $sender_address_part . '>';
115 $senderName .= $sender_address_part;
116 $senderAddress .= $sender_address_part;
120 // If Sent, prefix with To: but only if not Sent folder
121 if ($bHandleAsSent ^
$bSentFolder) {
122 $senderName = _("To:") . ' ' . $senderName;
123 $senderAddress = _("To:") . ' ' . $senderAddress;
126 if ($truncate_sender > 0)
127 $senderName = truncateWithEntities($senderName, $truncate_sender);
129 echo html_tag( 'tr','','','','VALIGN="top"') . "\n";
131 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
132 $flag = "<font color=\"$color[2]\">";
133 $flag_end = '</font>';
138 if (!isset($msg['FLAG_SEEN']) ||
($msg['FLAG_SEEN'] == false)) {
145 if ($bHandleAsSent) {
147 $italic_end = '</i>';
152 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
153 $fontstr = "<font color=\"$color[9]\">";
154 $fontstr_end = '</font>';
160 if ($where && $what) {
161 $searchstr = '&where='.$where.'&what='.$what;
166 if (is_array($message_highlight_list) && count($message_highlight_list)) {
167 $msg['TO'] = parseAddress($msg['TO']);
168 $msg['CC'] = parseAddress($msg['CC']);
169 foreach ($message_highlight_list as $message_highlight_list_part) {
170 if (trim($message_highlight_list_part['value']) != '') {
171 $high_val = strtolower($message_highlight_list_part['value']);
172 $match_type = strtoupper($message_highlight_list_part['match_type']);
173 if($match_type == 'TO_CC') {
174 $match = array('TO', 'CC');
176 $match = array($match_type);
178 foreach($match as $match_type) {
179 switch($match_type) {
183 foreach ($msg[$match_type] as $address) {
184 $address[0] = decodeHeader($address[0], true, false);
185 $address[1] = decodeHeader($address[1], true, false);
186 if (strstr('^^' . strtolower($address[0]), $high_val) ||
187 strstr('^^' . strtolower($address[1]), $high_val)) {
188 $hlt_color = $message_highlight_list_part['color'];
194 $headertest = strtolower(decodeHeader($msg[$match_type], true, false));
195 if (strstr('^^' . $headertest, $high_val)) {
196 $hlt_color = $message_highlight_list_part['color'];
206 if (!isset($hlt_color)) {
207 $hlt_color = $color_string;
209 $checked = ($checkall == 1) ?
' CHECKED' : '';
211 $msg['SUBJECT'] = str_replace(' ', ' ', decodeHeader($msg['SUBJECT']));
212 $subject = processSubject($msg['SUBJECT'], $indent_array[$msg['ID']]);
213 if (sizeof($index_order)) {
214 foreach ($index_order as $index_order_part) {
215 switch ($index_order_part) {
216 case 1: /* checkbox */
218 "<input type=checkbox name=\"msg[$t]\" value=\"".$msg['ID']."\"$checked>",
223 if ($senderAddress != $senderName) {
224 $senderAddress = strtr($senderAddress, array_flip(get_html_translation_table(HTML_SPECIALCHARS
)));
225 $title = ' title="' . str_replace('"', "''", $senderAddress) . '"';
230 $italic . $bold . $flag . $fontstr . $senderName .
231 $fontstr_end . $flag_end . $bold_end . $italic_end,
233 $hlt_color, $title );
236 $date_string = $msg['DATE_STRING'] . '';
237 if ($date_string == '') {
238 $date_string = _("Unknown date");
241 $bold . $flag . $fontstr . $date_string .
242 $fontstr_end . $flag_end . $bold_end,
247 case 4: /* subject */
249 if ($thread_sort_messages == 1) {
250 if (isset($indent_array[$msg['ID']])) {
251 $td_str .= str_repeat(" ",$indent_array[$msg['ID']]);
254 $td_str .= '<a href="read_body.php?mailbox='.$urlMailbox
255 . '&passed_id='. $msg["ID"]
256 . '&startMessage='.$start_msg.$searchstr.'"';
257 $td_str .= ' ' .concat_hook_function('subject_link', array($start_msg, $searchstr));
258 if ($subject != $msg['SUBJECT']) {
259 $title = get_html_translation_table(HTML_SPECIALCHARS
);
260 $title = array_flip($title);
261 $title = strtr($msg['SUBJECT'], $title);
262 $title = str_replace('"', "''", $title);
263 $td_str .= " title=\"$title\"";
265 $td_str .= ">$flag$subject$flag_end</a>$bold_end";
266 echo html_tag( 'td', $td_str, 'left', $hlt_color );
270 $td_str = "<b><small>";
272 if (isset($msg['FLAG_ANSWERED']) && $msg['FLAG_ANSWERED'] == true) {
276 if ($msg['TYPE0'] == 'multipart') {
280 if ($default_use_priority) {
281 if ( ($msg['PRIORITY'] == 1) ||
($msg['PRIORITY'] == 2) ) {
282 $td_str .= "<font color=\"$color[1]\">!</font>";
285 if ($msg['PRIORITY'] == 5) {
286 $td_str .= "<font color=\"$color[8]\">?</font>";
290 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'] == true) {
291 $td_str .= "<font color=\"$color[1]\">D</font>";
297 do_hook("msg_envelope");
298 $td_str .= '</small></b>';
307 $bold . $fontstr . show_readable_size($msg['SIZE']) .
308 $fontstr_end . $bold_end,
317 echo '</tr>' . "\n" . '<tr><td COLSPAN="' . $col . '" BGCOLOR="' .
318 $color[0] . '" HEIGHT="1"></td></tr>' . "\n";
324 function getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id) {
326 $id = array_slice($id, ($start_msg-1), $show_num);
327 $end = $start_msg +
$show_num - 1;
328 if ($num_msgs < $show_num) {
329 $end_loop = $num_msgs;
330 } else if ($end > $num_msgs) {
331 $end_loop = $num_msgs - $start_msg +
1;
333 $end_loop = $show_num;
335 return fillMessageArray($imapConnection,$id,$end_loop,$show_num);
341 function getThreadMessages($imapConnection, $start_msg, $show_num, $num_msgs) {
342 $id = get_thread_sort($imapConnection);
343 return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
346 function getServerSortMessages($imapConnection, $start_msg, $show_num,
347 $num_msgs, $server_sort_order, $mbxresponse) {
348 $id = sqimap_get_sort_order($imapConnection, $server_sort_order,$mbxresponse);
349 return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
352 function getSelfSortMessages($imapConnection, $start_msg, $show_num,
353 $num_msgs, $sort, $mbxresponse) {
355 if ($num_msgs >= 1) {
356 $id = sqimap_get_php_sort_order ($imapConnection, $mbxresponse);
360 /* set shownum to 999999 to fool sqimap_get_small_header_list
361 and rebuild the msgs_str to 1:* */
364 /* if it's not sorted */
365 if ($start_msg +
($show_num - 1) < $num_msgs) {
366 $end_msg = $start_msg +
($show_num - 1);
368 $end_msg = $num_msgs;
370 if ($end_msg < $start_msg) {
371 $start_msg = $start_msg - $show_num;
372 if ($start_msg < 1) {
376 $id = array_slice(array_reverse($id), ($start_msg-1), $show_num);
377 $end = $start_msg +
$show_num - 1;
378 if ($num_msgs < $show_num) {
379 $end_loop = $num_msgs;
380 } else if ($end > $num_msgs) {
381 $end_loop = $num_msgs - $start_msg +
1;
383 $end_loop = $show_num;
386 $msgs = fillMessageArray($imapConnection,$id,$end_loop, $show_num);
394 * This function loops through a group of messages in the mailbox
395 * and shows them to the user.
397 function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
398 $start_msg, $sort, $color, $show_num,
399 $use_cache, $mode='') {
400 global $msgs, $msort, $auto_expunge, $thread_sort_messages,
401 $allow_server_sort, $server_sort_order;
404 * For some reason, on PHP 4.3+, this being unset, and set in the session causes havoc
405 * so setting it to an empty array beforehand seems to clean up the issue, and stopping the
406 * "Your script possibly relies on a session side-effect which existed until PHP 4.2.3" error
409 if (!isset($msort)) {
417 //$start = microtime();
418 /* If autoexpunge is turned on, then do it now. */
419 $mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox);
421 /* If autoexpunge is turned on, then do it now. */
422 if ($auto_expunge == true) {
423 $exp_cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, false, '');
424 $mbxresponse['EXISTS'] = $mbxresponse['EXISTS'] - $exp_cnt;
425 $num_msgs = $mbxresponse['EXISTS'];
428 if ($mbxresponse['EXISTS'] > 0) {
429 /* if $start_msg is lower than $num_msgs, we probably deleted all messages
430 * in the last page. We need to re-adjust the start_msg
433 if($start_msg > $num_msgs) {
434 $start_msg -= $show_num;
440 /* This code and the next if() block check for
441 * server-side sorting methods. The $id array is
442 * formatted and $sort is set to 6 to disable
443 * SM internal sorting
446 if ($thread_sort_messages == 1) {
448 } elseif ($allow_server_sort == 1) {
449 $mode = 'serversort';
455 sqgetGlobalVar('msgs', $msgs, SQ_SESSION
);
456 sqgetGlobalVar('msort', $msort, SQ_SESSION
);
458 sqsession_unregister('msort');
459 sqsession_unregister('msgs'); }
462 $id = get_thread_sort($imapConnection);
463 $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
464 if ($msgs === false) {
465 echo '<b><small><center><font color=red>' .
466 _("Thread sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
467 '</center></small></b>';
468 $thread_sort_messages = 0;
469 $msort = $msgs = array();
476 $id = sqimap_get_sort_order($imapConnection, $sort, $mbxresponse);
477 $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
478 if ($msgs === false) {
479 echo '<b><small><center><font color=red>' .
480 _( "Server-side sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
481 '</center></small></b>';
482 $sort = $server_sort_order;
483 $allow_server_sort = FALSE;
484 $msort = $msgs = array();
493 $msgs = getSelfSortMessages($imapConnection, $start_msg, $show_num,
494 $num_msgs, $sort, $mbxresponse);
495 $msort = calc_msort($msgs, $sort);
499 sqsession_register($msort, 'msort');
500 sqsession_register($msgs, 'msgs');
502 } /* if exists > 0 */
504 $res = getEndMessage($start_msg, $show_num, $num_msgs);
505 $start_msg = $res[0];
508 $paginator_str = get_paginator_str($mailbox, $start_msg, $end_msg,
509 $num_msgs, $show_num, $sort);
511 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
513 do_hook('mailbox_index_before');
514 echo '<table border="0" width="100%" cellpadding="0" cellspacing="0">';
517 mail_message_listing_beginning($imapConnection, $mailbox, $sort,
518 $msg_cnt_str, $paginator_str, $start_msg);
520 /* line between the button area and the list */
521 echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>';
524 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
526 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[5].'">';
528 printHeader($mailbox, $srt, $color, !$thread_sort_messages);
530 displayMessageArray($imapConnection, $num_msgs, $start_msg,
531 $msort, $mailbox, $sort, $color, $show_num,0,0);
532 echo '</td></tr></table></td></tr></table>';
534 mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color);
535 echo '</td></tr></table>';
536 //$t = elapsed($start);
537 //echo("elapsed time = $t seconds\n");
540 function calc_msort($msgs, $sort) {
551 if (($sort == 0) ||
($sort == 1)) {
552 foreach ($msgs as $item) {
553 $msort[] = $item['TIME_STAMP'];
555 } elseif (($sort == 2) ||
($sort == 3)) {
556 foreach ($msgs as $item) {
557 $msort[] = $item['FROM-SORT'];
559 } elseif (($sort == 4) ||
($sort == 5)) {
560 foreach ($msgs as $item) {
561 $msort[] = $item['SUBJECT-SORT'];
576 function fillMessageArray($imapConnection, $id, $count, $show_num=false) {
577 return sqimap_get_small_header_list($imapConnection, $id, $show_num);
581 /* Generic function to convert the msgs array into an HTML table. */
582 function displayMessageArray($imapConnection, $num_msgs, $start_msg,
583 $msort, $mailbox, $sort, $color,
584 $show_num, $where=0, $what=0) {
585 global $imapServerAddress, $use_mailbox_cache, $index_order,
586 $indent_array, $thread_sort_messages, $allow_server_sort,
587 $server_sort_order, $PHP_SELF;
589 $res = getEndMessage($start_msg, $show_num, $num_msgs);
590 $start_msg = $res[0];
593 $urlMailbox = urlencode($mailbox);
595 /* get indent level for subject display */
596 if ($thread_sort_messages == 1 && $num_msgs) {
597 $indent_array = get_parent_level($imapConnection);
600 $real_startMessage = $start_msg;
602 if ($end_msg - $start_msg < $show_num - 1) {
603 $end_msg = $end_msg - $start_msg +
1;
605 } else if ($start_msg > $show_num) {
606 $end_msg = $show_num;
610 $endVar = $end_msg +
1;
613 * Loop through and display the info for each message.
614 * ($t is used for the checkbox number)
618 /* messages display */
621 /* if there's no messages in this folder */
624 "<BR><b>" . _("THIS FOLDER IS EMPTY") . "</b><BR> ",
627 'COLSPAN="' . count($index_order) . '"'
630 } elseif ($start_msg == $end_msg) {
631 /* if there's only one message in the box, handle it differently. */
643 } while (isset ($key) && ($k < $i));
644 printMessageInfo($imapConnection, $t, true, $key, $mailbox,
645 $real_startMessage, $where, $what);
654 } while (isset ($key) && ($k < $i));
657 if (!$i ||
$i == $endVar-1) $not_last = false;
658 printMessageInfo($imapConnection, $t, $not_last, $key, $mailbox,
659 $real_startMessage, $where, $what);
664 } while ($i && $i < $endVar);
669 * Displays the standard message list header. To finish the table,
670 * you need to do a "</table></table>";
672 * $moveURL is the URL to submit the delete/move form to
673 * $mailbox is the current mailbox
674 * $sort is the current sorting method (-1 for no sorting available [searches])
675 * $Message is a message that is centered on top of the list
676 * $More is a second line that is left aligned
679 function mail_message_listing_beginning ($imapConnection,
680 $mailbox = '', $sort = -1,
682 $paginator = ' ',
684 global $color, $auto_expunge, $base_uri, $thread_sort_messages,
685 $allow_thread_sort, $allow_server_sort, $server_sort_order,
688 $php_self = $PHP_SELF;
689 /* fix for incorrect $PHP_SELF */
690 if (strpos($php_self, 'move_messages.php')) {
691 $php_self = str_replace('move_messages.php', 'right_main.php', $php_self);
693 $urlMailbox = urlencode($mailbox);
695 if (preg_match('/^(.+)\?.+$/',$php_self,$regs)) {
696 $source_url = $regs[1];
698 $source_url = $php_self;
704 $moveFields = '<input type="hidden" name="msg" value="'.htmlspecialchars($msg).'">' .
705 '<input type="hidden" name="mailbox" value="'.htmlspecialchars($mailbox).'">' .
706 '<input type="hidden" name="startMessage" value="'.htmlspecialchars($start_msg).'">';
708 // $moveURL = "move_messages.php?msg=$msg&mailbox=$urlMailbox"
709 // . "&startMessage=$start_msg";
711 * This is the beginning of the message list table.
712 * It wraps around all messages
714 $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $mailbox);
715 $form_name = "FormMsgs" . $safe_name;
716 echo '<form name="' . $form_name . '" method="post" action="move_messages.php">' ."\n"
718 . html_tag( 'table' ,
723 html_tag( 'td', $paginator, 'left' ) .
724 html_tag( 'td', $msg_cnt_str, 'right' )
726 , '', $color[4], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
729 , '', '', 'border="0" width="100%" cellpadding="1" cellspacing="0"' );
730 /* line between header and button area */
731 echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>';
734 echo html_tag( 'tr' ) . "\n"
735 . html_tag( 'td' ,'' , 'left', '', '' )
736 . html_tag( 'table' ,'' , '', $color[9], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
738 . html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
740 getSmallStringCell(_("Move Selected To"), 'left', 'nowrap') .
741 getSmallStringCell(_("Transform Selected Messages"), 'right')
743 . html_tag( 'tr' ) ."\n"
744 . html_tag( 'td', '', 'left', '', 'valign="middle" nowrap' );
745 getMbxList($imapConnection);
746 echo getButton('SUBMIT', 'moveButton',_("Move")) . "\n";
747 echo getButton('SUBMIT', 'attache',_("Forward")) . "\n";
750 . html_tag( 'td', '', 'right', '', 'nowrap' );
754 if (!$auto_expunge) {
755 echo getButton('SUBMIT', 'expungeButton',_("Expunge"))
756 .' ' . _("mailbox") . "\n";
758 do_hook('mailbox_display_buttons');
759 echo getButton('SUBMIT', 'markRead',_("Read"));
760 echo getButton('SUBMIT', 'markUnread',_("Unread"));
761 echo getButton('SUBMIT', 'delete',_("Delete")) ." \n";
762 if (!strpos($php_self,'mailbox')) {
763 $location = $php_self.'?mailbox=INBOX&startMessage=1';
765 $location = $php_self;
767 echo '<INPUT TYPE="HIDDEN" NAME="location" VALUE="'.$location.'">';
771 /* draws thread sorting links */
772 if ($allow_thread_sort == TRUE) {
773 if ($thread_sort_messages == 1 ) {
775 $thread_name = _("Unthread View");
776 } elseif ($thread_sort_messages == 0) {
778 $thread_name = _("Thread View");
780 echo html_tag( 'tr' ,
782 ' <a href=' . $source_url . '?sort='
783 . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
784 . '&mailbox=' . urlencode($mailbox) . '><small>' . $thread_name
785 . '</a></small> '
786 , '', '', '' ) . html_tag( 'td', _("Bypass Trash") . '<input type="checkbox" name="bypass_trash">','right','','')
791 echo "</TABLE></td></tr></table></td></tr>\n";
793 do_hook('mailbox_form_before');
795 /* if using server sort we highjack the
796 * the $sort var and use $server_sort_order
797 * instead. but here we reset sort for a bit
800 if ($allow_server_sort == TRUE) {
801 $sort = $server_sort_order;
805 function mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color) {
807 /* space between list and footer */
808 echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'" COLSPAN="1">';
810 echo '</td></tr><tr><td>';
811 echo html_tag( 'table',
816 html_tag( 'td', $paginator_str ) .
817 html_tag( 'td', $msg_cnt_str, 'right' )
819 , '', $color[4], 'width="100%" border="0" cellpadding="1" cellspacing="0"' )
822 , '', $color[9], 'width="100%" border="0" cellpadding="1" cellspacing="0"' );
825 /* End of message-list table */
827 do_hook('mailbox_index_after');
831 function printHeader($mailbox, $sort, $color, $showsort=true) {
833 echo html_tag( 'tr' ,'' , 'center', $color[5] );
835 /* calculate the width of the subject column based on the
836 * widths of the other columns */
837 $widths = array(1=>1,2=>25,3=>5,4=>0,5=>1,6=>5);
839 foreach($index_order as $item) {
840 $subjectwidth -= $widths[$item];
843 foreach ($index_order as $item) {
845 case 1: /* checkbox */
847 echo html_tag( 'td' ,' ' , '', '', 'width="1%"' );
850 if (handleAsSent($mailbox)) {
851 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
852 . '<b>' . _("To") . '</b>';
854 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
855 . '<b>' . _("From") . '</b>';
858 ShowSortButton($sort, $mailbox, 2, 3);
863 echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
864 . '<b>' . _("Date") . '</b>';
866 ShowSortButton($sort, $mailbox, 0, 1);
870 case 4: /* subject */
871 echo html_tag( 'td' ,'' , 'left', '', 'width="'.$subjectwidth.'%"' )
872 . '<b>' . _("Subject") . '</b>';
874 ShowSortButton($sort, $mailbox, 4, 5);
879 echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%" nowrap' );
888 * This function shows the sort button. Isn't this a good comment?
890 function ShowSortButton($sort, $mailbox, $Up, $Down ) {
892 /* Figure out which image we want to use. */
893 if ($sort != $Up && $sort != $Down) {
894 $img = 'sort_none.png';
896 } elseif ($sort == $Up) {
897 $img = 'up_pointer.png';
900 $img = 'down_pointer.png';
904 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
905 $source_url = $regs[1];
907 $source_url = $PHP_SELF;
910 /* Now that we have everything figured out, show the actual button. */
911 echo ' <a href="' . $source_url .'?newsort=' . $which
912 . '&startMessage=1&mailbox=' . urlencode($mailbox)
913 . '"><img src="../images/' . $img
914 . '" border="0" width="12" height="10" alt="sort" title="'
915 . _("Click here to change the sorting of the message list") .'"></a>';
918 function get_selectall_link($start_msg, $sort) {
919 global $checkall, $what, $where, $mailbox, $javascript_on;
920 global $PHP_SELF, $PG_SHOWNUM;
923 if ($javascript_on) {
924 $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $mailbox);
925 $func_name = "CheckAll" . $safe_name;
926 $form_name = "FormMsgs" . $safe_name;
927 $result = '<script language="JavaScript" type="text/javascript">'
929 . "function " . $func_name . "() {\n"
930 . " for (var i = 0; i < document." . $form_name . ".elements.length; i++) {\n"
931 . " if(document." . $form_name . ".elements[i].type == 'checkbox' && "
932 . "document." . $form_name . ".elements[i].name != 'bypass_trash'){\n"
933 . " document." . $form_name . ".elements[i].checked = "
934 . " !(document." . $form_name . ".elements[i].checked);\n"
939 . '</script><a href="javascript:void(0)" onClick="' . $func_name . '();">' . _("Toggle All")
940 /* . '</script><a href="javascript:' . $func_name . '()">' . _("Toggle All")*/
943 if (strpos($PHP_SELF, "?")) {
944 $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($mailbox)
945 . "&startMessage=$start_msg&sort=$sort&checkall=";
947 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
948 . "&startMessage=$start_msg&sort=$sort&checkall=";
950 if (isset($checkall) && $checkall == '1') {
956 if (isset($where) && isset($what)) {
957 $result .= '&where=' . urlencode($where)
958 . '&what=' . urlencode($what);
962 if (isset($checkall) && ($checkall == '1')) {
963 $result .= _("Unselect All");
965 $result .= _("Select All");
970 /* Return our final result. */
975 * This function computes the "Viewing Messages..." string.
977 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
978 /* Compute the $msg_cnt_str. */
980 if ($start_msg < $end_msg) {
981 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"),
982 $start_msg, $end_msg, $num_msgs);
983 } else if ($start_msg == $end_msg) {
984 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
988 /* Return our result string. */
993 * Generate a paginator link.
995 function get_paginator_link($box, $start_msg, $use, $text) {
998 $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
999 . "&startMessage=$start_msg&mailbox=$box\" "
1000 . "TARGET=\"right\">$text</A>";
1003 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
1004 $source_url = $regs[1];
1006 $source_url = $PHP_SELF;
1009 $result = '<A HREF="'. $source_url . "?use_mailbox_cache=$use"
1010 . "&startMessage=$start_msg&mailbox=$box\" "
1011 . "TARGET=\"right\">$text</A>";
1017 * This function computes the paginator string.
1019 function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
1021 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
1023 /* Initialize paginator string chunks. */
1030 $box = urlencode($box);
1032 /* Create simple strings that will be creating the paginator. */
1033 $spc = ' '; /* This will be used as a space. */
1034 $sep = '|'; /* This will be used as a seperator. */
1036 /* Get some paginator preference values. */
1037 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON
);
1038 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
);
1040 /* Make sure that our start message number is not too big. */
1041 $start_msg = min($start_msg, $num_msgs);
1043 /* Decide whether or not we will use the mailbox cache. */
1044 /* Not sure why $use_mailbox_cache is even passed in. */
1051 /* Compute the starting message of the previous and next page group. */
1052 $next_grp = $start_msg +
$show_num;
1053 $prev_grp = $start_msg - $show_num;
1055 /* Compute the basic previous and next strings. */
1056 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
1057 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1058 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1059 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
1060 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1061 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
1062 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
1063 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
1064 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1067 /* Page selector block. Following code computes page links. */
1068 if ($pg_sel && ($num_msgs > $show_num)) {
1069 /* Most importantly, what is the current page!!! */
1070 $cur_pg = intval($start_msg / $show_num) +
1;
1072 /* Compute total # of pages and # of paginator page links. */
1073 $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
1074 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
1076 /* Compute the size of the four quarters of the page links. */
1078 /* If we can, just show all the pages. */
1079 if (($tot_pgs - 1) <= $pg_max) {
1080 $q1_pgs = $cur_pg - 1;
1081 $q2_pgs = $q3_pgs = 0;
1082 $q4_pgs = $tot_pgs - $cur_pg;
1084 /* Otherwise, compute some magic to choose the four quarters. */
1087 * Compute the magic base values. Added together,
1088 * these values will always equal to the $pag_pgs.
1089 * NOTE: These are DEFAULT values and do not take
1090 * the current page into account. That is below.
1092 $q1_pgs = floor($vis_pgs/4);
1093 $q2_pgs = round($vis_pgs/4, 0);
1094 $q3_pgs = ceil($vis_pgs/4);
1095 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
1097 /* Adjust if the first quarter contains the current page. */
1098 if (($cur_pg - $q1_pgs) < 1) {
1099 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) +
$q2_pgs;
1100 $q1_pgs = $cur_pg - 1;
1102 $q3_pgs +
= ceil($extra_pgs / 2);
1103 $q4_pgs +
= floor($extra_pgs / 2);
1105 /* Adjust if the first and second quarters intersect. */
1106 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
1107 $extra_pgs = $q2_pgs;
1108 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1109 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1110 $q3_pgs +
= ceil($extra_pgs / 2);
1111 $q4_pgs +
= floor($extra_pgs / 2);
1113 /* Adjust if the fourth quarter contains the current page. */
1114 } else if (($cur_pg +
$q4_pgs) >= $tot_pgs) {
1115 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) +
$q3_pgs;
1117 $q4_pgs = $tot_pgs - $cur_pg;
1118 $q1_pgs +
= floor($extra_pgs / 2);
1119 $q2_pgs +
= ceil($extra_pgs / 2);
1121 /* Adjust if the third and fourth quarter intersect. */
1122 } else if (($cur_pg +
$q3_pgs +
1) >= ($tot_pgs - $q4_pgs +
1)) {
1123 $extra_pgs = $q3_pgs;
1124 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1125 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1126 $q1_pgs +
= floor($extra_pgs / 2);
1127 $q2_pgs +
= ceil($extra_pgs / 2);
1132 * I am leaving this debug code here, commented out, because
1133 * it is a really nice way to see what the above code is doing.
1134 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
1135 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
1138 /* Print out the page links from the compute page quarters. */
1140 /* Start with the first quarter. */
1141 if (($q1_pgs == 0) && ($cur_pg > 1)) {
1142 $pg_str .= "...$spc";
1144 for ($pg = 1; $pg <= $q1_pgs; ++
$pg) {
1145 $start = (($pg-1) * $show_num) +
1;
1146 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1148 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
1149 $pg_str .= "...$spc";
1153 /* Continue with the second quarter. */
1154 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++
$pg) {
1155 $start = (($pg-1) * $show_num) +
1;
1156 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1159 /* Now print the current page. */
1160 $pg_str .= $cur_pg . $spc;
1162 /* Next comes the third quarter. */
1163 for ($pg = $cur_pg +
1; $pg <= $cur_pg +
$q3_pgs; ++
$pg) {
1164 $start = (($pg-1) * $show_num) +
1;
1165 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1168 /* And last, print the forth quarter page links. */
1169 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
1170 $pg_str .= "...$spc";
1172 if (($tot_pgs - $q4_pgs) > ($cur_pg +
$q3_pgs)) {
1173 $pg_str .= "...$spc";
1175 for ($pg = $tot_pgs - $q4_pgs +
1; $pg <= $tot_pgs; ++
$pg) {
1176 $start = (($pg-1) * $show_num) +
1;
1177 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1180 } else if ($PG_SHOWNUM == 999999) {
1181 $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
1182 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1183 . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc;
1186 /* If necessary, compute the 'show all' string. */
1187 if (($prv_str != '') ||
($nxt_str != '')) {
1188 $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
1189 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1190 . "TARGET=\"right\">" . _("Show All") . '</A>';
1193 /* Last but not least, get the value for the toggle all link. */
1194 $tgl_str = get_selectall_link($start_msg, $sort);
1196 /* Put all the pieces of the paginator string together. */
1198 * Hairy code... But let's leave it like it is since I am not certain
1199 * a different approach would be any easier to read. ;)
1202 $result .= ($prv_str != '' ?
$prv_str . $spc . $sep . $spc : '');
1203 $result .= ($nxt_str != '' ?
$nxt_str . $spc . $sep . $spc : '');
1204 $result .= ($pg_str != '' ?
$pg_str : '');
1205 $result .= ($all_str != '' ?
$sep . $spc . $all_str . $spc : '');
1206 $result .= ($result != '' ?
$sep . $spc . $tgl_str: $tgl_str);
1208 /* If the resulting string is blank, return a non-breaking space. */
1209 if ($result == '') {
1213 /* Return our final magical paginator string. */
1217 function truncateWithEntities($subject, $trim_at)
1219 $ent_strlen = strlen($subject);
1220 if (($trim_at <= 0) ||
($ent_strlen <= $trim_at))
1223 global $languages, $squirrelmail_language;
1226 * see if this is entities-encoded string
1227 * If so, Iterate through the whole string, find out
1228 * the real number of characters, and if more
1229 * than $trim_at, substr with an updated trim value.
1231 $trim_val = $trim_at;
1234 while ( $ent_loc < $trim_val && (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1235 (($ent_loc_end = strpos($subject, ';', $ent_loc+
3)) !== false) ) {
1236 $trim_val +
= ($ent_loc_end-$ent_loc);
1237 $ent_offset = $ent_loc_end+
1;
1239 if (($trim_val > $trim_at) && ($ent_strlen > $trim_val) && (strpos($subject,';',$trim_val) < ($trim_val +
6))) {
1240 $i = strpos($subject,';',$trim_val);
1242 $trim_val = strpos($subject,';',$trim_val);
1245 // only print '...' when we're actually dropping part of the subject
1246 if ($ent_strlen <= $trim_val)
1249 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
1250 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
1251 return $languages[$squirrelmail_language]['XTRA_CODE']('strimwidth', $subject, $trim_val);
1254 return substr_replace($subject, '...', $trim_val);
1257 function processSubject($subject, $threadlevel = 0) {
1258 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1259 if ($subject == '') {
1260 return _("(no subject)");
1263 $trim_at = SUBJ_TRIM_AT
;
1265 /* if this is threaded, subtract two chars per indentlevel */
1266 if (($threadlevel > 0) && ($threadlevel <= 10))
1267 $trim_at -= (2*$threadlevel);
1269 return truncateWithEntities($subject, $trim_at);
1272 function getMbxList($imapConnection, $boxes = 0) {
1273 global $lastTargetMailbox;
1274 echo ' <small> <tt><select name="targetMailbox">';
1275 echo sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)), 0, $boxes);
1276 echo ' </SELECT></TT> ';
1279 function getButton($type, $name, $value) {
1280 return '<INPUT TYPE="'.$type.'" NAME="'.$name.'" VALUE="'.$value . '">';
1283 function getSmallStringCell($string, $align) {
1284 return html_tag('td',
1285 '<small>' . $string . ': </small>',
1291 function getEndMessage($start_msg, $show_num, $num_msgs) {
1292 if ($start_msg +
($show_num - 1) < $num_msgs){
1293 $end_msg = $start_msg +
($show_num - 1);
1295 $end_msg = $num_msgs;
1298 if ($end_msg < $start_msg) {
1299 $start_msg = $start_msg - $show_num;
1300 if ($start_msg < 1) {
1304 return (array($start_msg,$end_msg));
1307 function handleAsSent($mailbox) {
1308 global $handleAsSent_result;
1310 /* First check if this is the sent or draft folder. */
1311 $handleAsSent_result = isSentMailbox($mailbox) ||
isDraftMailbox($mailbox);
1313 /* Then check the result of the handleAsSent hook. */
1314 do_hook('check_handleAsSent_result', $mailbox);
1316 /* And return the result. */
1317 return $handleAsSent_result;