6e93c81ec2ac3ed07dbeaa976740033140bcc3a4
6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This contains functions that display mailbox information, such as the
10 * table row that has sender, date, subject, etc...
13 * @package squirrelmail
16 /** The standard includes.. */
17 require_once(SM_PATH
. 'functions/strings.php');
18 require_once(SM_PATH
. 'functions/html.php');
19 require_once(SM_PATH
. 'class/html.class.php');
20 require_once(SM_PATH
. 'functions/imap_mailbox.php');
21 require_once(SM_PATH
. 'functions/imap_messages.php');
22 require_once(SM_PATH
. 'functions/mime.php');
25 * default value for page_selector_max
27 define('PG_SEL_MAX', 10);
30 * @param mixed $start UNDOCUMENTED
32 function elapsed($start)
35 list($start2, $start1) = explode(" ", $start);
36 list($end2, $end1) = explode(" ", $end);
37 $diff1 = $end1 - $start1;
38 $diff2 = $end2 - $start2;
43 return $diff2 +
$diff1;
46 function printMessageInfo($imapConnection, $t, $not_last=true, $key, $mailbox,
47 $start_msg, $where, $what) {
49 $color, $msgs, $msort, $td_str, $msg,
50 $default_use_priority,
51 $message_highlight_list,
53 $indent_array, /* indent subject by */
54 $pos, /* Search postion (if any) */
55 $thread_sort_messages, /* thread sorting on/off */
56 $server_sort_order, /* sort value when using server-sorting */
58 $allow_server_sort, /* enable/disable server-side sorting */
59 $truncate_sender, /* number of characters for From/To field (<= 0 for unchanged) */
61 $show_recipient_instead, /* show recipient name instead of default identity */
62 $use_icons, /* indicates to use icons or text markers */
63 $icon_theme; /* icons theming */
65 $color_string = $color[4];
67 if ($GLOBALS['alt_index_colors']) {
68 if (!isset($row_count)) {
73 if (!isset($color[12])) {
74 $color[12] = '#EAEAEA';
76 $color_string = $color[12];
81 if($mailbox == 'None') {
82 $boxes = sqimap_mailbox_list($imapConnection);
83 $mailbox = $boxes[0]['unformatted'];
86 $urlMailbox = urlencode($mailbox);
88 $bSentFolder = handleAsSent($mailbox);
89 if ((!$bSentFolder) && ($show_recipient_instead)) {
90 // If the From address is the same as $email_address, then handle as Sent
91 $from_array = parseAddress($msg['FROM'], 1);
92 if (!isset($email_address)) {
93 global $datadir, $username;
94 $email_address = getPref($datadir, $username, 'email_address');
96 $bHandleAsSent = ((isset($from_array[0][0])) && ($from_array[0][0] == $email_address));
99 $bHandleAsSent = $bSentFolder;
100 // If this is a Sent message, display To address instead of From
102 $msg['FROM'] = $msg['TO'];
103 // Passing 1 below results in only 1 address being parsed, thus defeating the following code
104 $msg['FROM'] = parseAddress($msg['FROM']/*,1*/);
107 * This is done in case you're looking into Sent folders,
108 * because you can have multiple receivers.
110 $senderNames = $msg['FROM'];
113 if (sizeof($senderNames)){
114 foreach ($senderNames as $senderNames_part) {
115 if ($senderName != '') {
117 $senderAddress .= ', ';
119 $sender_address_part = htmlspecialchars($senderNames_part[0]);
120 $sender_name_part = str_replace(' ',' ', decodeHeader($senderNames_part[1]));
121 if ($sender_name_part) {
122 $senderName .= $sender_name_part;
123 $senderAddress .= $sender_name_part . ' <' . $sender_address_part . '>';
125 $senderName .= $sender_address_part;
126 $senderAddress .= $sender_address_part;
130 // If Sent, prefix with To: but only if not Sent folder
131 if ($bHandleAsSent ^
$bSentFolder) {
132 $senderName = _("To:") . ' ' . $senderName;
133 $senderAddress = _("To:") . ' ' . $senderAddress;
136 if ($truncate_sender > 0)
137 $senderName = truncateWithEntities($senderName, $truncate_sender);
139 echo html_tag( 'tr','','','','VALIGN="top"') . "\n";
141 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
142 $flag = "<font color=\"$color[2]\">";
143 $flag_end = '</font>';
148 if (!isset($msg['FLAG_SEEN']) ||
($msg['FLAG_SEEN'] == false)) {
155 if ($bHandleAsSent) {
157 $italic_end = '</i>';
162 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
163 $fontstr = "<font color=\"$color[9]\">";
164 $fontstr_end = '</font>';
170 if ($where && $what) {
171 $searchstr = '&where='.$where.'&what='.$what;
176 if (is_array($message_highlight_list) && count($message_highlight_list)) {
177 $msg['TO'] = parseAddress($msg['TO']);
178 $msg['CC'] = parseAddress($msg['CC']);
179 foreach ($message_highlight_list as $message_highlight_list_part) {
180 if (trim($message_highlight_list_part['value']) != '') {
181 $high_val = strtolower($message_highlight_list_part['value']);
182 $match_type = strtoupper($message_highlight_list_part['match_type']);
183 if($match_type == 'TO_CC') {
184 $match = array('TO', 'CC');
186 $match = array($match_type);
188 foreach($match as $match_type) {
189 switch($match_type) {
193 foreach ($msg[$match_type] as $address) {
194 $address[0] = decodeHeader($address[0], true, false);
195 $address[1] = decodeHeader($address[1], true, false);
196 if (strstr('^^' . strtolower($address[0]), $high_val) ||
197 strstr('^^' . strtolower($address[1]), $high_val)) {
198 $hlt_color = $message_highlight_list_part['color'];
204 $headertest = strtolower(decodeHeader($msg[$match_type], true, false));
205 if (strstr('^^' . $headertest, $high_val)) {
206 $hlt_color = $message_highlight_list_part['color'];
216 if (!isset($hlt_color)) {
217 $hlt_color = $color_string;
219 $checked = ($checkall == 1) ?
' CHECKED' : '';
221 $msg['SUBJECT'] = str_replace(' ', ' ', decodeHeader($msg['SUBJECT']));
222 $subject = processSubject($msg['SUBJECT'], $indent_array[$msg['ID']]);
223 if (sizeof($index_order)) {
224 foreach ($index_order as $index_order_part) {
225 switch ($index_order_part) {
226 case 1: /* checkbox */
228 "<input type=checkbox name=\"msg[$t]\" value=\"".$msg['ID']."\"$checked>",
233 if ($senderAddress != $senderName) {
234 $senderAddress = strtr($senderAddress, array_flip(get_html_translation_table(HTML_SPECIALCHARS
)));
235 $title = ' title="' . str_replace('"', "''", $senderAddress) . '"';
240 $italic . $bold . $flag . $fontstr . $senderName .
241 $fontstr_end . $flag_end . $bold_end . $italic_end,
243 $hlt_color, $title );
246 $date_string = $msg['DATE_STRING'] . '';
247 if ($date_string == '') {
248 $date_string = _("Unknown date");
251 $bold . $flag . $fontstr . $date_string .
252 $fontstr_end . $flag_end . $bold_end,
257 case 4: /* subject */
259 if ($thread_sort_messages == 1) {
260 if (isset($indent_array[$msg['ID']])) {
261 $td_str .= str_repeat(" ",$indent_array[$msg['ID']]);
264 $td_str .= '<a href="read_body.php?mailbox='.$urlMailbox
265 . '&passed_id='. $msg["ID"]
266 . '&startMessage='.$start_msg.$searchstr.'"';
267 $td_str .= ' ' .concat_hook_function('subject_link', array($start_msg, $searchstr));
268 if ($subject != $msg['SUBJECT']) {
269 $title = get_html_translation_table(HTML_SPECIALCHARS
);
270 $title = array_flip($title);
271 $title = strtr($msg['SUBJECT'], $title);
272 $title = str_replace('"', "''", $title);
273 $td_str .= " title=\"$title\"";
275 $td_str .= ">$flag$subject$flag_end</a>$bold_end";
276 echo html_tag( 'td', $td_str, 'left', $hlt_color );
280 // icon message markers
282 if ($use_icons && $icon_theme != 'none') {
283 $td_str = "<b><small>";
284 if (isset($msg['FLAG_FLAGGED']) && $msg['FLAG_FLAGGED'] == true) {
285 $td_str .= _('<IMG SRC="' . SM_PATH
. 'images/themes/' . $icon_theme . '/flagged.gif" border="0" height="10" width="10"> ');
287 if ($default_use_priority) {
288 if ( ($msg['PRIORITY'] == 1) ||
($msg['PRIORITY'] == 2) ) {
289 $td_str .= '<IMG SRC="' . SM_PATH
. 'images/themes/' . $icon_theme . '/prio_high.gif" border="0" height="10" width="5"> ';
291 else if ($msg['PRIORITY'] == 5) {
292 $td_str .= '<IMG SRC="' . SM_PATH
. 'images/themes/' . $icon_theme . '/prio_low.gif" border="0" height="10" width="5"> ';
296 $td_str .= '<IMG SRC="' . SM_PATH
. 'images/themes/' . $icon_theme . '/transparent.gif" border="0" width="5"> ';
299 if ($msg['TYPE0'] == 'multipart') {
300 $td_str .= '<IMG SRC="' . SM_PATH
. 'images/themes/' . $icon_theme . '/attach.gif" border="0" height="10" width="6">';
304 $td_str .= '<IMG SRC="' . SM_PATH
. 'images/themes/' . $icon_theme . '/transparent.gif" border="0" width="6">';
308 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';
316 $msg_alt = '(' . _("Read") . ')';
317 $msg_title = '(' . _("Read") . ')';
318 $msg_icon .= SM_PATH
. 'images/themes/' . $icon_theme . '/msg_read';
320 if (isset($msg['FLAG_DELETED']) && ($msg['FLAG_DELETED']) == true)
322 $msg_icon .= '_deleted';
324 if (isset($msg['FLAG_ANSWERED']) && ($msg['FLAG_ANSWERED']) == true)
326 $msg_icon .= '_reply';
328 $td_str .= '<IMG SRC="' . $msg_icon . '.gif" border="0" alt="'. $msg_alt . '" title="' . $msg_title . '" height="12" width="18" >';
329 $td_str .= '</small></b>';
338 // plain text message markers
342 $td_str = "<b><small>";
343 if (isset($msg['FLAG_ANSWERED']) && $msg['FLAG_ANSWERED'] == true) {
347 if ($msg['TYPE0'] == 'multipart') {
351 if ($default_use_priority) {
352 if ( ($msg['PRIORITY'] == 1) ||
($msg['PRIORITY'] == 2) ) {
353 $td_str .= "<font color=\"$color[1]\">!</font>";
356 if ($msg['PRIORITY'] == 5) {
357 $td_str .= "<font color=\"$color[8]\">?</font>";
361 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'] == true) {
362 $td_str .= "<font color=\"$color[1]\">D</font>";
368 $td_str .= '</small></b>';
378 $bold . $fontstr . show_readable_size($msg['SIZE']) .
379 $fontstr_end . $bold_end,
388 echo '</tr>' . "\n" . '<tr><td COLSPAN="' . $col . '" BGCOLOR="' .
389 $color[0] . '" HEIGHT="1"></td></tr>' . "\n";
395 function getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id) {
397 $id = array_slice($id, ($start_msg-1), $show_num);
398 $end = $start_msg +
$show_num - 1;
399 if ($num_msgs < $show_num) {
400 $end_loop = $num_msgs;
401 } else if ($end > $num_msgs) {
402 $end_loop = $num_msgs - $start_msg +
1;
404 $end_loop = $show_num;
406 return fillMessageArray($imapConnection,$id,$end_loop,$show_num);
412 function getThreadMessages($imapConnection, $start_msg, $show_num, $num_msgs) {
413 $id = get_thread_sort($imapConnection);
414 return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
417 function getServerSortMessages($imapConnection, $start_msg, $show_num,
418 $num_msgs, $server_sort_order, $mbxresponse) {
419 $id = sqimap_get_sort_order($imapConnection, $server_sort_order,$mbxresponse);
420 return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
423 function getSelfSortMessages($imapConnection, $start_msg, $show_num,
424 $num_msgs, $sort, $mbxresponse) {
426 if ($num_msgs >= 1) {
427 $id = sqimap_get_php_sort_order ($imapConnection, $mbxresponse);
431 /* set shownum to 999999 to fool sqimap_get_small_header_list
432 and rebuild the msgs_str to 1:* */
435 /* if it's not sorted */
436 if ($start_msg +
($show_num - 1) < $num_msgs) {
437 $end_msg = $start_msg +
($show_num - 1);
439 $end_msg = $num_msgs;
441 if ($end_msg < $start_msg) {
442 $start_msg = $start_msg - $show_num;
443 if ($start_msg < 1) {
447 $id = array_slice(array_reverse($id), ($start_msg-1), $show_num);
448 $end = $start_msg +
$show_num - 1;
449 if ($num_msgs < $show_num) {
450 $end_loop = $num_msgs;
451 } else if ($end > $num_msgs) {
452 $end_loop = $num_msgs - $start_msg +
1;
454 $end_loop = $show_num;
457 $msgs = fillMessageArray($imapConnection,$id,$end_loop, $show_num);
465 * This function loops through a group of messages in the mailbox
466 * and shows them to the user.
468 function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
469 $start_msg, $sort, $color, $show_num,
470 $use_cache, $mode='') {
471 global $msgs, $msort, $auto_expunge, $thread_sort_messages,
472 $allow_server_sort, $server_sort_order;
475 * For some reason, on PHP 4.3+, this being unset, and set in the session causes havoc
476 * so setting it to an empty array beforehand seems to clean up the issue, and stopping the
477 * "Your script possibly relies on a session side-effect which existed until PHP 4.2.3" error
480 if (!isset($msort)) {
488 //$start = microtime();
489 /* If autoexpunge is turned on, then do it now. */
490 $mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox);
492 /* If autoexpunge is turned on, then do it now. */
493 if ($auto_expunge == true) {
494 $exp_cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, false, '');
495 $mbxresponse['EXISTS'] = $mbxresponse['EXISTS'] - $exp_cnt;
496 $num_msgs = $mbxresponse['EXISTS'];
499 if ($mbxresponse['EXISTS'] > 0) {
500 /* if $start_msg is lower than $num_msgs, we probably deleted all messages
501 * in the last page. We need to re-adjust the start_msg
504 if($start_msg > $num_msgs) {
505 $start_msg -= $show_num;
511 /* This code and the next if() block check for
512 * server-side sorting methods. The $id array is
513 * formatted and $sort is set to 6 to disable
514 * SM internal sorting
517 if ($thread_sort_messages == 1) {
519 } elseif ($allow_server_sort == 1) {
520 $mode = 'serversort';
526 sqgetGlobalVar('msgs', $msgs, SQ_SESSION
);
527 sqgetGlobalVar('msort', $msort, SQ_SESSION
);
529 sqsession_unregister('msort');
530 sqsession_unregister('msgs'); }
533 $msgs = getThreadMessages($imapConnection, $start_msg, $show_num, $num_msgs);
534 if ($msgs === false) {
535 echo '<b><small><center><font color=red>' .
536 _("Thread sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
537 '</center></small></b>';
538 $thread_sort_messages = 0;
539 $msort = $msgs = array();
546 $msgs = getServerSortMessages($imapConnection, $start_msg, $show_num,
547 $num_msgs, $sort, $mbxresponse);
548 if ($msgs === false) {
549 echo '<b><small><center><font color=red>' .
550 _( "Server-side sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
551 '</center></small></b>';
552 $sort = $server_sort_order;
553 $allow_server_sort = FALSE;
554 $msort = $msgs = array();
563 $msgs = getSelfSortMessages($imapConnection, $start_msg, $show_num,
564 $num_msgs, $sort, $mbxresponse);
565 $msort = calc_msort($msgs, $sort);
569 sqsession_register($msort, 'msort');
570 sqsession_register($msgs, 'msgs');
572 } /* if exists > 0 */
574 $res = getEndMessage($start_msg, $show_num, $num_msgs);
575 $start_msg = $res[0];
578 $paginator_str = get_paginator_str($mailbox, $start_msg, $end_msg,
579 $num_msgs, $show_num, $sort);
581 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
583 do_hook('mailbox_index_before');
585 <table border
="0" width
="100%" cellpadding
="0" cellspacing
="0">
588 <?php
mail_message_listing_beginning($imapConnection, $mailbox, $sort,
589 $msg_cnt_str, $paginator_str, $start_msg); ?
>
592 <tr
><td HEIGHT
="5" BGCOLOR
="<?php echo $color[4]; ?>"></td
></tr
>
595 <table width
="100%" cellpadding
="1" cellspacing
="0" align
="center" border
="0" bgcolor
="<?php echo $color[9]; ?>">
598 <table width
="100%" cellpadding
="1" cellspacing
="0" align
="center" border
="0" bgcolor
="<?php echo $color[5]; ?>">
602 printHeader($mailbox, $srt, $color, !$thread_sort_messages, $start_msg);
603 displayMessageArray($imapConnection, $num_msgs, $start_msg,
604 $msort, $mailbox, $sort, $color, $show_num,0,0);
613 mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color);
619 //$t = elapsed($start);
620 //echo("elapsed time = $t seconds\n");
623 function calc_msort($msgs, $sort) {
634 if (($sort == 0) ||
($sort == 1)) {
635 foreach ($msgs as $item) {
636 $msort[] = $item['TIME_STAMP'];
638 } elseif (($sort == 2) ||
($sort == 3)) {
639 foreach ($msgs as $item) {
640 $msort[] = $item['FROM-SORT'];
642 } elseif (($sort == 4) ||
($sort == 5)) {
643 foreach ($msgs as $item) {
644 $msort[] = $item['SUBJECT-SORT'];
659 function fillMessageArray($imapConnection, $id, $count, $show_num=false) {
660 return sqimap_get_small_header_list($imapConnection, $id, $show_num);
664 /* Generic function to convert the msgs array into an HTML table. */
665 function displayMessageArray($imapConnection, $num_msgs, $start_msg,
666 $msort, $mailbox, $sort, $color,
667 $show_num, $where=0, $what=0) {
668 global $imapServerAddress, $use_mailbox_cache, $index_order,
669 $indent_array, $thread_sort_messages, $allow_server_sort,
670 $server_sort_order, $PHP_SELF;
672 $res = getEndMessage($start_msg, $show_num, $num_msgs);
673 $start_msg = $res[0];
676 $urlMailbox = urlencode($mailbox);
678 /* get indent level for subject display */
679 if ($thread_sort_messages == 1 && $num_msgs) {
680 $indent_array = get_parent_level($imapConnection);
683 $real_startMessage = $start_msg;
685 if ($end_msg - $start_msg < $show_num - 1) {
686 $end_msg = $end_msg - $start_msg +
1;
688 } else if ($start_msg > $show_num) {
689 $end_msg = $show_num;
693 $endVar = $end_msg +
1;
696 * Loop through and display the info for each message.
697 * ($t is used for the checkbox number)
701 /* messages display */
704 /* if there's no messages in this folder */
707 "<BR><b>" . _("THIS FOLDER IS EMPTY") . "</b><BR> ",
710 'COLSPAN="' . count($index_order) . '"'
713 } elseif ($start_msg == $end_msg) {
714 /* if there's only one message in the box, handle it differently. */
726 } while (isset ($key) && ($k < $i));
727 printMessageInfo($imapConnection, $t, true, $key, $mailbox,
728 $real_startMessage, $where, $what);
737 } while (isset ($key) && ($k < $i));
740 if (!$i ||
$i == $endVar-1) $not_last = false;
741 printMessageInfo($imapConnection, $t, $not_last, $key, $mailbox,
742 $real_startMessage, $where, $what);
747 } while ($i && $i < $endVar);
752 * Displays the standard message list header. To finish the table,
753 * you need to do a "</table></table>";
755 * $moveURL is the URL to submit the delete/move form to
756 * $mailbox is the current mailbox
757 * $sort is the current sorting method (-1 for no sorting available [searches])
758 * $Message is a message that is centered on top of the list
759 * $More is a second line that is left aligned
762 function mail_message_listing_beginning ($imapConnection,
763 $mailbox = '', $sort = -1,
765 $paginator = ' ',
767 global $color, $auto_expunge, $base_uri,
768 $allow_server_sort, $server_sort_order,
769 $PHP_SELF, $allow_thread_sort, $thread_sort_messages;
771 $php_self = $PHP_SELF;
772 /* fix for incorrect $PHP_SELF */
773 if (strpos($php_self, 'move_messages.php')) {
774 $php_self = str_replace('move_messages.php', 'right_main.php', $php_self);
776 $urlMailbox = urlencode($mailbox);
778 if (preg_match('/^(.+)\?.+$/',$php_self,$regs)) {
779 $source_url = $regs[1];
781 $source_url = $php_self;
788 if (!strpos($php_self,'?')) {
789 $location = $php_self.'?mailbox=INBOX&startMessage=1';
791 $location = $php_self;
794 $moveFields = '<input type="hidden" name="msg" value="'.htmlspecialchars($msg).'">' .
795 '<input type="hidden" name="mailbox" value="'.htmlspecialchars($mailbox).'">' .
796 '<input type="hidden" name="startMessage" value="'.htmlspecialchars($start_msg).'">'.
797 '<input type="hidden" name="location" value="'.$location.'">';
800 * This is the beginning of the message list table.
801 * It wraps around all messages
803 $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $mailbox);
804 $form_name = "FormMsgs" . $safe_name;
805 echo '<form name="' . $form_name . '" method="post" action="move_messages.php">' ."\n"
808 <table width
="100%" cellpadding
="1" cellspacing
="0" style
="border: 1px solid <?php echo $color[0]; ?>">
811 <table bgcolor
="<?php echo $color[4]; ?>" border
="0" width
="100%" cellpadding
="1" cellspacing
="0">
813 <td align
="left"><small
><?php
echo $paginator; ?
></small
></td
>
814 <td align
="right"><small
><?php
echo $msg_cnt_str; ?
></small
></td
>
819 <tr width
="100%" cellpadding
="1" cellspacing
="0" border
="0" bgcolor
="<?php echo $color[0]; ?>">
821 <table border
="0" width
="100%" cellpadding
="1" cellspacing
="0">
825 echo getButton('SUBMIT', 'markRead',_("Read"));
827 echo getButton('SUBMIT', 'markUnread',_("Unread"));
829 echo getButton('SUBMIT', 'attache',_("Forward"));
831 echo getButton('SUBMIT', 'delete',_("Delete"));
832 echo '<input type="checkbox" name="bypass_trash">' . _("Bypass Trash");
834 if (!$auto_expunge) {
835 echo getButton('SUBMIT', 'expungeButton',_("Expunge")) .' ' . _("mailbox") . "\n";
838 do_hook('mailbox_display_buttons');
843 /* draws thread sorting links */
844 if ($allow_thread_sort == TRUE) {
845 if ($thread_sort_messages == 1 ) {
847 $thread_name = _("Unthread View");
848 } elseif ($thread_sort_messages == 0) {
850 $thread_name = _("Thread View");
852 echo ' <small>[<a href="' . $source_url . '?sort='
853 . $sort . '&start_messages=1&set_thread=' . $set_thread
854 . '&mailbox=' . urlencode($mailbox) . '">' . $thread_name
857 getMbxList($imapConnection);
858 echo getButton('SUBMIT', 'moveButton',_("Move")) . "\n";
868 do_hook('mailbox_form_before');
870 /* if using server sort we highjack the
871 * the $sort var and use $server_sort_order
872 * instead. but here we reset sort for a bit
875 if ($allow_server_sort == TRUE) {
876 $sort = $server_sort_order;
880 function mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color) {
882 /* space between list and footer */
884 <tr
><td HEIGHT
="5" BGCOLOR
="<?php echo $color[4]; ?>" COLSPAN
="1"></td
></tr
>
887 <table width
="100%" cellpadding
="1" cellspacing
="0" style
="border: 1px solid <?php echo $color[0]; ?>">
890 <table bgcolor
="<?php echo $color[4]; ?>" border
="0" width
="100%" cellpadding
="1" cellspacing
="0">
892 <td align
="left"><small
><?php
echo $paginator_str; ?
></small
></td
>
893 <td align
="right"><small
><?php
echo $msg_cnt_str; ?
></small
></td
>
903 /* End of message-list table */
905 do_hook('mailbox_index_after');
909 function printHeader($mailbox, $sort, $color, $showsort=true, $start_msg=1) {
911 echo html_tag( 'tr' ,'' , 'center', $color[5] );
913 /* calculate the width of the subject column based on the
914 * widths of the other columns */
915 $widths = array(1=>1,2=>25,3=>5,4=>0,5=>1,6=>5);
917 foreach($index_order as $item) {
918 $subjectwidth -= $widths[$item];
921 foreach ($index_order as $item) {
923 case 1: /* checkbox */
924 echo html_tag( 'td',get_selectall_link($start_msg, $sort) , '', '', 'width="1%"' );
927 echo html_tag( 'td','' , '', '', 'width="1%"' );
930 if (handleAsSent($mailbox)) {
931 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
932 . '<b>' . _("To") . '</b>';
934 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
935 . '<b>' . _("From") . '</b>';
938 ShowSortButton($sort, $mailbox, 2, 3);
943 echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
944 . '<b>' . _("Date") . '</b>';
946 ShowSortButton($sort, $mailbox, 0, 1);
950 case 4: /* subject */
951 echo html_tag( 'td' ,'' , 'left', '', 'width="'.$subjectwidth.'%"' )
952 . '<b>' . _("Subject") . '</b>';
954 ShowSortButton($sort, $mailbox, 4, 5);
959 echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%" nowrap' );
968 * This function shows the sort button. Isn't this a good comment?
970 function ShowSortButton($sort, $mailbox, $Down, $Up ) {
973 /* Figure out which image we want to use. */
974 if ($sort != $Up && $sort != $Down) {
975 $img = 'sort_none.png';
977 } elseif ($sort == $Up) {
978 $img = 'up_pointer.png';
981 $img = 'down_pointer.png';
985 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
986 $source_url = $regs[1];
988 $source_url = $PHP_SELF;
991 /* Now that we have everything figured out, show the actual button. */
992 echo ' <a href="' . $source_url .'?newsort=' . $which
993 . '&startMessage=1&mailbox=' . urlencode($mailbox)
994 . '"><img src="../images/' . $img
995 . '" border="0" width="12" height="10" alt="sort" title="'
996 . _("Click here to change the sorting of the message list") .'"></a>';
999 function get_selectall_link($start_msg, $sort) {
1000 global $checkall, $what, $where, $mailbox, $javascript_on;
1001 global $PHP_SELF, $PG_SHOWNUM;
1004 if ($javascript_on) {
1005 $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $mailbox);
1006 $func_name = "CheckAll" . $safe_name;
1007 $form_name = "FormMsgs" . $safe_name;
1008 $result = '<script language="JavaScript" type="text/javascript">'
1010 . "function " . $func_name . "() {\n"
1011 . " for (var i = 0; i < document." . $form_name . ".elements.length; i++) {\n"
1012 . " if(document." . $form_name . ".elements[i].type == 'checkbox' && "
1013 . "document." . $form_name . ".elements[i].name != 'bypass_trash'){\n"
1014 . " document." . $form_name . ".elements[i].checked = "
1015 . " !(document." . $form_name . ".elements[i].checked);\n"
1021 . '<input type="checkbox" name="toggleAll" title="'._("Toggle All").'" onclick="'.$func_name.'();">';
1022 // . <a href="javascript:void(0)" onClick="' . $func_name . '();">' . _("Toggle All")
1025 if (strpos($PHP_SELF, "?")) {
1026 $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($mailbox)
1027 . "&startMessage=$start_msg&sort=$sort&checkall=";
1029 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
1030 . "&startMessage=$start_msg&sort=$sort&checkall=";
1032 if (isset($checkall) && $checkall == '1') {
1038 if (isset($where) && isset($what)) {
1039 $result .= '&where=' . urlencode($where)
1040 . '&what=' . urlencode($what);
1044 if (isset($checkall) && ($checkall == '1')) {
1045 $result .= _("Unselect All");
1047 $result .= _("Select All");
1049 $result .= "</A>\n";
1052 /* Return our final result. */
1057 * This function computes the "Viewing Messages..." string.
1059 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
1060 /* Compute the $msg_cnt_str. */
1062 if ($start_msg < $end_msg) {
1063 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"),
1064 $start_msg, $end_msg, $num_msgs);
1065 } else if ($start_msg == $end_msg) {
1066 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
1070 /* Return our result string. */
1075 * Generate a paginator link.
1077 function get_paginator_link($box, $start_msg, $use, $text) {
1080 $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
1081 . "&startMessage=$start_msg&mailbox=$box\" "
1085 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
1086 $source_url = $regs[1];
1088 $source_url = $PHP_SELF;
1091 $result = '<A HREF="'. $source_url . "?use_mailbox_cache=$use"
1092 . "&startMessage=$start_msg&mailbox=$box\" "
1099 * This function computes the paginator string.
1101 function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
1103 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
1105 /* Initialize paginator string chunks. */
1111 $box = urlencode($box);
1113 /* Create simple strings that will be creating the paginator. */
1114 $spc = ' '; /* This will be used as a space. */
1115 $sep = '|'; /* This will be used as a seperator. */
1117 /* Get some paginator preference values. */
1118 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON
);
1119 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
);
1121 /* Make sure that our start message number is not too big. */
1122 $start_msg = min($start_msg, $num_msgs);
1124 /* Decide whether or not we will use the mailbox cache. */
1125 /* Not sure why $use_mailbox_cache is even passed in. */
1132 /* Compute the starting message of the previous and next page group. */
1133 $next_grp = $start_msg +
$show_num;
1134 $prev_grp = $start_msg - $show_num;
1136 /* Compute the basic previous and next strings. */
1137 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
1138 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1139 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1140 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
1141 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1142 $nxt_str = _("Next");
1143 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
1144 $prv_str = _("Previous");
1145 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1148 /* Page selector block. Following code computes page links. */
1149 if ($pg_sel && ($num_msgs > $show_num)) {
1150 /* Most importantly, what is the current page!!! */
1151 $cur_pg = intval($start_msg / $show_num) +
1;
1153 /* Compute total # of pages and # of paginator page links. */
1154 $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
1155 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
1157 /* Compute the size of the four quarters of the page links. */
1159 /* If we can, just show all the pages. */
1160 if (($tot_pgs - 1) <= $pg_max) {
1161 $q1_pgs = $cur_pg - 1;
1162 $q2_pgs = $q3_pgs = 0;
1163 $q4_pgs = $tot_pgs - $cur_pg;
1165 /* Otherwise, compute some magic to choose the four quarters. */
1168 * Compute the magic base values. Added together,
1169 * these values will always equal to the $pag_pgs.
1170 * NOTE: These are DEFAULT values and do not take
1171 * the current page into account. That is below.
1173 $q1_pgs = floor($vis_pgs/4);
1174 $q2_pgs = round($vis_pgs/4, 0);
1175 $q3_pgs = ceil($vis_pgs/4);
1176 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
1178 /* Adjust if the first quarter contains the current page. */
1179 if (($cur_pg - $q1_pgs) < 1) {
1180 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) +
$q2_pgs;
1181 $q1_pgs = $cur_pg - 1;
1183 $q3_pgs +
= ceil($extra_pgs / 2);
1184 $q4_pgs +
= floor($extra_pgs / 2);
1186 /* Adjust if the first and second quarters intersect. */
1187 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
1188 $extra_pgs = $q2_pgs;
1189 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 3/4);
1190 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 3/4);
1191 $q3_pgs +
= ceil($extra_pgs / 2);
1192 $q4_pgs +
= floor($extra_pgs / 2);
1194 /* Adjust if the fourth quarter contains the current page. */
1195 } else if (($cur_pg +
$q4_pgs) >= $tot_pgs) {
1196 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) +
$q3_pgs;
1198 $q4_pgs = $tot_pgs - $cur_pg;
1199 $q1_pgs +
= floor($extra_pgs / 2);
1200 $q2_pgs +
= ceil($extra_pgs / 2);
1202 /* Adjust if the third and fourth quarter intersect. */
1203 } else if (($cur_pg +
$q3_pgs +
1) >= ($tot_pgs - $q4_pgs +
1)) {
1204 $extra_pgs = $q3_pgs;
1205 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 3/4);
1206 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 3/4);
1207 $q1_pgs +
= floor($extra_pgs / 2);
1208 $q2_pgs +
= ceil($extra_pgs / 2);
1213 * I am leaving this debug code here, commented out, because
1214 * it is a really nice way to see what the above code is doing.
1215 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
1216 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
1219 /* Print out the page links from the compute page quarters. */
1221 /* Start with the first quarter. */
1222 if (($q1_pgs == 0) && ($cur_pg > 1)) {
1223 $pg_str .= "...$spc";
1225 for ($pg = 1; $pg <= $q1_pgs; ++
$pg) {
1226 $start = (($pg-1) * $show_num) +
1;
1227 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1229 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
1230 $pg_str .= "...$spc";
1234 /* Continue with the second quarter. */
1235 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++
$pg) {
1236 $start = (($pg-1) * $show_num) +
1;
1237 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1240 /* Now print the current page. */
1241 $pg_str .= $cur_pg . $spc;
1243 /* Next comes the third quarter. */
1244 for ($pg = $cur_pg +
1; $pg <= $cur_pg +
$q3_pgs; ++
$pg) {
1245 $start = (($pg-1) * $show_num) +
1;
1246 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1249 /* And last, print the forth quarter page links. */
1250 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
1251 $pg_str .= "...$spc";
1253 if (($tot_pgs - $q4_pgs) > ($cur_pg +
$q3_pgs)) {
1254 $pg_str .= "...$spc";
1256 for ($pg = $tot_pgs - $q4_pgs +
1; $pg <= $tot_pgs; ++
$pg) {
1257 $start = (($pg-1) * $show_num) +
1;
1258 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1261 } else if ($PG_SHOWNUM == 999999) {
1262 $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
1263 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1264 . ">" ._("Paginate") . '</A>';
1267 /* Put all the pieces of the paginator string together. */
1269 * Hairy code... But let's leave it like it is since I am not certain
1270 * a different approach would be any easier to read. ;)
1273 if ( $prv_str != '' ||
$nxt_str != '' )
1276 $result .= ($prv_str != '' ?
$prv_str . $spc . $sep . $spc : '');
1277 $result .= ($nxt_str != '' ?
$nxt_str : '');
1278 $result .= ']' . $spc ;
1280 /* Compute the 'show all' string. */
1281 $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
1282 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1283 . ">" . _("Show All") . '</A>';
1286 $result .= ($pg_str != '' ?
$spc . '['.$spc.$pg_str.']' . $spc : '');
1287 $result .= ($all_str != '' ?
$spc . '['.$all_str.']' . $spc . $spc : '');
1289 /* If the resulting string is blank, return a non-breaking space. */
1290 if ($result == '') {
1294 /* Return our final magical paginator string. */
1298 function truncateWithEntities($subject, $trim_at)
1300 $ent_strlen = strlen($subject);
1301 if (($trim_at <= 0) ||
($ent_strlen <= $trim_at))
1304 global $languages, $squirrelmail_language;
1307 * see if this is entities-encoded string
1308 * If so, Iterate through the whole string, find out
1309 * the real number of characters, and if more
1310 * than $trim_at, substr with an updated trim value.
1312 $trim_val = $trim_at;
1315 while ( $ent_loc < $trim_val && (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1316 (($ent_loc_end = strpos($subject, ';', $ent_loc+
3)) !== false) ) {
1317 $trim_val +
= ($ent_loc_end-$ent_loc);
1318 $ent_offset = $ent_loc_end+
1;
1320 if (($trim_val > $trim_at) && ($ent_strlen > $trim_val) && (strpos($subject,';',$trim_val) < ($trim_val +
6))) {
1321 $i = strpos($subject,';',$trim_val);
1323 $trim_val = strpos($subject,';',$trim_val);
1326 // only print '...' when we're actually dropping part of the subject
1327 if ($ent_strlen <= $trim_val)
1330 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
1331 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
1332 return $languages[$squirrelmail_language]['XTRA_CODE']('strimwidth', $subject, $trim_val);
1335 return substr_replace($subject, '...', $trim_val);
1338 function processSubject($subject, $threadlevel = 0) {
1339 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1340 if ($subject == '') {
1341 return _("(no subject)");
1344 global $truncate_subject; /* number of characters for Subject field (<= 0 for unchanged) */
1345 $trim_at = $truncate_subject;
1347 /* if this is threaded, subtract two chars per indentlevel */
1348 if (($threadlevel > 0) && ($threadlevel <= 10))
1349 $trim_at -= (2*$threadlevel);
1351 return truncateWithEntities($subject, $trim_at);
1354 function getMbxList($imapConnection, $boxes = 0) {
1355 global $lastTargetMailbox;
1356 echo ' <small> <tt><select name="targetMailbox">';
1357 echo sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)), 0, $boxes);
1358 echo ' </SELECT></TT> ';
1361 function getButton($type, $name, $value) {
1362 return '<INPUT TYPE="'.$type.'" NAME="'.$name.'" VALUE="'.$value . '" style="padding: 0px; margin: 0px">';
1365 function getSmallStringCell($string, $align) {
1366 return html_tag('td',
1367 '<small>' . $string . ': </small>',
1373 function getEndMessage($start_msg, $show_num, $num_msgs) {
1374 if ($start_msg +
($show_num - 1) < $num_msgs){
1375 $end_msg = $start_msg +
($show_num - 1);
1377 $end_msg = $num_msgs;
1380 if ($end_msg < $start_msg) {
1381 $start_msg = $start_msg - $show_num;
1382 if ($start_msg < 1) {
1386 return (array($start_msg,$end_msg));
1389 // This should go in imap_mailbox.php
1390 function handleAsSent($mailbox) {
1391 global $handleAsSent_result;
1393 /* First check if this is the sent or draft folder. */
1394 $handleAsSent_result = isSentMailbox($mailbox) ||
isDraftMailbox($mailbox);
1396 /* Then check the result of the handleAsSent hook. */
1397 do_hook('check_handleAsSent_result', $mailbox);
1399 /* And return the result. */
1400 return $handleAsSent_result;