da3224e11813a79dc9300acf802cba1362f48d3d
6 * Copyright (c) 1999-2004 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');
23 require_once(SM_PATH
. 'functions/forms.php');
26 * default value for page_selector_max
28 define('PG_SEL_MAX', 10);
31 * @param mixed $start UNDOCUMENTED
33 function elapsed($start) {
36 list($start2, $start1) = explode(" ", $start);
37 list($end2, $end1) = explode(" ", $end);
38 $diff1 = $end1 - $start1;
39 $diff2 = $end2 - $start2;
44 return $diff2 +
$diff1;
48 * Displays message listing
50 * @param mixed $t UNDOCUMENTED
51 * @param bool $not_last UNDOCUMENTED
52 * @param mixed $key UNDOCUMENTED
53 * @param string $mailbox mail folder
54 * @param mixed $start_msg UNDOCUMENTED
55 * @param mixed $where UNDOCUMENTED
56 * @param mixed $what UNDOCUMENTED
59 function printMessageInfo($t, $last=false, $msg, $mailbox,
60 $start_msg, $where, $what) {
63 $default_use_priority,
64 $message_highlight_list,
66 $indent_array, /* indent subject by */
67 $pos, /* Search postion (if any) */
68 $thread_sort_messages, /* thread sorting on/off */
70 $truncate_sender, /* number of characters for From/To field (<= 0 for unchanged) */
72 $show_recipient_instead, /* show recipient name instead of default identity */
73 $use_icons, /* indicates to use icons or text markers */
74 $icon_theme; /* icons theming */
76 $color_string = $color[4];
78 if ($GLOBALS['alt_index_colors']) {
79 if (!isset($row_count)) {
84 if (!isset($color[12])) {
85 $color[12] = '#EAEAEA';
87 $color_string = $color[12];
91 $urlMailbox = urlencode($mailbox);
93 $bSentFolder = handleAsSent($mailbox);
94 if ((!$bSentFolder) && ($show_recipient_instead)) {
95 // If the From address is the same as $email_address, then handle as Sent
96 $from_array = parseAddress($msg['FROM'], 1);
97 if (!isset($email_address)) {
98 global $datadir, $username;
99 $email_address = getPref($datadir, $username, 'email_address');
101 $bHandleAsSent = ((isset($from_array[0][0])) && ($from_array[0][0] == $email_address));
104 $bHandleAsSent = $bSentFolder;
105 // If this is a Sent message, display To address instead of From
107 $msg['FROM'] = $msg['TO'];
108 // Passing 1 below results in only 1 address being parsed, thus defeating the following code
109 $msg['FROM'] = parseAddress($msg['FROM']/*,1*/);
112 * This is done in case you're looking into Sent folders,
113 * because you can have multiple receivers.
115 $senderNames = $msg['FROM'];
118 if (sizeof($senderNames)){
119 foreach ($senderNames as $senderNames_part) {
120 if ($senderName != '') {
122 $senderAddress .= ', ';
124 $sender_address_part = htmlspecialchars($senderNames_part[0]);
125 $sender_name_part = str_replace(' ',' ', decodeHeader($senderNames_part[1]));
126 if ($sender_name_part) {
127 $senderName .= $sender_name_part;
128 $senderAddress .= $sender_name_part . ' <' . $sender_address_part . '>';
130 $senderName .= $sender_address_part;
131 $senderAddress .= $sender_address_part;
135 // If Sent, prefix with To: but only if not Sent folder
136 if ($bHandleAsSent ^
$bSentFolder) {
137 $senderName = _("To:") . ' ' . $senderName;
138 $senderAddress = _("To:") . ' ' . $senderAddress;
141 if ($truncate_sender > 0)
142 $senderName = truncateWithEntities($senderName, $truncate_sender);
144 echo html_tag( 'tr','','','','VALIGN="top"') . "\n";
146 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
147 $flag = "<font color=\"$color[2]\">";
148 $flag_end = '</font>';
153 if (!isset($msg['FLAG_SEEN']) ||
($msg['FLAG_SEEN'] == false)) {
160 if ($bHandleAsSent) {
162 $italic_end = '</i>';
167 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
168 $fontstr = "<font color=\"$color[9]\">";
169 $fontstr_end = '</font>';
175 if ($where && $what) {
176 $searchstr = '&where='.$where.'&what='.$what;
181 if (is_array($message_highlight_list) && count($message_highlight_list)) {
182 $msg['TO'] = parseAddress($msg['TO']);
183 $msg['CC'] = parseAddress($msg['CC']);
184 foreach ($message_highlight_list as $message_highlight_list_part) {
185 if (trim($message_highlight_list_part['value']) != '') {
186 $high_val = strtolower($message_highlight_list_part['value']);
187 $match_type = strtoupper($message_highlight_list_part['match_type']);
188 if($match_type == 'TO_CC') {
189 $match = array('TO', 'CC');
191 $match = array($match_type);
193 foreach($match as $match_type) {
194 switch($match_type) {
198 foreach ($msg[$match_type] as $address) {
199 $address[0] = decodeHeader($address[0], true, false);
200 $address[1] = decodeHeader($address[1], true, false);
201 if (strstr('^^' . strtolower($address[0]), $high_val) ||
202 strstr('^^' . strtolower($address[1]), $high_val)) {
203 $hlt_color = $message_highlight_list_part['color'];
209 $headertest = strtolower(decodeHeader($msg[$match_type], true, false));
210 if (strstr('^^' . $headertest, $high_val)) {
211 $hlt_color = $message_highlight_list_part['color'];
221 if (!isset($hlt_color)) {
222 $hlt_color = $color_string;
225 $msg['SUBJECT'] = str_replace(' ', ' ', decodeHeader($msg['SUBJECT']));
226 $subject = processSubject($msg['SUBJECT'], $indent_array[$msg['ID']]);
227 if (sizeof($index_order)) {
228 foreach ($index_order as $index_order_part) {
229 switch ($index_order_part) {
230 case 1: /* checkbox */
232 addCheckBox("msg[$t]", $checkall, $msg['ID']),
237 if ($senderAddress != $senderName) {
238 $senderAddress = strtr($senderAddress, array_flip(get_html_translation_table(HTML_SPECIALCHARS
)));
239 $title = ' title="' . str_replace('"', "''", $senderAddress) . '"';
244 $italic . $bold . $flag . $fontstr . $senderName .
245 $fontstr_end . $flag_end . $bold_end . $italic_end,
247 $hlt_color, $title );
250 $date_string = $msg['DATE_STRING'] . '';
251 if ($date_string == '') {
252 $date_string = _("Unknown date");
255 $bold . $flag . $fontstr . $date_string .
256 $fontstr_end . $flag_end . $bold_end,
261 case 4: /* subject */
263 if ($thread_sort_messages == 1) {
264 if (isset($indent_array[$msg['ID']])) {
265 $td_str .= str_repeat(" ",$indent_array[$msg['ID']]);
268 $td_str .= '<a href="read_body.php?mailbox='.$urlMailbox
269 . '&passed_id='. $msg["ID"]
270 . '&startMessage='.$start_msg.$searchstr.'"';
271 $td_str .= ' ' .concat_hook_function('subject_link', array($start_msg, $searchstr));
272 if ($subject != $msg['SUBJECT']) {
273 $title = get_html_translation_table(HTML_SPECIALCHARS
);
274 $title = array_flip($title);
275 $title = strtr($msg['SUBJECT'], $title);
276 $title = str_replace('"', "''", $title);
277 $td_str .= " title=\"$title\"";
279 $td_str .= ">$flag$subject$flag_end</a>$bold_end";
280 echo html_tag( 'td', $td_str, 'left', $hlt_color );
284 // icon message markers
286 if ($use_icons && $icon_theme != 'none') {
287 $td_str = "<b><small>";
288 if (isset($msg['FLAG_FLAGGED']) && $msg['FLAG_FLAGGED'] == true) {
289 $td_str .= '<img src="' . SM_PATH
. 'images/themes/' . $icon_theme . '/flagged.png" border="0" height="10" width="10" /> ';
291 if ($default_use_priority) {
292 if ( ($msg['PRIORITY'] == 1) ||
($msg['PRIORITY'] == 2) ) {
293 $td_str .= '<img src="' . SM_PATH
. 'images/themes/' . $icon_theme . '/prio_high.png" border="0" height="10" width="5" /> ';
295 else if ($msg['PRIORITY'] == 5) {
296 $td_str .= '<img src="' . SM_PATH
. 'images/themes/' . $icon_theme . '/prio_low.png" border="0" height="10" width="5" /> ';
299 $td_str .= '<img src="' . SM_PATH
. 'images/themes/' . $icon_theme . '/transparent.png" border="0" width="5" /> ';
302 if ($msg['TYPE0'] == 'multipart') {
303 $td_str .= '<img src="' . SM_PATH
. 'images/themes/' . $icon_theme . '/attach.png" border="0" height="10" width="6" />';
305 $td_str .= '<img src="' . SM_PATH
. 'images/themes/' . $icon_theme . '/transparent.png" border="0" width="6" />';
309 if (!isset($msg['FLAG_SEEN']) ||
($msg['FLAG_SEEN']) == false) {
310 $msg_alt = '(' . _("New") . ')';
311 $msg_title = '(' . _("New") . ')';
312 $msg_icon .= SM_PATH
. 'images/themes/' . $icon_theme . '/msg_new';
314 $msg_alt = '(' . _("Read") . ')';
315 $msg_title = '(' . _("Read") . ')';
316 $msg_icon .= SM_PATH
. 'images/themes/' . $icon_theme . '/msg_read';
318 if (isset($msg['FLAG_DELETED']) && ($msg['FLAG_DELETED']) == true) {
319 $msg_icon .= '_deleted';
321 if (isset($msg['FLAG_ANSWERED']) && ($msg['FLAG_ANSWERED']) == true) {
322 $msg_alt = '(' . _("Answered") . ')';
323 $msg_title = '(' . _("Answered") . ')';
324 $msg_icon .= '_reply';
326 $td_str .= '<img src="' . $msg_icon . '.png" border="0" alt="'. $msg_alt . '" title="' . $msg_title . '" height="12" width="18" />';
327 $td_str .= '</small></b>';
336 // plain text message markers
340 $td_str = "<b><small>";
341 if (isset($msg['FLAG_ANSWERED']) && $msg['FLAG_ANSWERED'] == true) {
345 if ($msg['TYPE0'] == 'multipart') {
349 if ($default_use_priority) {
350 if ( ($msg['PRIORITY'] == 1) ||
($msg['PRIORITY'] == 2) ) {
351 $td_str .= "<font color=\"$color[1]\">!</font>";
354 if ($msg['PRIORITY'] == 5) {
355 $td_str .= "<font color=\"$color[8]\">?</font>";
359 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'] == true) {
360 $td_str .= "<font color=\"$color[1]\">D</font>";
366 $td_str .= '</small></b>';
376 $bold . $fontstr . show_readable_size($msg['SIZE']) .
377 $fontstr_end . $bold_end,
388 echo '</tr>' . "\n" . '<tr><td colspan="' . $col . '" bgcolor="' .
389 $color[0] . '" height="1"></td></tr>' . "\n";
394 * FIXME: Undocumented function
396 * @param mixed $imapConnection
397 * @param mixed $start_msg
398 * @param mixed $show_num
399 * @param mixed $num_msgs
403 function getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id) {
405 $id = array_slice($id, ($start_msg-1), $show_num);
406 $end = $start_msg +
$show_num - 1;
407 if ($num_msgs < $show_num) {
408 $end_loop = $num_msgs;
409 } else if ($end > $num_msgs) {
410 $end_loop = $num_msgs - $start_msg +
1;
412 $end_loop = $show_num;
414 return fillMessageArray($imapConnection,$id,$end_loop,$show_num);
421 * FIXME: Undocumented function
423 * @param mixed $imapConnection
424 * @param mixed $start_msg
425 * @param mixed $show_num
426 * @param mixed $num_msgs
429 function getThreadMessages($imapConnection, $start_msg, $show_num, $num_msgs) {
430 $id = get_thread_sort($imapConnection);
431 return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
435 * FIXME: Undocumented function
437 * @param mixed $imapConnection
438 * @param mixed $start_msg
439 * @param mixed $show_num
440 * @param mixed $num_msgs
441 * @param mixed $server_sort_order
442 * @param mixed $mbxresponse
445 function getServerSortMessages($imapConnection, $start_msg, $show_num,
446 $num_msgs, $server_sort_order, $mbxresponse) {
447 if (isset($mbxresponse['SORT_ARRAY']) && is_array($mbxresponse['SORT_ARRAY'])) {
448 $id = $mbxresponse['SORT_ARRAY'];
450 $id = sqimap_get_sort_order($imapConnection, $server_sort_order,$mbxresponse);
452 return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
456 * FIXME: Undocumented function
458 * @param mixed $imapConnection
459 * @param mixed $start_msg
460 * @param mixed $show_num
461 * @param mixed $num_msgs
463 * @param mixed $mbxresponse
466 function getSelfSortMessages($imapConnection, $start_msg, $show_num,
467 $num_msgs, $sort, $mbxresponse) {
469 if ($num_msgs >= 1) {
470 $id = sqimap_get_php_sort_order ($imapConnection, $mbxresponse);
474 /* set shownum to 999999 to fool sqimap_get_small_header_list
475 and rebuild the msgs_str to 1:* */
478 /* if it's not sorted */
479 if ($start_msg +
($show_num - 1) < $num_msgs) {
480 $end_msg = $start_msg +
($show_num - 1);
482 $end_msg = $num_msgs;
484 if ($end_msg < $start_msg) {
485 $start_msg = $start_msg - $show_num;
486 if ($start_msg < 1) {
490 $id = array_slice(array_reverse($id), ($start_msg-1), $show_num);
491 $end = $start_msg +
$show_num - 1;
492 if ($num_msgs < $show_num) {
493 $end_loop = $num_msgs;
494 } else if ($end > $num_msgs) {
495 $end_loop = $num_msgs - $start_msg +
1;
497 $end_loop = $show_num;
500 $msgs = fillMessageArray($imapConnection,$id,$end_loop, $show_num);
508 * This function loops through a group of messages in the mailbox
509 * and shows them to the user.
511 * @param mixed $imapConnection
512 * @param string $mailbox mail folder
513 * @param mixed $num_msgs
514 * @param mixed $start_msg
516 * @param mixed $color
517 * @param mixed $show_num
518 * @param mixed $use_cache
521 function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
522 $start_msg, $sort, $color, $show_num,
523 $use_cache, $mode='',$mbxresponse) {
524 global $msgs, $msort, $auto_expunge, $thread_sort_messages,
525 $allow_server_sort, $server_sort_order;
526 /* if there's no messages in this folder */
527 if ($mbxresponse['EXISTS'] == 0) {
528 $string = '<b>' . _("THIS FOLDER IS EMPTY") . '</b>';
529 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
531 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
532 echo ' <tr><td><br />';
533 echo ' <table cellpadding="1" cellspacing="5" align="center" border="0">';
534 echo ' <tr>' . html_tag( 'td', $string."\n", 'left')
537 echo ' <br /></td></tr>';
538 echo ' </table></td></tr>';
546 * For some reason, on PHP 4.3+, this being unset, and set in the session causes havoc
547 * so setting it to an empty array beforehand seems to clean up the issue, and stopping the
548 * "Your script possibly relies on a session side-effect which existed until PHP 4.2.3" error
551 if (!isset($msort)) {
559 //$start = microtime();
560 /* If autoexpunge is turned on, then do it now. */
561 //$mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox);
563 /* If autoexpunge is turned on, then do it now. */
564 //if ($auto_expunge == true) {
565 // $exp_cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, false, '');
566 // $mbxresponse['EXISTS'] = $mbxresponse['EXISTS'] - $exp_cnt;
567 // $num_msgs = $mbxresponse['EXISTS'];
570 if ($mbxresponse['EXISTS'] > 0) {
571 /* if $start_msg is lower than $num_msgs, we probably deleted all messages
572 * in the last page. We need to re-adjust the start_msg
575 if($start_msg > $num_msgs) {
576 $start_msg -= $show_num;
582 /* This code and the next if() block check for
583 * server-side sorting methods. The $id array is
584 * formatted and $sort is set to 6 to disable
585 * SM internal sorting
588 if ($thread_sort_messages == 1) {
590 } elseif ($allow_server_sort == 1) {
591 $mode = 'serversort';
597 sqgetGlobalVar('msgs', $msgs, SQ_SESSION
);
598 sqgetGlobalVar('msort', $msort, SQ_SESSION
);
600 sqsession_unregister('msort');
601 sqsession_unregister('msgs'); }
604 $msgs = getThreadMessages($imapConnection, $start_msg, $show_num, $num_msgs);
605 if ($msgs === false) {
606 echo '<b><small><center><font color=red>' .
607 _("Thread sorting is not supported by your IMAP server.") . '<br />' .
608 _("Please report this to the system administrator.").
609 '</center></small></b>';
610 $thread_sort_messages = 0;
611 $msort = $msgs = array();
614 $msort = calc_msort($msgs, $sort);
618 $msgs = getServerSortMessages($imapConnection, $start_msg, $show_num,
619 $num_msgs, $sort, $mbxresponse);
620 if ($msgs === false) {
621 echo '<b><small><center><font color=red>' .
622 _( "Server-side sorting is not supported by your IMAP server.") . '<br />' .
623 _("Please report this to the system administrator.").
624 '</center></small></b>';
625 $sort = $server_sort_order;
626 $allow_server_sort = FALSE;
627 $msort = $msgs = array();
631 $msort = calc_msort($msgs, $sort);
635 $msgs = getSelfSortMessages($imapConnection, $start_msg, $show_num,
636 $num_msgs, $sort, $mbxresponse);
637 $msort = calc_msort($msgs, $sort);
640 sqsession_register($msort, 'msort');
641 sqsession_register($msgs, 'msgs');
643 } /* if exists > 0 */
645 $res = getEndMessage($start_msg, $show_num, $num_msgs);
646 $start_msg = $res[0];
649 $paginator_str = get_paginator_str($mailbox, $start_msg, $end_msg,
650 $num_msgs, $show_num, $sort);
652 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
654 do_hook('mailbox_index_before');
656 <table border
="0" width
="100%" cellpadding
="0" cellspacing
="0">
659 <?php
mail_message_listing_beginning($imapConnection, $mbxresponse, $mailbox, $sort,
660 $msg_cnt_str, $paginator_str, $start_msg); ?
>
663 <tr
><td height
="5" bgcolor
="<?php echo $color[4]; ?>"></td
></tr
>
666 <table width
="100%" cellpadding
="1" cellspacing
="0" align
="center" border
="0" bgcolor
="<?php echo $color[9]; ?>">
669 <table width
="100%" cellpadding
="1" cellspacing
="0" align
="center" border
="0" bgcolor
="<?php echo $color[5]; ?>">
673 printHeader($mailbox, $srt, $color, !$thread_sort_messages, $start_msg);
674 displayMessageArray($imapConnection, $num_msgs, $start_msg,
675 $msort, $mailbox, $sort, $color, $show_num,0,0);
684 mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color);
690 //$t = elapsed($start);
691 //echo("elapsed time = $t seconds\n");
695 * FIXME: Undocumented function
697 * @param array $messages
698 * @param integer $sort sorting order
701 function calc_msort($msgs, $sort) {
711 if (($sort == 0) ||
($sort == 1)) {
712 foreach ($msgs as $item) {
713 $msort[$item['ID']] = $item['TIME_STAMP'];
715 } elseif (($sort == 2) ||
($sort == 3)) {
716 foreach ($msgs as $item) {
717 $msort[$item['ID']] = $item['FROM-SORT'];
719 } elseif (($sort == 4) ||
($sort == 5)) {
720 foreach ($msgs as $item) {
721 //echo $item['SUBJECT-SORT'] . "<br />";
722 $msort[$item['ID']] = $item['SUBJECT-SORT'];
725 return array_keys($msgs); //array_walk($msort, create_function('&$v,$k', '$v = $v["ID"];'));
733 $msort = array_keys($msort);
739 * FIXME: Undocumented function
741 * @param mixed $imapConnection
743 * @param mixed $count
744 * @param bool $show_num
746 function fillMessageArray($imapConnection, $id, $count, $show_num=false) {
747 return sqimap_get_small_header_list($imapConnection, $id, $show_num);
752 * Generic function to convert the msgs array into an HTML table.
754 * @param resource $imapConnection
755 * @param int $num_msgs total number of messages in the mailbox
756 * @param int $start_msg offset in messages to sisplay
757 * @param array $msort sorted array which is used to map the index to the unsorted $msgs index
758 * @param string $mailbox mail folder name
759 * @param int $sort sort order. 6 means no sorting or server side / thread sort
760 * @param array $color
761 * @param int $show_num number of messages to show
762 * @param mixed $where
768 // remove thread stuff
769 // remove $msgs global and add it as argument (i hate globals)
770 function displayMessageArray($imapConnection, $num_msgs, $start_msg,
771 $msort, $mailbox, $sort, $color,
772 $show_num, $where=0, $what=0) {
773 global $indent_array, $thread_sort_messages, $msgs;
775 /* get indent level for subject display */
776 // FIX ME this call is at the wrong place
777 if ($thread_sort_messages == 1 && $num_msgs) {
778 $indent_array = get_parent_level($imapConnection);
781 // if client side sorting and no sort we only fetch num_msgs so the start_msg in the $msgs
782 // array must be corrected
783 $i = ($sort == 6) ?
0 : $start_msg -1;
786 * Loop through and display the info for each message.
787 * ($t is used for the checkbox number)
789 $iEnd = $i +
$show_num;
790 for ($j=$i,$t=0;$j<$iEnd;++
$j) {
791 if (isset($msort[$j])) {
792 $msg = $msgs[$msort[$j]];
793 $last = (isset($msort[$j+
1]) ||
$j == $iEnd) ?
false : true;
794 printMessageInfo($t, $last, $msg, $mailbox,
795 $start_msg, $where, $what);
804 * Displays the standard message list header.
806 * To finish the table, you need to do a "</table></table>";
808 * @param mixed $imapConnection
809 * @param array $mbxresponse the array with the results of SELECT against the current mailbox
810 * @param string $mailbox the current mailbox
811 * @param mixed $sort the current sorting method (-1 for no sorting available [searches])
812 * @param mixed $msg_cnt_str
813 * @param mixed $paginator
814 * @param mixed $start_msg
816 function mail_message_listing_beginning ($imapConnection,
818 $mailbox = '', $sort = -1,
820 $paginator = ' ',
822 global $color, $auto_expunge, $base_uri, $show_flag_buttons,
823 $allow_server_sort, $server_sort_order,
824 $PHP_SELF, $allow_thread_sort, $thread_sort_messages;
826 $php_self = $PHP_SELF;
827 /* fix for incorrect $PHP_SELF */
828 if (strpos($php_self, 'move_messages.php')) {
829 $php_self = str_replace('move_messages.php', 'right_main.php', $php_self);
831 $urlMailbox = urlencode($mailbox);
833 if (preg_match('/^(.+)\?.+$/',$php_self,$regs)) {
834 $source_url = $regs[1];
836 $source_url = $php_self;
843 if (!strpos($php_self,'?')) {
844 $location = $php_self.'?mailbox=INBOX&startMessage=1';
846 $location = $php_self;
849 $moveFields = addHidden('msg', $msg).
850 addHidden('mailbox', $mailbox).
851 addHidden('startMessage', $start_msg).
852 addHidden('location', $location);
854 /* build thread sorting links */
855 if ($allow_thread_sort == TRUE) {
856 if ($thread_sort_messages == 1 ) {
858 $thread_name = _("Unthread View");
859 } elseif ($thread_sort_messages == 0) {
861 $thread_name = _("Thread View");
863 $thread_link_str = '<small>[<a href="' . $source_url . '?sort='
864 . $sort . '&start_messages=1&set_thread=' . $set_thread
865 . '&mailbox=' . urlencode($mailbox) . '">' . $thread_name
869 $thread_link_str ='';
872 * This is the beginning of the message list table.
873 * It wraps around all messages
875 $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $mailbox);
876 $form_name = "FormMsgs" . $safe_name;
878 echo '<form name="' . $form_name . '" method="post" action="move_messages.php">' ."\n"
881 <table width
="100%" cellpadding
="1" cellspacing
="0" style
="border: 1px solid <?php echo $color[0]; ?>">
884 <table bgcolor
="<?php echo $color[4]; ?>" border
="0" width
="100%" cellpadding
="1" cellspacing
="0">
886 <td align
="left"><small
><?php
echo $paginator . $thread_link_str; ?
></small
></td
>
887 <td align
="center"></td
>
888 <td align
="right"><small
><?php
echo $msg_cnt_str; ?
></small
></td
>
893 <tr width
="100%" cellpadding
="1" cellspacing
="0" border
="0" bgcolor
="<?php echo $color[0]; ?>">
895 <table border
="0" width
="100%" cellpadding
="1" cellspacing
="0">
900 // display flag buttons only if supported
901 if ($show_flag_buttons && $mbxresponse != NULL &&
902 array_search('\\flagged',$mbxresponse['PERMANENTFLAGS'], true) !== FALSE) {
903 echo getButton('SUBMIT', 'markUnflagged',_("Unflag"));
904 echo getButton('SUBMIT', 'markFlagged',_("Flag"));
907 if (array_search('\\seen',$mbxresponse['PERMANENTFLAGS'], true) !== FALSE) {
908 echo getButton('SUBMIT', 'markUnread',_("Unread"));
909 echo getButton('SUBMIT', 'markRead',_("Read"));
913 echo getButton('SUBMIT', 'attache',_("Forward"));
915 if (array_search('\\deleted',$mbxresponse['PERMANENTFLAGS'], true) !== FALSE) {
916 echo getButton('SUBMIT', 'delete',_("Delete"));
917 echo '<input type="checkbox" name="bypass_trash" />' . _("Bypass Trash");
920 if (!$auto_expunge && $mbxresponse['RIGHTS'] != 'READ-ONLY') {
921 echo getButton('SUBMIT', 'expungeButton',_("Expunge")) .' ' . _("mailbox") . "\n";
924 do_hook('mailbox_display_buttons');
928 if (array_search('\\deleted',$mbxresponse['PERMANENTFLAGS'], true) !== FALSE) {
929 echo '<td align="right">
931 //echo $thread_link_str; //previous behaviour
932 getMbxList($imapConnection);
933 echo getButton('SUBMIT', 'moveButton',_("Move")) . "\n
945 do_hook('mailbox_form_before');
947 /* if using server sort we highjack the
948 * the $sort var and use $server_sort_order
949 * instead. but here we reset sort for a bit
952 if ($allow_server_sort == TRUE) {
953 $sort = $server_sort_order;
958 * FIXME: Undocumented function
960 * @param mixed $num_msgs
961 * @param mixed $paginator_str
962 * @param mixed $msg_cnt_str
963 * @param mixed $color
965 function mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color) {
967 /* space between list and footer */
969 <tr
><td height
="5" bgcolor
="<?php echo $color[4]; ?>" colspan
="1"></td
></tr
>
972 <table width
="100%" cellpadding
="1" cellspacing
="0" style
="border: 1px solid <?php echo $color[0]; ?>">
975 <table bgcolor
="<?php echo $color[4]; ?>" border
="0" width
="100%" cellpadding
="1" cellspacing
="0">
977 <td align
="left"><small
><?php
echo $paginator_str; ?
></small
></td
>
978 <td align
="right"><small
><?php
echo $msg_cnt_str; ?
></small
></td
>
988 /* End of message-list table */
990 do_hook('mailbox_index_after');
995 * FIXME: Undocumented function
997 * @param string $mailbox
999 * @param mixed $color
1000 * @param bool $showsort
1001 * @param mixed $start_msg
1003 function printHeader($mailbox, $sort, $color, $showsort=true, $start_msg=1) {
1004 global $index_order;
1005 echo html_tag( 'tr' ,'' , 'center', $color[5] );
1007 /* calculate the width of the subject column based on the
1008 * widths of the other columns */
1009 $widths = array(1=>1,2=>25,3=>5,4=>0,5=>1,6=>5);
1010 $subjectwidth = 100;
1011 foreach($index_order as $item) {
1012 $subjectwidth -= $widths[$item];
1015 foreach ($index_order as $item) {
1017 case 1: /* checkbox */
1018 echo html_tag( 'td',get_selectall_link($start_msg, $sort, $mailbox) , '', '', 'width="1%"' );
1021 echo html_tag( 'td','' , '', '', 'width="1%"' );
1024 if (handleAsSent($mailbox)) {
1025 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
1026 . '<b>' . _("To") . '</b>';
1028 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
1029 . '<b>' . _("From") . '</b>';
1032 ShowSortButton($sort, $mailbox, 2, 3);
1037 echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
1038 . '<b>' . _("Date") . '</b>';
1040 ShowSortButton($sort, $mailbox, 0, 1);
1044 case 4: /* subject */
1045 echo html_tag( 'td' ,'' , 'left', '', 'width="'.$subjectwidth.'%"' )
1046 . '<b>' . _("Subject") . '</b>';
1048 ShowSortButton($sort, $mailbox, 4, 5);
1053 echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%" nowrap' );
1062 * This function shows the sort button. Isn't this a good comment?
1064 * @param mixed $sort
1065 * @param string $mailbox
1066 * @param mixed $Down
1069 function ShowSortButton($sort, $mailbox, $Down, $Up ) {
1072 /* Figure out which image we want to use. */
1073 if ($sort != $Up && $sort != $Down) {
1074 $img = 'sort_none.png';
1076 } elseif ($sort == $Up) {
1077 $img = 'up_pointer.png';
1080 $img = 'down_pointer.png';
1084 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
1085 $source_url = $regs[1];
1087 $source_url = $PHP_SELF;
1090 /* Now that we have everything figured out, show the actual button. */
1091 echo ' <a href="' . $source_url .'?newsort=' . $which
1092 . '&startMessage=1&mailbox=' . urlencode($mailbox)
1093 . '"><img src="../images/' . $img
1094 . '" border="0" width="12" height="10" alt="sort" title="'
1095 . _("Click here to change the sorting of the message list") .' /"></a>';
1099 * FIXME: Undocumented function
1101 * @param mixed $start_msg
1102 * @param mixed $sort
1103 * @param string $mailbox
1105 function get_selectall_link($start_msg, $sort, $mailbox) {
1106 global $checkall, $what, $where, $javascript_on;
1107 global $PHP_SELF, $PG_SHOWNUM;
1110 if ($javascript_on) {
1111 $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $mailbox);
1112 $func_name = "CheckAll" . $safe_name;
1113 $form_name = "FormMsgs" . $safe_name;
1114 $result = '<script language="JavaScript" type="text/javascript">'
1116 . "function " . $func_name . "() {\n"
1117 . " for (var i = 0; i < document." . $form_name . ".elements.length; i++) {\n"
1118 . " if(document." . $form_name . ".elements[i].type == 'checkbox' && "
1119 . " document." . $form_name . ".elements[i].name.substring(0,3) == 'msg'){\n"
1120 . " document." . $form_name . ".elements[i].checked = "
1121 . " !(document." . $form_name . ".elements[i].checked);\n"
1127 . '<input type="checkbox" name="toggleAll" title="'._("Toggle All").'" onclick="'.$func_name.'();" />';
1128 // . <a href="javascript:void(0)" onClick="' . $func_name . '();">' . _("Toggle All")
1131 if (strpos($PHP_SELF, "?")) {
1132 $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($mailbox)
1133 . "&startMessage=$start_msg&sort=$sort&checkall=";
1135 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
1136 . "&startMessage=$start_msg&sort=$sort&checkall=";
1138 if (isset($checkall) && $checkall == '1') {
1144 if (isset($where) && isset($what)) {
1145 $result .= '&where=' . urlencode($where)
1146 . '&what=' . urlencode($what);
1149 $result .= _("All");
1150 $result .= "</a>\n";
1153 /* Return our final result. */
1158 * This function computes the "Viewing Messages..." string.
1160 * @param integer $start_msg first message number
1161 * @param integer $end_msg last message number
1162 * @param integer $num_msgs total number of message in folder
1165 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
1166 /* Compute the $msg_cnt_str. */
1168 if ($start_msg < $end_msg) {
1169 $result = sprintf(_("Viewing Messages: %s to %s (%s total)"),
1170 '<b>'.$start_msg.'</b>', '<b>'.$end_msg.'</b>', $num_msgs);
1171 } else if ($start_msg == $end_msg) {
1172 $result = sprintf(_("Viewing Message: %s (1 total)"), '<b>'.$start_msg.'</b>');
1176 /* Return our result string. */
1181 * Generate a paginator link.
1184 * @param mixed $start_msg
1186 * @param string $text text used for paginator link
1189 function get_paginator_link($box, $start_msg, $use, $text) {
1191 $result = "<a href=\"right_main.php?use_mailbox_cache=$use"
1192 . "&startMessage=$start_msg&mailbox=$box\" "
1199 * This function computes the paginator string.
1202 * @param mixed $start_msg
1203 * @param mixed $end_msg
1204 * @param integer $num_msgs
1205 * @param mixed $show_num
1206 * @param mixed $sort
1208 function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
1210 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
1212 /* Initialize paginator string chunks. */
1218 $box = urlencode($box);
1220 /* Create simple strings that will be creating the paginator. */
1221 $spc = ' '; /* This will be used as a space. */
1222 $sep = '|'; /* This will be used as a seperator. */
1224 /* Get some paginator preference values. */
1225 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON
);
1226 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
);
1228 /* Make sure that our start message number is not too big. */
1229 $start_msg = min($start_msg, $num_msgs);
1231 /* Decide whether or not we will use the mailbox cache. */
1232 /* Not sure why $use_mailbox_cache is even passed in. */
1239 /* Compute the starting message of the previous and next page group. */
1240 $next_grp = $start_msg +
$show_num;
1241 $prev_grp = $start_msg - $show_num;
1243 /* Compute the basic previous and next strings. */
1244 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
1245 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1246 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1247 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
1248 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1249 $nxt_str = _("Next");
1250 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
1251 $prv_str = _("Previous");
1252 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1255 /* Page selector block. Following code computes page links. */
1256 if ($pg_sel && ($num_msgs > $show_num)) {
1257 /* Most importantly, what is the current page!!! */
1258 $cur_pg = intval($start_msg / $show_num) +
1;
1260 /* Compute total # of pages and # of paginator page links. */
1261 $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
1262 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
1264 /* Compute the size of the four quarters of the page links. */
1266 /* If we can, just show all the pages. */
1267 if (($tot_pgs - 1) <= $pg_max) {
1268 $q1_pgs = $cur_pg - 1;
1269 $q2_pgs = $q3_pgs = 0;
1270 $q4_pgs = $tot_pgs - $cur_pg;
1272 /* Otherwise, compute some magic to choose the four quarters. */
1275 * Compute the magic base values. Added together,
1276 * these values will always equal to the $pag_pgs.
1277 * NOTE: These are DEFAULT values and do not take
1278 * the current page into account. That is below.
1280 $q1_pgs = floor($vis_pgs/4);
1281 $q2_pgs = round($vis_pgs/4, 0);
1282 $q3_pgs = ceil($vis_pgs/4);
1283 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
1285 /* Adjust if the first quarter contains the current page. */
1286 if (($cur_pg - $q1_pgs) < 1) {
1287 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) +
$q2_pgs;
1288 $q1_pgs = $cur_pg - 1;
1290 $q3_pgs +
= ceil($extra_pgs / 2);
1291 $q4_pgs +
= floor($extra_pgs / 2);
1293 /* Adjust if the first and second quarters intersect. */
1294 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
1295 $extra_pgs = $q2_pgs;
1296 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 3/4);
1297 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 3/4);
1298 $q3_pgs +
= ceil($extra_pgs / 2);
1299 $q4_pgs +
= floor($extra_pgs / 2);
1301 /* Adjust if the fourth quarter contains the current page. */
1302 } else if (($cur_pg +
$q4_pgs) >= $tot_pgs) {
1303 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) +
$q3_pgs;
1305 $q4_pgs = $tot_pgs - $cur_pg;
1306 $q1_pgs +
= floor($extra_pgs / 2);
1307 $q2_pgs +
= ceil($extra_pgs / 2);
1309 /* Adjust if the third and fourth quarter intersect. */
1310 } else if (($cur_pg +
$q3_pgs +
1) >= ($tot_pgs - $q4_pgs +
1)) {
1311 $extra_pgs = $q3_pgs;
1312 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 3/4);
1313 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 3/4);
1314 $q1_pgs +
= floor($extra_pgs / 2);
1315 $q2_pgs +
= ceil($extra_pgs / 2);
1320 * I am leaving this debug code here, commented out, because
1321 * it is a really nice way to see what the above code is doing.
1322 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
1323 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br />';
1326 /* Print out the page links from the compute page quarters. */
1328 /* Start with the first quarter. */
1329 if (($q1_pgs == 0) && ($cur_pg > 1)) {
1330 $pg_str .= "...$spc";
1332 for ($pg = 1; $pg <= $q1_pgs; ++
$pg) {
1333 $start = (($pg-1) * $show_num) +
1;
1334 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1336 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
1337 $pg_str .= "...$spc";
1341 /* Continue with the second quarter. */
1342 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++
$pg) {
1343 $start = (($pg-1) * $show_num) +
1;
1344 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1347 /* Now print the current page. */
1348 $pg_str .= $cur_pg . $spc;
1350 /* Next comes the third quarter. */
1351 for ($pg = $cur_pg +
1; $pg <= $cur_pg +
$q3_pgs; ++
$pg) {
1352 $start = (($pg-1) * $show_num) +
1;
1353 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1356 /* And last, print the forth quarter page links. */
1357 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
1358 $pg_str .= "...$spc";
1360 if (($tot_pgs - $q4_pgs) > ($cur_pg +
$q3_pgs)) {
1361 $pg_str .= "...$spc";
1363 for ($pg = $tot_pgs - $q4_pgs +
1; $pg <= $tot_pgs; ++
$pg) {
1364 $start = (($pg-1) * $show_num) +
1;
1365 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1368 } else if ($PG_SHOWNUM == 999999) {
1369 $pg_str = "<a href=\"right_main.php?PG_SHOWALL=0"
1370 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1371 . ">" ._("Paginate") . '</a>';
1374 /* Put all the pieces of the paginator string together. */
1376 * Hairy code... But let's leave it like it is since I am not certain
1377 * a different approach would be any easier to read. ;)
1380 if ( $prv_str != '' ||
$nxt_str != '' )
1383 $result .= ($prv_str != '' ?
$prv_str . $spc . $sep . $spc : '');
1384 $result .= ($nxt_str != '' ?
$nxt_str : '');
1385 $result .= ']' . $spc ;
1387 /* Compute the 'show all' string. */
1388 $all_str = "<a href=\"right_main.php?PG_SHOWALL=1"
1389 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1390 . ">" . _("Show All") . '</a>';
1393 $result .= ($pg_str != '' ?
$spc . '['.$spc.$pg_str.']' . $spc : '');
1394 $result .= ($all_str != '' ?
$spc . '['.$all_str.']' . $spc . $spc : '');
1396 /* If the resulting string is blank, return a non-breaking space. */
1397 if ($result == '') {
1401 /* Return our final magical paginator string. */
1406 * FIXME: Undocumented function
1408 function truncateWithEntities($subject, $trim_at)
1410 $ent_strlen = strlen($subject);
1411 if (($trim_at <= 0) ||
($ent_strlen <= $trim_at))
1414 global $languages, $squirrelmail_language;
1417 * see if this is entities-encoded string
1418 * If so, Iterate through the whole string, find out
1419 * the real number of characters, and if more
1420 * than $trim_at, substr with an updated trim value.
1422 $trim_val = $trim_at;
1425 while ( $ent_loc < $trim_val && (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1426 (($ent_loc_end = strpos($subject, ';', $ent_loc+
3)) !== false) ) {
1427 $trim_val +
= ($ent_loc_end-$ent_loc);
1428 $ent_offset = $ent_loc_end+
1;
1430 if (($trim_val > $trim_at) && ($ent_strlen > $trim_val) && (strpos($subject,';',$trim_val) < ($trim_val +
6))) {
1431 $i = strpos($subject,';',$trim_val);
1433 $trim_val = strpos($subject,';',$trim_val);
1436 // only print '...' when we're actually dropping part of the subject
1437 if ($ent_strlen <= $trim_val)
1440 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
1441 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
1442 return $languages[$squirrelmail_language]['XTRA_CODE']('strimwidth', $subject, $trim_val);
1445 return substr_replace($subject, '...', $trim_val);
1449 * FIXME: Undocumented function
1451 function processSubject($subject, $threadlevel = 0) {
1452 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1453 if ($subject == '') {
1454 return _("(no subject)");
1457 global $truncate_subject; /* number of characters for Subject field (<= 0 for unchanged) */
1458 $trim_at = $truncate_subject;
1460 /* if this is threaded, subtract two chars per indentlevel */
1461 if (($threadlevel > 0) && ($threadlevel <= 10))
1462 $trim_at -= (2*$threadlevel);
1464 return truncateWithEntities($subject, $trim_at);
1468 * FIXME: Undocumented function
1470 * @param mixed $imapConnection
1471 * @param mixed $boxes
1473 function getMbxList($imapConnection, $boxes = 0) {
1474 global $lastTargetMailbox;
1475 echo ' <small> <tt><select name="targetMailbox">';
1476 echo sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)), 0, $boxes);
1477 echo ' </select></tt> ';
1483 * @deprecated see form functions available in 1.5.1 and 1.4.3.
1484 * @param string $type
1485 * @param string $name
1486 * @param string $value
1488 * @param bool $enabled
1490 function getButton($type, $name, $value, $js = '', $enabled = TRUE) {
1491 $disabled = ( $enabled ?
'' : 'disabled ' );
1492 $js = ( $js ?
$js.' ' : '' );
1493 return '<input '.$disabled.$js.
1496 '" value="'.$value .
1497 '" style="padding: 0px; margin: 0px" />';
1501 * Puts string into cell, aligns it and adds <small> tag
1503 * @param string $string string
1504 * @param string $align alignment
1506 function getSmallStringCell($string, $align) {
1507 return html_tag('td',
1508 '<small>' . $string . ': </small>',
1515 * FIXME: Undocumented function
1517 * @param integer $start_msg
1518 * @param integer $show_num
1519 * @param integer $num_msgs
1521 function getEndMessage($start_msg, $show_num, $num_msgs) {
1522 if ($start_msg +
($show_num - 1) < $num_msgs){
1523 $end_msg = $start_msg +
($show_num - 1);
1525 $end_msg = $num_msgs;
1528 if ($end_msg < $start_msg) {
1529 $start_msg = $start_msg - $show_num;
1530 if ($start_msg < 1) {
1534 return (array($start_msg,$end_msg));
1538 * This should go in imap_mailbox.php
1539 * @param string $mailbox
1541 function handleAsSent($mailbox) {
1542 global $handleAsSent_result;
1544 /* First check if this is the sent or draft folder. */
1545 $handleAsSent_result = isSentMailbox($mailbox) ||
isDraftMailbox($mailbox);
1547 /* Then check the result of the handleAsSent hook. */
1548 do_hook('check_handleAsSent_result', $mailbox);
1550 /* And return the result. */
1551 return $handleAsSent_result;