485e88569e5cea09f2b5c6dc5044eb78dca06db9
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 $imapConnection
51 * @param mixed $t UNDOCUMENTED
52 * @param bool $not_last UNDOCUMENTED
53 * @param mixed $key UNDOCUMENTED
54 * @param string $mailbox mail folder
55 * @param mixed $start_msg UNDOCUMENTED
56 * @param mixed $where UNDOCUMENTED
57 * @param mixed $what UNDOCUMENTED
59 function printMessageInfo($imapConnection, $t, $not_last=true, $key, $mailbox,
60 $start_msg, $where, $what) {
62 $color, $msgs, $msort, $td_str, $msg,
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 */
69 $server_sort_order, /* sort value when using server-sorting */
71 $allow_server_sort, /* enable/disable server-side sorting */
72 $truncate_sender, /* number of characters for From/To field (<= 0 for unchanged) */
74 $show_recipient_instead, /* show recipient name instead of default identity */
75 $use_icons, /* indicates to use icons or text markers */
76 $icon_theme; /* icons theming */
78 $color_string = $color[4];
80 if ($GLOBALS['alt_index_colors']) {
81 if (!isset($row_count)) {
86 if (!isset($color[12])) {
87 $color[12] = '#EAEAEA';
89 $color_string = $color[12];
94 if($mailbox == 'None') {
95 $boxes = sqimap_mailbox_list($imapConnection);
96 $mailbox = $boxes[0]['unformatted'];
99 $urlMailbox = urlencode($mailbox);
101 $bSentFolder = handleAsSent($mailbox);
102 if ((!$bSentFolder) && ($show_recipient_instead)) {
103 // If the From address is the same as $email_address, then handle as Sent
104 $from_array = parseAddress($msg['FROM'], 1);
105 if (!isset($email_address)) {
106 global $datadir, $username;
107 $email_address = getPref($datadir, $username, 'email_address');
109 $bHandleAsSent = ((isset($from_array[0][0])) && ($from_array[0][0] == $email_address));
112 $bHandleAsSent = $bSentFolder;
113 // If this is a Sent message, display To address instead of From
115 $msg['FROM'] = $msg['TO'];
116 // Passing 1 below results in only 1 address being parsed, thus defeating the following code
117 $msg['FROM'] = parseAddress($msg['FROM']/*,1*/);
120 * This is done in case you're looking into Sent folders,
121 * because you can have multiple receivers.
123 $senderNames = $msg['FROM'];
126 if (sizeof($senderNames)){
127 foreach ($senderNames as $senderNames_part) {
128 if ($senderName != '') {
130 $senderAddress .= ', ';
132 $sender_address_part = htmlspecialchars($senderNames_part[0]);
133 $sender_name_part = str_replace(' ',' ', decodeHeader($senderNames_part[1]));
134 if ($sender_name_part) {
135 $senderName .= $sender_name_part;
136 $senderAddress .= $sender_name_part . ' <' . $sender_address_part . '>';
138 $senderName .= $sender_address_part;
139 $senderAddress .= $sender_address_part;
143 // If Sent, prefix with To: but only if not Sent folder
144 if ($bHandleAsSent ^
$bSentFolder) {
145 $senderName = _("To:") . ' ' . $senderName;
146 $senderAddress = _("To:") . ' ' . $senderAddress;
149 if ($truncate_sender > 0)
150 $senderName = truncateWithEntities($senderName, $truncate_sender);
152 echo html_tag( 'tr','','','','VALIGN="top"') . "\n";
154 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
155 $flag = "<font color=\"$color[2]\">";
156 $flag_end = '</font>';
161 if (!isset($msg['FLAG_SEEN']) ||
($msg['FLAG_SEEN'] == false)) {
168 if ($bHandleAsSent) {
170 $italic_end = '</i>';
175 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
176 $fontstr = "<font color=\"$color[9]\">";
177 $fontstr_end = '</font>';
183 if ($where && $what) {
184 $searchstr = '&where='.$where.'&what='.$what;
189 if (is_array($message_highlight_list) && count($message_highlight_list)) {
190 $msg['TO'] = parseAddress($msg['TO']);
191 $msg['CC'] = parseAddress($msg['CC']);
192 foreach ($message_highlight_list as $message_highlight_list_part) {
193 if (trim($message_highlight_list_part['value']) != '') {
194 $high_val = strtolower($message_highlight_list_part['value']);
195 $match_type = strtoupper($message_highlight_list_part['match_type']);
196 if($match_type == 'TO_CC') {
197 $match = array('TO', 'CC');
199 $match = array($match_type);
201 foreach($match as $match_type) {
202 switch($match_type) {
206 foreach ($msg[$match_type] as $address) {
207 $address[0] = decodeHeader($address[0], true, false);
208 $address[1] = decodeHeader($address[1], true, false);
209 if (strstr('^^' . strtolower($address[0]), $high_val) ||
210 strstr('^^' . strtolower($address[1]), $high_val)) {
211 $hlt_color = $message_highlight_list_part['color'];
217 $headertest = strtolower(decodeHeader($msg[$match_type], true, false));
218 if (strstr('^^' . $headertest, $high_val)) {
219 $hlt_color = $message_highlight_list_part['color'];
229 if (!isset($hlt_color)) {
230 $hlt_color = $color_string;
233 $msg['SUBJECT'] = str_replace(' ', ' ', decodeHeader($msg['SUBJECT']));
234 $subject = processSubject($msg['SUBJECT'], $indent_array[$msg['ID']]);
235 if (sizeof($index_order)) {
236 foreach ($index_order as $index_order_part) {
237 switch ($index_order_part) {
238 case 1: /* checkbox */
240 addCheckBox("msg[$t]", $checkall, $msg['ID']),
245 if ($senderAddress != $senderName) {
246 $senderAddress = strtr($senderAddress, array_flip(get_html_translation_table(HTML_SPECIALCHARS
)));
247 $title = ' title="' . str_replace('"', "''", $senderAddress) . '"';
252 $italic . $bold . $flag . $fontstr . $senderName .
253 $fontstr_end . $flag_end . $bold_end . $italic_end,
255 $hlt_color, $title );
258 $date_string = $msg['DATE_STRING'] . '';
259 if ($date_string == '') {
260 $date_string = _("Unknown date");
263 $bold . $flag . $fontstr . $date_string .
264 $fontstr_end . $flag_end . $bold_end,
269 case 4: /* subject */
271 if ($thread_sort_messages == 1) {
272 if (isset($indent_array[$msg['ID']])) {
273 $td_str .= str_repeat(" ",$indent_array[$msg['ID']]);
276 $td_str .= '<a href="read_body.php?mailbox='.$urlMailbox
277 . '&passed_id='. $msg["ID"]
278 . '&startMessage='.$start_msg.$searchstr.'"';
279 $td_str .= ' ' .concat_hook_function('subject_link', array($start_msg, $searchstr));
280 if ($subject != $msg['SUBJECT']) {
281 $title = get_html_translation_table(HTML_SPECIALCHARS
);
282 $title = array_flip($title);
283 $title = strtr($msg['SUBJECT'], $title);
284 $title = str_replace('"', "''", $title);
285 $td_str .= " title=\"$title\"";
287 $td_str .= ">$flag$subject$flag_end</a>$bold_end";
288 echo html_tag( 'td', $td_str, 'left', $hlt_color );
292 // icon message markers
294 if ($use_icons && $icon_theme != 'none') {
295 $td_str = "<b><small>";
296 if (isset($msg['FLAG_FLAGGED']) && $msg['FLAG_FLAGGED'] == true) {
297 $td_str .= '<img src="' . SM_PATH
. 'images/themes/' . $icon_theme . '/flagged.png" border="0" height="10" width="10" /> ';
299 if ($default_use_priority) {
300 if ( ($msg['PRIORITY'] == 1) ||
($msg['PRIORITY'] == 2) ) {
301 $td_str .= '<img src="' . SM_PATH
. 'images/themes/' . $icon_theme . '/prio_high.png" border="0" height="10" width="5" /> ';
303 else if ($msg['PRIORITY'] == 5) {
304 $td_str .= '<img src="' . SM_PATH
. 'images/themes/' . $icon_theme . '/prio_low.png" border="0" height="10" width="5" /> ';
308 $td_str .= '<img src="' . SM_PATH
. 'images/themes/' . $icon_theme . '/transparent.png" border="0" width="5" /> ';
311 if ($msg['TYPE0'] == 'multipart') {
312 $td_str .= '<img src="' . SM_PATH
. 'images/themes/' . $icon_theme . '/attach.png" border="0" height="10" width="6" />';
316 $td_str .= '<img src="' . SM_PATH
. 'images/themes/' . $icon_theme . '/transparent.png" border="0" width="6" />';
320 if (!isset($msg['FLAG_SEEN']) ||
($msg['FLAG_SEEN']) == false)
322 $msg_alt = '(' . _("New") . ')';
323 $msg_title = '(' . _("New") . ')';
324 $msg_icon .= SM_PATH
. 'images/themes/' . $icon_theme . '/msg_new';
328 $msg_alt = '(' . _("Read") . ')';
329 $msg_title = '(' . _("Read") . ')';
330 $msg_icon .= SM_PATH
. 'images/themes/' . $icon_theme . '/msg_read';
332 if (isset($msg['FLAG_DELETED']) && ($msg['FLAG_DELETED']) == true)
334 $msg_icon .= '_deleted';
336 if (isset($msg['FLAG_ANSWERED']) && ($msg['FLAG_ANSWERED']) == true)
338 $msg_alt = '(' . _("Answered") . ')';
339 $msg_title = '(' . _("Answered") . ')';
340 $msg_icon .= '_reply';
342 $td_str .= '<img src="' . $msg_icon . '.png" border="0" alt="'. $msg_alt . '" title="' . $msg_title . '" height="12" width="18" />';
343 $td_str .= '</small></b>';
352 // plain text message markers
356 $td_str = "<b><small>";
357 if (isset($msg['FLAG_ANSWERED']) && $msg['FLAG_ANSWERED'] == true) {
361 if ($msg['TYPE0'] == 'multipart') {
365 if ($default_use_priority) {
366 if ( ($msg['PRIORITY'] == 1) ||
($msg['PRIORITY'] == 2) ) {
367 $td_str .= "<font color=\"$color[1]\">!</font>";
370 if ($msg['PRIORITY'] == 5) {
371 $td_str .= "<font color=\"$color[8]\">?</font>";
375 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'] == true) {
376 $td_str .= "<font color=\"$color[1]\">D</font>";
382 $td_str .= '</small></b>';
392 $bold . $fontstr . show_readable_size($msg['SIZE']) .
393 $fontstr_end . $bold_end,
402 echo '</tr>' . "\n" . '<tr><td colspan="' . $col . '" bgcolor="' .
403 $color[0] . '" height="1"></td></tr>' . "\n";
410 * FIXME: Undocumented function
412 * @param mixed $imapConnection
413 * @param mixed $start_msg
414 * @param mixed $show_num
415 * @param mixed $num_msgs
419 function getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id) {
421 $id = array_slice($id, ($start_msg-1), $show_num);
422 $end = $start_msg +
$show_num - 1;
423 if ($num_msgs < $show_num) {
424 $end_loop = $num_msgs;
425 } else if ($end > $num_msgs) {
426 $end_loop = $num_msgs - $start_msg +
1;
428 $end_loop = $show_num;
430 return fillMessageArray($imapConnection,$id,$end_loop,$show_num);
437 * FIXME: Undocumented function
439 * @param mixed $imapConnection
440 * @param mixed $start_msg
441 * @param mixed $show_num
442 * @param mixed $num_msgs
445 function getThreadMessages($imapConnection, $start_msg, $show_num, $num_msgs) {
446 $id = get_thread_sort($imapConnection);
447 return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
451 * FIXME: Undocumented function
453 * @param mixed $imapConnection
454 * @param mixed $start_msg
455 * @param mixed $show_num
456 * @param mixed $num_msgs
457 * @param mixed $server_sort_order
458 * @param mixed $mbxresponse
461 function getServerSortMessages($imapConnection, $start_msg, $show_num,
462 $num_msgs, $server_sort_order, $mbxresponse) {
463 if (isset($mbxresponse['SORT_ARRAY']) && is_array($mbxresponse['SORT_ARRAY'])) {
464 $id = $mbxresponse['SORT_ARRAY'];
466 $id = sqimap_get_sort_order($imapConnection, $server_sort_order,$mbxresponse);
468 return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
472 * FIXME: Undocumented function
474 * @param mixed $imapConnection
475 * @param mixed $start_msg
476 * @param mixed $show_num
477 * @param mixed $num_msgs
479 * @param mixed $mbxresponse
482 function getSelfSortMessages($imapConnection, $start_msg, $show_num,
483 $num_msgs, $sort, $mbxresponse) {
485 if ($num_msgs >= 1) {
486 $id = sqimap_get_php_sort_order ($imapConnection, $mbxresponse);
490 /* set shownum to 999999 to fool sqimap_get_small_header_list
491 and rebuild the msgs_str to 1:* */
494 /* if it's not sorted */
495 if ($start_msg +
($show_num - 1) < $num_msgs) {
496 $end_msg = $start_msg +
($show_num - 1);
498 $end_msg = $num_msgs;
500 if ($end_msg < $start_msg) {
501 $start_msg = $start_msg - $show_num;
502 if ($start_msg < 1) {
506 $id = array_slice(array_reverse($id), ($start_msg-1), $show_num);
507 $end = $start_msg +
$show_num - 1;
508 if ($num_msgs < $show_num) {
509 $end_loop = $num_msgs;
510 } else if ($end > $num_msgs) {
511 $end_loop = $num_msgs - $start_msg +
1;
513 $end_loop = $show_num;
516 $msgs = fillMessageArray($imapConnection,$id,$end_loop, $show_num);
524 * This function loops through a group of messages in the mailbox
525 * and shows them to the user.
527 * @param mixed $imapConnection
528 * @param string $mailbox mail folder
529 * @param mixed $num_msgs
530 * @param mixed $start_msg
532 * @param mixed $color
533 * @param mixed $show_num
534 * @param mixed $use_cache
537 function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
538 $start_msg, $sort, $color, $show_num,
539 $use_cache, $mode='',$mbxresponse) {
540 global $msgs, $msort, $auto_expunge, $thread_sort_messages,
541 $allow_server_sort, $server_sort_order;
544 * For some reason, on PHP 4.3+, this being unset, and set in the session causes havoc
545 * so setting it to an empty array beforehand seems to clean up the issue, and stopping the
546 * "Your script possibly relies on a session side-effect which existed until PHP 4.2.3" error
549 if (!isset($msort)) {
557 //$start = microtime();
558 /* If autoexpunge is turned on, then do it now. */
559 //$mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox);
561 /* If autoexpunge is turned on, then do it now. */
562 //if ($auto_expunge == true) {
563 // $exp_cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, false, '');
564 // $mbxresponse['EXISTS'] = $mbxresponse['EXISTS'] - $exp_cnt;
565 // $num_msgs = $mbxresponse['EXISTS'];
568 if ($mbxresponse['EXISTS'] > 0) {
569 /* if $start_msg is lower than $num_msgs, we probably deleted all messages
570 * in the last page. We need to re-adjust the start_msg
573 if($start_msg > $num_msgs) {
574 $start_msg -= $show_num;
580 /* This code and the next if() block check for
581 * server-side sorting methods. The $id array is
582 * formatted and $sort is set to 6 to disable
583 * SM internal sorting
586 if ($thread_sort_messages == 1) {
588 } elseif ($allow_server_sort == 1) {
589 $mode = 'serversort';
595 sqgetGlobalVar('msgs', $msgs, SQ_SESSION
);
596 sqgetGlobalVar('msort', $msort, SQ_SESSION
);
598 sqsession_unregister('msort');
599 sqsession_unregister('msgs'); }
602 $msgs = getThreadMessages($imapConnection, $start_msg, $show_num, $num_msgs);
603 if ($msgs === false) {
604 echo '<b><small><center><font color=red>' .
605 _("Thread sorting is not supported by your IMAP server.") . '<br />' .
606 _("Please report this to the system administrator.").
607 '</center></small></b>';
608 $thread_sort_messages = 0;
609 $msort = $msgs = array();
616 $msgs = getServerSortMessages($imapConnection, $start_msg, $show_num,
617 $num_msgs, $sort, $mbxresponse);
618 if ($msgs === false) {
619 echo '<b><small><center><font color=red>' .
620 _( "Server-side sorting is not supported by your IMAP server.") . '<br />' .
621 _("Please report this to the system administrator.").
622 '</center></small></b>';
623 $sort = $server_sort_order;
624 $allow_server_sort = FALSE;
625 $msort = $msgs = array();
634 $msgs = getSelfSortMessages($imapConnection, $start_msg, $show_num,
635 $num_msgs, $sort, $mbxresponse);
636 $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) {
712 if (($sort == 0) ||
($sort == 1)) {
713 foreach ($msgs as $item) {
714 $msort[] = $item['TIME_STAMP'];
716 } elseif (($sort == 2) ||
($sort == 3)) {
717 foreach ($msgs as $item) {
718 $msort[] = $item['FROM-SORT'];
720 } elseif (($sort == 4) ||
($sort == 5)) {
721 foreach ($msgs as $item) {
722 $msort[] = $item['SUBJECT-SORT'];
738 * FIXME: Undocumented function
740 * @param mixed $imapConnection
742 * @param mixed $count
743 * @param bool $show_num
745 function fillMessageArray($imapConnection, $id, $count, $show_num=false) {
746 return sqimap_get_small_header_list($imapConnection, $id, $show_num);
751 * Generic function to convert the msgs array into an HTML table.
753 * @param mixed $imapConnection
754 * @param mixed $num_msgs
755 * @param mixed $start_msg
756 * @param mixed $msort
757 * @param string $mailbox mail folder name
759 * @param mixed $color
760 * @param mixed $show_num
761 * @param mixed $where
764 function displayMessageArray($imapConnection, $num_msgs, $start_msg,
765 $msort, $mailbox, $sort, $color,
766 $show_num, $where=0, $what=0) {
767 global $imapServerAddress, $use_mailbox_cache, $index_order,
768 $indent_array, $thread_sort_messages, $allow_server_sort,
769 $server_sort_order, $PHP_SELF;
771 $res = getEndMessage($start_msg, $show_num, $num_msgs);
772 $start_msg = $res[0];
775 $urlMailbox = urlencode($mailbox);
777 /* get indent level for subject display */
778 if ($thread_sort_messages == 1 && $num_msgs) {
779 $indent_array = get_parent_level($imapConnection);
782 $real_startMessage = $start_msg;
784 if ($end_msg - $start_msg < $show_num - 1) {
785 $end_msg = $end_msg - $start_msg +
1;
787 } else if ($start_msg > $show_num) {
788 $end_msg = $show_num;
792 $endVar = $end_msg +
1;
795 * Loop through and display the info for each message.
796 * ($t is used for the checkbox number)
800 /* messages display */
803 /* if there's no messages in this folder */
806 "<br /><b>" . _("THIS FOLDER IS EMPTY") . "</b><br /> ",
809 'colspan="' . count($index_order) . '"'
812 } elseif ($start_msg == $end_msg) {
813 /* if there's only one message in the box, handle it differently. */
825 } while (isset ($key) && ($k < $i));
826 printMessageInfo($imapConnection, $t, true, $key, $mailbox,
827 $real_startMessage, $where, $what);
836 } while (isset ($key) && ($k < $i));
839 if (!$i ||
$i == $endVar-1) $not_last = false;
840 printMessageInfo($imapConnection, $t, $not_last, $key, $mailbox,
841 $real_startMessage, $where, $what);
846 } while ($i && $i < $endVar);
851 * Displays the standard message list header.
853 * To finish the table, you need to do a "</table></table>";
855 * @param mixed $imapConnection
856 * @param array $mbxresponse the array with the results of SELECT against the current mailbox
857 * @param string $mailbox the current mailbox
858 * @param mixed $sort the current sorting method (-1 for no sorting available [searches])
859 * @param mixed $msg_cnt_str
860 * @param mixed $paginator
861 * @param mixed $start_msg
863 function mail_message_listing_beginning ($imapConnection,
865 $mailbox = '', $sort = -1,
867 $paginator = ' ',
869 global $color, $auto_expunge, $base_uri, $show_flag_buttons,
870 $allow_server_sort, $server_sort_order,
871 $PHP_SELF, $allow_thread_sort, $thread_sort_messages;
873 $php_self = $PHP_SELF;
874 /* fix for incorrect $PHP_SELF */
875 if (strpos($php_self, 'move_messages.php')) {
876 $php_self = str_replace('move_messages.php', 'right_main.php', $php_self);
878 $urlMailbox = urlencode($mailbox);
880 if (preg_match('/^(.+)\?.+$/',$php_self,$regs)) {
881 $source_url = $regs[1];
883 $source_url = $php_self;
890 if (!strpos($php_self,'?')) {
891 $location = $php_self.'?mailbox=INBOX&startMessage=1';
893 $location = $php_self;
896 $moveFields = addHidden('msg', $msg).
897 addHidden('mailbox', $mailbox).
898 addHidden('startMessage', $start_msg).
899 addHidden('location', $location);
901 /* build thread sorting links */
902 if ($allow_thread_sort == TRUE) {
903 if ($thread_sort_messages == 1 ) {
905 $thread_name = _("Unthread View");
906 } elseif ($thread_sort_messages == 0) {
908 $thread_name = _("Thread View");
910 $thread_link_str = '<small>[<a href="' . $source_url . '?sort='
911 . $sort . '&start_messages=1&set_thread=' . $set_thread
912 . '&mailbox=' . urlencode($mailbox) . '">' . $thread_name
916 $thread_link_str ='';
919 * This is the beginning of the message list table.
920 * It wraps around all messages
922 $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $mailbox);
923 $form_name = "FormMsgs" . $safe_name;
925 echo '<form name="' . $form_name . '" method="post" action="move_messages.php">' ."\n"
928 <table width
="100%" cellpadding
="1" cellspacing
="0" style
="border: 1px solid <?php echo $color[0]; ?>">
931 <table bgcolor
="<?php echo $color[4]; ?>" border
="0" width
="100%" cellpadding
="1" cellspacing
="0">
933 <td align
="left"><small
><?php
echo $paginator . $thread_link_str; ?
></small
></td
>
934 <td align
="center"></td
>
935 <td align
="right"><small
><?php
echo $msg_cnt_str; ?
></small
></td
>
940 <tr width
="100%" cellpadding
="1" cellspacing
="0" border
="0" bgcolor
="<?php echo $color[0]; ?>">
942 <table border
="0" width
="100%" cellpadding
="1" cellspacing
="0">
947 // display flag buttons only if supported
948 if ($show_flag_buttons && $mbxresponse != NULL &&
949 array_search('\\flagged',$mbxresponse['PERMANENTFLAGS'], true) !== FALSE) {
950 echo getButton('SUBMIT', 'markUnflagged',_("Unflag"));
951 echo getButton('SUBMIT', 'markFlagged',_("Flag"));
954 if (array_search('\\seen',$mbxresponse['PERMANENTFLAGS'], true) !== FALSE) {
955 echo getButton('SUBMIT', 'markUnread',_("Unread"));
956 echo getButton('SUBMIT', 'markRead',_("Read"));
960 echo getButton('SUBMIT', 'attache',_("Forward"));
962 if (array_search('\\deleted',$mbxresponse['PERMANENTFLAGS'], true) !== FALSE) {
963 echo getButton('SUBMIT', 'delete',_("Delete"));
964 echo '<input type="checkbox" name="bypass_trash" />' . _("Bypass Trash");
967 if (!$auto_expunge && $mbxresponse['RIGHTS'] != 'READ-ONLY') {
968 echo getButton('SUBMIT', 'expungeButton',_("Expunge")) .' ' . _("mailbox") . "\n";
971 do_hook('mailbox_display_buttons');
975 if (array_search('\\deleted',$mbxresponse['PERMANENTFLAGS'], true) !== FALSE) {
976 echo '<td align="right">
978 //echo $thread_link_str; //previous behaviour
979 getMbxList($imapConnection);
980 echo getButton('SUBMIT', 'moveButton',_("Move")) . "\n
992 do_hook('mailbox_form_before');
994 /* if using server sort we highjack the
995 * the $sort var and use $server_sort_order
996 * instead. but here we reset sort for a bit
999 if ($allow_server_sort == TRUE) {
1000 $sort = $server_sort_order;
1005 * FIXME: Undocumented function
1007 * @param mixed $num_msgs
1008 * @param mixed $paginator_str
1009 * @param mixed $msg_cnt_str
1010 * @param mixed $color
1012 function mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color) {
1014 /* space between list and footer */
1016 <tr
><td height
="5" bgcolor
="<?php echo $color[4]; ?>" colspan
="1"></td
></tr
>
1019 <table width
="100%" cellpadding
="1" cellspacing
="0" style
="border: 1px solid <?php echo $color[0]; ?>">
1022 <table bgcolor
="<?php echo $color[4]; ?>" border
="0" width
="100%" cellpadding
="1" cellspacing
="0">
1024 <td align
="left"><small
><?php
echo $paginator_str; ?
></small
></td
>
1025 <td align
="right"><small
><?php
echo $msg_cnt_str; ?
></small
></td
>
1035 /* End of message-list table */
1037 do_hook('mailbox_index_after');
1042 * FIXME: Undocumented function
1044 * @param string $mailbox
1045 * @param mixed $sort
1046 * @param mixed $color
1047 * @param bool $showsort
1048 * @param mixed $start_msg
1050 function printHeader($mailbox, $sort, $color, $showsort=true, $start_msg=1) {
1051 global $index_order;
1052 echo html_tag( 'tr' ,'' , 'center', $color[5] );
1054 /* calculate the width of the subject column based on the
1055 * widths of the other columns */
1056 $widths = array(1=>1,2=>25,3=>5,4=>0,5=>1,6=>5);
1057 $subjectwidth = 100;
1058 foreach($index_order as $item) {
1059 $subjectwidth -= $widths[$item];
1062 foreach ($index_order as $item) {
1064 case 1: /* checkbox */
1065 echo html_tag( 'td',get_selectall_link($start_msg, $sort, $mailbox) , '', '', 'width="1%"' );
1068 echo html_tag( 'td','' , '', '', 'width="1%"' );
1071 if (handleAsSent($mailbox)) {
1072 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
1073 . '<b>' . _("To") . '</b>';
1075 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
1076 . '<b>' . _("From") . '</b>';
1079 ShowSortButton($sort, $mailbox, 2, 3);
1084 echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
1085 . '<b>' . _("Date") . '</b>';
1087 ShowSortButton($sort, $mailbox, 0, 1);
1091 case 4: /* subject */
1092 echo html_tag( 'td' ,'' , 'left', '', 'width="'.$subjectwidth.'%"' )
1093 . '<b>' . _("Subject") . '</b>';
1095 ShowSortButton($sort, $mailbox, 4, 5);
1100 echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%" nowrap' );
1109 * This function shows the sort button. Isn't this a good comment?
1111 * @param mixed $sort
1112 * @param string $mailbox
1113 * @param mixed $Down
1116 function ShowSortButton($sort, $mailbox, $Down, $Up ) {
1119 /* Figure out which image we want to use. */
1120 if ($sort != $Up && $sort != $Down) {
1121 $img = 'sort_none.png';
1123 } elseif ($sort == $Up) {
1124 $img = 'up_pointer.png';
1127 $img = 'down_pointer.png';
1131 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
1132 $source_url = $regs[1];
1134 $source_url = $PHP_SELF;
1137 /* Now that we have everything figured out, show the actual button. */
1138 echo ' <a href="' . $source_url .'?newsort=' . $which
1139 . '&startMessage=1&mailbox=' . urlencode($mailbox)
1140 . '"><img src="../images/' . $img
1141 . '" border="0" width="12" height="10" alt="sort" title="'
1142 . _("Click here to change the sorting of the message list") .' /"></a>';
1146 * FIXME: Undocumented function
1148 * @param mixed $start_msg
1149 * @param mixed $sort
1150 * @param string $mailbox
1152 function get_selectall_link($start_msg, $sort, $mailbox) {
1153 global $checkall, $what, $where, $javascript_on;
1154 global $PHP_SELF, $PG_SHOWNUM;
1157 if ($javascript_on) {
1158 $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $mailbox);
1159 $func_name = "CheckAll" . $safe_name;
1160 $form_name = "FormMsgs" . $safe_name;
1161 $result = '<script language="JavaScript" type="text/javascript">'
1163 . "function " . $func_name . "() {\n"
1164 . " for (var i = 0; i < document." . $form_name . ".elements.length; i++) {\n"
1165 . " if(document." . $form_name . ".elements[i].type == 'checkbox' && "
1166 . " document." . $form_name . ".elements[i].name.substring(0,3) == 'msg'){\n"
1167 . " document." . $form_name . ".elements[i].checked = "
1168 . " !(document." . $form_name . ".elements[i].checked);\n"
1174 . '<input type="checkbox" name="toggleAll" title="'._("Toggle All").'" onclick="'.$func_name.'();" />';
1175 // . <a href="javascript:void(0)" onClick="' . $func_name . '();">' . _("Toggle All")
1178 if (strpos($PHP_SELF, "?")) {
1179 $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($mailbox)
1180 . "&startMessage=$start_msg&sort=$sort&checkall=";
1182 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
1183 . "&startMessage=$start_msg&sort=$sort&checkall=";
1185 if (isset($checkall) && $checkall == '1') {
1191 if (isset($where) && isset($what)) {
1192 $result .= '&where=' . urlencode($where)
1193 . '&what=' . urlencode($what);
1196 $result .= _("All");
1197 $result .= "</a>\n";
1200 /* Return our final result. */
1205 * This function computes the "Viewing Messages..." string.
1207 * @param integer $start_msg first message number
1208 * @param integer $end_msg last message number
1209 * @param integer $num_msgs total number of message in folder
1212 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
1213 /* Compute the $msg_cnt_str. */
1215 if ($start_msg < $end_msg) {
1216 $result = sprintf(_("Viewing Messages: %s to %s (%s total)"),
1217 '<b>'.$start_msg.'</b>', '<b>'.$end_msg.'</b>', $num_msgs);
1218 } else if ($start_msg == $end_msg) {
1219 $result = sprintf(_("Viewing Message: %s (1 total)"), '<b>'.$start_msg.'</b>');
1223 /* Return our result string. */
1228 * Generate a paginator link.
1231 * @param mixed $start_msg
1233 * @param string $text text used for paginator link
1236 function get_paginator_link($box, $start_msg, $use, $text) {
1238 $result = "<a href=\"right_main.php?use_mailbox_cache=$use"
1239 . "&startMessage=$start_msg&mailbox=$box\" "
1246 * This function computes the paginator string.
1249 * @param mixed $start_msg
1250 * @param mixed $end_msg
1251 * @param integer $num_msgs
1252 * @param mixed $show_num
1253 * @param mixed $sort
1255 function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
1257 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
1259 /* Initialize paginator string chunks. */
1265 $box = urlencode($box);
1267 /* Create simple strings that will be creating the paginator. */
1268 $spc = ' '; /* This will be used as a space. */
1269 $sep = '|'; /* This will be used as a seperator. */
1271 /* Get some paginator preference values. */
1272 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON
);
1273 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
);
1275 /* Make sure that our start message number is not too big. */
1276 $start_msg = min($start_msg, $num_msgs);
1278 /* Decide whether or not we will use the mailbox cache. */
1279 /* Not sure why $use_mailbox_cache is even passed in. */
1286 /* Compute the starting message of the previous and next page group. */
1287 $next_grp = $start_msg +
$show_num;
1288 $prev_grp = $start_msg - $show_num;
1290 /* Compute the basic previous and next strings. */
1291 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
1292 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1293 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1294 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
1295 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1296 $nxt_str = _("Next");
1297 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
1298 $prv_str = _("Previous");
1299 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1302 /* Page selector block. Following code computes page links. */
1303 if ($pg_sel && ($num_msgs > $show_num)) {
1304 /* Most importantly, what is the current page!!! */
1305 $cur_pg = intval($start_msg / $show_num) +
1;
1307 /* Compute total # of pages and # of paginator page links. */
1308 $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
1309 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
1311 /* Compute the size of the four quarters of the page links. */
1313 /* If we can, just show all the pages. */
1314 if (($tot_pgs - 1) <= $pg_max) {
1315 $q1_pgs = $cur_pg - 1;
1316 $q2_pgs = $q3_pgs = 0;
1317 $q4_pgs = $tot_pgs - $cur_pg;
1319 /* Otherwise, compute some magic to choose the four quarters. */
1322 * Compute the magic base values. Added together,
1323 * these values will always equal to the $pag_pgs.
1324 * NOTE: These are DEFAULT values and do not take
1325 * the current page into account. That is below.
1327 $q1_pgs = floor($vis_pgs/4);
1328 $q2_pgs = round($vis_pgs/4, 0);
1329 $q3_pgs = ceil($vis_pgs/4);
1330 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
1332 /* Adjust if the first quarter contains the current page. */
1333 if (($cur_pg - $q1_pgs) < 1) {
1334 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) +
$q2_pgs;
1335 $q1_pgs = $cur_pg - 1;
1337 $q3_pgs +
= ceil($extra_pgs / 2);
1338 $q4_pgs +
= floor($extra_pgs / 2);
1340 /* Adjust if the first and second quarters intersect. */
1341 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
1342 $extra_pgs = $q2_pgs;
1343 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 3/4);
1344 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 3/4);
1345 $q3_pgs +
= ceil($extra_pgs / 2);
1346 $q4_pgs +
= floor($extra_pgs / 2);
1348 /* Adjust if the fourth quarter contains the current page. */
1349 } else if (($cur_pg +
$q4_pgs) >= $tot_pgs) {
1350 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) +
$q3_pgs;
1352 $q4_pgs = $tot_pgs - $cur_pg;
1353 $q1_pgs +
= floor($extra_pgs / 2);
1354 $q2_pgs +
= ceil($extra_pgs / 2);
1356 /* Adjust if the third and fourth quarter intersect. */
1357 } else if (($cur_pg +
$q3_pgs +
1) >= ($tot_pgs - $q4_pgs +
1)) {
1358 $extra_pgs = $q3_pgs;
1359 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 3/4);
1360 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 3/4);
1361 $q1_pgs +
= floor($extra_pgs / 2);
1362 $q2_pgs +
= ceil($extra_pgs / 2);
1367 * I am leaving this debug code here, commented out, because
1368 * it is a really nice way to see what the above code is doing.
1369 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
1370 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br />';
1373 /* Print out the page links from the compute page quarters. */
1375 /* Start with the first quarter. */
1376 if (($q1_pgs == 0) && ($cur_pg > 1)) {
1377 $pg_str .= "...$spc";
1379 for ($pg = 1; $pg <= $q1_pgs; ++
$pg) {
1380 $start = (($pg-1) * $show_num) +
1;
1381 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1383 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
1384 $pg_str .= "...$spc";
1388 /* Continue with the second quarter. */
1389 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++
$pg) {
1390 $start = (($pg-1) * $show_num) +
1;
1391 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1394 /* Now print the current page. */
1395 $pg_str .= $cur_pg . $spc;
1397 /* Next comes the third quarter. */
1398 for ($pg = $cur_pg +
1; $pg <= $cur_pg +
$q3_pgs; ++
$pg) {
1399 $start = (($pg-1) * $show_num) +
1;
1400 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1403 /* And last, print the forth quarter page links. */
1404 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
1405 $pg_str .= "...$spc";
1407 if (($tot_pgs - $q4_pgs) > ($cur_pg +
$q3_pgs)) {
1408 $pg_str .= "...$spc";
1410 for ($pg = $tot_pgs - $q4_pgs +
1; $pg <= $tot_pgs; ++
$pg) {
1411 $start = (($pg-1) * $show_num) +
1;
1412 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1415 } else if ($PG_SHOWNUM == 999999) {
1416 $pg_str = "<a href=\"right_main.php?PG_SHOWALL=0"
1417 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1418 . ">" ._("Paginate") . '</a>';
1421 /* Put all the pieces of the paginator string together. */
1423 * Hairy code... But let's leave it like it is since I am not certain
1424 * a different approach would be any easier to read. ;)
1427 if ( $prv_str != '' ||
$nxt_str != '' )
1430 $result .= ($prv_str != '' ?
$prv_str . $spc . $sep . $spc : '');
1431 $result .= ($nxt_str != '' ?
$nxt_str : '');
1432 $result .= ']' . $spc ;
1434 /* Compute the 'show all' string. */
1435 $all_str = "<a href=\"right_main.php?PG_SHOWALL=1"
1436 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1437 . ">" . _("Show All") . '</a>';
1440 $result .= ($pg_str != '' ?
$spc . '['.$spc.$pg_str.']' . $spc : '');
1441 $result .= ($all_str != '' ?
$spc . '['.$all_str.']' . $spc . $spc : '');
1443 /* If the resulting string is blank, return a non-breaking space. */
1444 if ($result == '') {
1448 /* Return our final magical paginator string. */
1453 * FIXME: Undocumented function
1455 function truncateWithEntities($subject, $trim_at)
1457 $ent_strlen = strlen($subject);
1458 if (($trim_at <= 0) ||
($ent_strlen <= $trim_at))
1461 global $languages, $squirrelmail_language;
1464 * see if this is entities-encoded string
1465 * If so, Iterate through the whole string, find out
1466 * the real number of characters, and if more
1467 * than $trim_at, substr with an updated trim value.
1469 $trim_val = $trim_at;
1472 while ( $ent_loc < $trim_val && (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1473 (($ent_loc_end = strpos($subject, ';', $ent_loc+
3)) !== false) ) {
1474 $trim_val +
= ($ent_loc_end-$ent_loc);
1475 $ent_offset = $ent_loc_end+
1;
1477 if (($trim_val > $trim_at) && ($ent_strlen > $trim_val) && (strpos($subject,';',$trim_val) < ($trim_val +
6))) {
1478 $i = strpos($subject,';',$trim_val);
1480 $trim_val = strpos($subject,';',$trim_val);
1483 // only print '...' when we're actually dropping part of the subject
1484 if ($ent_strlen <= $trim_val)
1487 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
1488 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
1489 return $languages[$squirrelmail_language]['XTRA_CODE']('strimwidth', $subject, $trim_val);
1492 return substr_replace($subject, '...', $trim_val);
1496 * FIXME: Undocumented function
1498 function processSubject($subject, $threadlevel = 0) {
1499 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1500 if ($subject == '') {
1501 return _("(no subject)");
1504 global $truncate_subject; /* number of characters for Subject field (<= 0 for unchanged) */
1505 $trim_at = $truncate_subject;
1507 /* if this is threaded, subtract two chars per indentlevel */
1508 if (($threadlevel > 0) && ($threadlevel <= 10))
1509 $trim_at -= (2*$threadlevel);
1511 return truncateWithEntities($subject, $trim_at);
1515 * FIXME: Undocumented function
1517 * @param mixed $imapConnection
1518 * @param mixed $boxes
1520 function getMbxList($imapConnection, $boxes = 0) {
1521 global $lastTargetMailbox;
1522 echo ' <small> <tt><select name="targetMailbox">';
1523 echo sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)), 0, $boxes);
1524 echo ' </select></tt> ';
1530 * @deprecated see form functions available in 1.5.1 and 1.4.3.
1531 * @param string $type
1532 * @param string $name
1533 * @param string $value
1535 * @param bool $enabled
1537 function getButton($type, $name, $value, $js = '', $enabled = TRUE) {
1538 $disabled = ( $enabled ?
'' : 'disabled ' );
1539 $js = ( $js ?
$js.' ' : '' );
1540 return '<input '.$disabled.$js.
1543 '" value="'.$value .
1544 '" style="padding: 0px; margin: 0px" />';
1548 * Puts string into cell, aligns it and adds <small> tag
1550 * @param string $string string
1551 * @param string $align alignment
1553 function getSmallStringCell($string, $align) {
1554 return html_tag('td',
1555 '<small>' . $string . ': </small>',
1562 * FIXME: Undocumented function
1564 * @param integer $start_msg
1565 * @param integer $show_num
1566 * @param integer $num_msgs
1568 function getEndMessage($start_msg, $show_num, $num_msgs) {
1569 if ($start_msg +
($show_num - 1) < $num_msgs){
1570 $end_msg = $start_msg +
($show_num - 1);
1572 $end_msg = $num_msgs;
1575 if ($end_msg < $start_msg) {
1576 $start_msg = $start_msg - $show_num;
1577 if ($start_msg < 1) {
1581 return (array($start_msg,$end_msg));
1585 * This should go in imap_mailbox.php
1586 * @param string $mailbox
1588 function handleAsSent($mailbox) {
1589 global $handleAsSent_result;
1591 /* First check if this is the sent or draft folder. */
1592 $handleAsSent_result = isSentMailbox($mailbox) ||
isDraftMailbox($mailbox);
1594 /* Then check the result of the handleAsSent hook. */
1595 do_hook('check_handleAsSent_result', $mailbox);
1597 /* And return the result. */
1598 return $handleAsSent_result;