b978c33bc43da216897a9f12b99d798840a870e3
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This contains functions that display mailbox information, such as the
10 * table row that has sender, date, subject, etc...
15 require_once('../functions/strings.php');
16 require_once('../functions/html.php');
17 require_once('../class/html.class');
18 require_once('../functions/imap_utf7_decode_local.php');
20 /* Default value for page_selector_max. */
21 define('PG_SEL_MAX', 10);
23 function printMessageInfo($imapConnection, $t, $i, $key, $mailbox,
26 $color, $msgs, $msort,
27 $default_use_priority,
28 $message_highlight_list,
30 $indent_array, /* indent subject by */
31 $pos, /* Search postion (if any) */
32 $thread_sort_messages, /* thread sorting on/off */
33 $server_sort_order, /* sort value when using server-sorting */
35 $allow_server_sort; /* enable/disable server-side sorting */
36 $color_string = $color[4];
38 if ($GLOBALS['alt_index_colors']) {
39 if (!isset($row_count)) {
44 if (!isset($color[12])) {
45 $color[12] = '#EAEAEA';
47 $color_string = $color[12];
52 if( $mailbox == 'None' ) {
53 $boxes = sqimap_mailbox_list($imapConnection);
54 $mailbox = $boxes[0]['unformatted'];
57 $urlMailbox = urlencode($mailbox);
59 if (handleAsSent($mailbox)) {
60 $msg['FROM'] = $msg['TO'];
62 * This is done in case you're looking into Sent folders,
63 * because you can have multiple receivers.
65 $senderNames = explode(',', $msg['FROM']);
67 if (sizeof($senderNames)){
68 foreach ($senderNames as $senderNames_part) {
69 if ($senderName != '') {
72 $senderName .= sqimap_find_displayable_name($senderNames_part);
76 $senderName = sqimap_find_displayable_name($msg['FROM']);
79 $subject = processSubject($msg['SUBJECT']);
81 echo html_tag( 'tr' ) . "\n";
83 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
84 $flag = "<font color=\"$color[2]\">";
85 $flag_end = '</font>';
90 if (!isset($msg['FLAG_SEEN']) ||
($msg['FLAG_SEEN'] == false)) {
97 if (handleAsSent($mailbox)) {
104 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
105 $fontstr = "<font color=\"$color[9]\">";
106 $fontstr_end = '</font>';
113 * AAAAH! Make my eyes stop bleeding!
116 if (sizeof($message_highlight_list)){
117 foreach ($message_highlight_list as $message_highlight_list_part) {
118 if (trim($message_highlight_list_part['value']) != '') {
119 if ($message_highlight_list_part['match_type'] == 'to_cc') {
120 if (strstr('^^' . strtolower($msg['TO']),
121 strtolower($message_highlight_list_part['value']))
122 ||
strstr('^^'.strtolower($msg['CC']),
123 strtolower($message_highlight_list_part['value']))) {
124 $hlt_color = $message_highlight_list_part['color'];
128 if (strstr('^^' . strtolower($msg[strtoupper($message_highlight_list_part['match_type'])]),
129 strtolower($message_highlight_list_part['value']))) {
130 $hlt_color = $message_highlight_list_part['color'];
137 if (!isset($hlt_color)) {
138 $hlt_color = $color_string;
141 $checked = ($checkall == 1) ?
' checked' : '';
148 if (sizeof($index_order)){
149 foreach ($index_order as $index_order_part) {
150 switch ($index_order_part) {
151 case 1: /* checkbox */
153 "<input type=checkbox name=\"msg[$t]\" value=\"".$msg['ID']."\"$checked>",
159 $italic . $bold . $flag . $fontstr . $senderName .
160 $fontstr_end . $flag_end . $bold_end . $italic_end,
166 $bold . $flag . $fontstr . $msg['DATE_STRING'] .
167 $fontstr_end . $flag_end . $bold_end,
172 case 4: /* subject */
174 if ($thread_sort_messages == 1) {
175 if (isset($indent_array[$msg["ID"]])) {
176 $td_str .= str_repeat(" ",$indent_array[$msg['ID']]);
179 $td_str .= '<a href="read_body.php?mailbox='.$urlMailbox
180 .'&passed_id='. $msg["ID"]
181 . '&startMessage='.$start_msg
182 .'&show_more=0"';
183 do_hook("subject_link");
184 if ($subject != $msg['SUBJECT']) {
185 $title = get_html_translation_table(HTML_SPECIALCHARS
);
186 $title = array_flip($title);
187 $title = strtr($msg['SUBJECT'], $title);
188 $title = str_replace('"', "''", $title);
189 $td_str .= " title=\"$title\"";
191 $td_str .= ">$flag$subject$flag_end</a>$bold_end";
192 echo html_tag( 'td', $td_str, 'left', $hlt_color );
196 $td_str = "<b><small>";
198 if (isset($msg['FLAG_ANSWERED']) && $msg['FLAG_ANSWERED'] == true) {
202 if ($msg['TYPE0'] == 'multipart') {
206 if ($default_use_priority) {
207 if ( ($msg['PRIORITY'] == 1) ||
($msg['PRIORITY'] == 2) ) {
208 $td_str .= "<font color=\"$color[1]\">!</font>";
211 if ($msg['PRIORITY'] == 5) {
212 $td_str .= "<font color=\"$color[8]\">?</font>";
216 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'] == true) {
217 $td_str .= "<font color=\"$color[1]\">D</font>";
223 $td_str .= '</small></b>';
233 $bold . $fontstr . show_readable_size($msg['SIZE']) .
234 $fontstr_end . $bold_end,
244 function getThreadMessages($imapConnection, $start_msg, $show_num, $num_msgs) {
245 $id = get_thread_sort($imapConnection);
247 if ($start_msg +
($show_num - 1) < $num_msgs) {
248 $end_msg = $start_msg +
($show_num-1);
250 $end_msg = $num_msgs;
252 $id = array_slice($id, ($start_msg-1), ($end_msg));
254 $end = $start_msg +
$show_num - 1;
255 if ($num_msgs < $show_num) {
256 $end_loop = $num_msgs;
257 } else if ($end > $num_msgs) {
258 $end_loop = $num_msgs - $start_msg +
1;
260 $end_loop = $show_num;
262 return fillMessageArray($imapConnection,$id,$end_loop);
268 function getServerSortMessages($imapConnection, $start_msg, $show_num,
269 $num_msgs, $server_sort_order, $mbxresponse) {
270 $id = sqimap_get_sort_order($imapConnection, $server_sort_order,$mbxresponse);
272 if ($start_msg +
($show_num - 1) < $num_msgs) {
273 $end_msg = $start_msg +
($show_num-1);
275 $end_msg = $num_msgs;
277 $id = array_slice($id, ($start_msg-1), ($end_msg));
279 $end = $start_msg +
$show_num - 1;
280 if ($num_msgs < $show_num) {
281 $end_loop = $num_msgs;
282 } else if ($end > $num_msgs) {
283 $end_loop = $num_msgs - $start_msg +
1;
285 $end_loop = $show_num;
287 return fillMessageArray($imapConnection,$id,$end_loop);
293 function getSelfSortMessages($imapConnection, $start_msg, $show_num,
294 $num_msgs, $sort, $mbxresponse) {
296 if ($num_msgs >= 1) {
297 $id = sqimap_get_php_sort_order ($imapConnection, $mbxresponse);
302 /* if it's not sorted */
303 if ($start_msg +
($show_num - 1) < $num_msgs) {
304 $end_msg = $start_msg +
($show_num - 1);
306 $end_msg = $num_msgs;
308 if ($end_msg < $start_msg) {
309 $start_msg = $start_msg - $show_num;
310 if ($start_msg < 1) {
314 $id = array_slice(array_reverse($id), ($start_msg-1), ($end_msg));
315 $end = $start_msg +
$show_num - 1;
316 if ($num_msgs < $show_num) {
317 $end_loop = $num_msgs;
318 } else if ($end > $num_msgs) {
319 $end_loop = $num_msgs - $start_msg +
1;
321 $end_loop = $show_num;
324 $msgs = fillMessageArray($imapConnection,$id,$end_loop);
332 * This function loops through a group of messages in the mailbox
333 * and shows them to the user.
335 function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
336 $start_msg, $sort, $color, $show_num,
337 $use_cache, $mode='') {
338 global $msgs, $msort, $auto_expunge, $thread_sort_messages,
339 $allow_server_sort, $server_sort_order;
341 /* If autoexpunge is turned on, then do it now. */
342 $mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox);
344 /* If autoexpunge is turned on, then do it now. */
345 if ($auto_expunge == true) {
346 $exp_cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, false, '');
347 $mbxresponse['EXISTS'] = $mbxresponse['EXISTS'] - $exp_cnt;
350 if ($mbxresponse['EXISTS']>0) {
351 /* if $start_msg is lower than $num_msgs, we probably deleted all messages
352 * in the last page. We need to re-adjust the start_msg
355 if($start_msg > $num_msgs) {
356 $start_msg -= $show_num;
362 /* This code and the next if() block check for
363 * server-side sorting methods. The $id array is
364 * formatted and $sort is set to 6 to disable
365 * SM internal sorting
368 if ($thread_sort_messages == 1) {
370 } elseif ($allow_server_sort == 1) {
371 $mode = 'serversort';
378 session_unregister('msort');
379 session_unregister('msgs');
380 $msgs = getThreadMessages($imapConnection, $start_msg, $show_num,
382 if ($msgs === false) {
383 echo '<b><small><center><font color=red>' .
384 _("Thread sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
385 '</center></small></b>';
386 $thread_sort_messages = 0;
387 $msort = $msgs = array();
388 session_register('msort');
389 session_register('msgs');
393 session_register('msort');
394 session_register('msgs');
399 $msgs = getServerSortMessages($imapConnection, $start_msg, $show_num,
400 $num_msgs, $sort, $mbxresponse);
401 if ($msgs === false) {
402 echo '<b><small><center><font color=red>' .
403 _( "Server-side sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
404 '</center></small></b>';
405 $sort = $server_sort_order;
406 $allow_server_sort = FALSE;
407 $msort = $msgs = array();
408 session_register('msort');
409 session_register('msgs');
414 session_register('msort');
415 session_register('msgs');
420 session_unregister('msgs');
421 session_unregister('msort');
422 $msgs= getSelfSortMessages($imapConnection, $start_msg, $show_num,
423 $num_msgs, $sort, $mbxresponse);
424 $msort = calc_msort($msgs, $sort);
425 session_register('msort');
426 session_register('msgs');
430 } /* if exists > 0 */
432 $end_msg = getEndMessage(&$start_msg, $show_num, $num_msgs);
434 $paginator_str = get_paginator_str($mailbox, $start_msg, $end_msg,
435 $num_msgs, $show_num, $sort);
437 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
439 do_hook('mailbox_index_before');
441 mail_message_listing_beginning($imapConnection, $mailbox, $sort,
442 $msg_cnt_str, $paginator_str, $start_msg);
445 printHeader($mailbox, $srt, $color, !$thread_sort_messages);
447 displayMessageArray($imapConnection, $num_msgs, $start_msg,
448 $msort, $mailbox, $sort, $color, $show_num,0,0);
450 mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color);
453 * TODO: Switch to using $_SESSION[] whenever we ditch the 4.0.x series.
457 function calc_msort($msgs, $sort) {
467 if (($sort == 0) ||
($sort == 1)) {
468 $msort = array_cleave ($msgs, 'TIME_STAMP');
469 } elseif (($sort == 2) ||
($sort == 3)) {
470 $msort = array_cleave ($msgs, 'FROM-SORT');
471 } elseif (($sort == 4) ||
($sort == 5)) {
472 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
486 function fillMessageArray($imapConnection,$id,$count) {
487 $msgs_list = sqimap_get_small_header_list($imapConnection, $id);
489 if (sizeof($msgs_list)){
490 foreach ($msgs_list as $hdr) {
491 $unique_id[] = $hdr->uid
;
492 $from[] = $hdr->from
;
493 $date[] = $hdr->date
;
494 $subject[] = $hdr->subject
;
496 $priority[] = $hdr->priority
;
498 $size[] = $hdr->size
;
499 $type[] = $hdr->type0
;
500 $flag_deleted[] = $hdr->flag_deleted
;
501 $flag_answered[] = $hdr->flag_answered
;
502 $flag_seen[] = $hdr->flag_seen
;
503 $flag_flagged[] = $hdr->flag_flagged
;
508 while ($j < $count) {
510 if (isset($date[$j])) {
511 $date[$j] = str_replace(' ', ' ', $date[$j]);
512 $tmpdate = explode(' ', trim($date[$j]));
514 $tmpdate = $date = array('', '', '', '', '', '');
516 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
517 $messages[$j]['DATE_STRING'] =
518 getDateString($messages[$j]['TIME_STAMP']);
519 $messages[$j]['ID'] = $unique_id[$j];
520 $messages[$j]['FROM'] = decodeHeader($from[$j]);
521 $messages[$j]['FROM-SORT'] =
522 strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
523 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
524 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
525 $messages[$j]['TO'] = decodeHeader($to[$j]);
526 $messages[$j]['PRIORITY'] = $priority[$j];
527 $messages[$j]['CC'] = $cc[$j];
528 $messages[$j]['SIZE'] = $size[$j];
529 $messages[$j]['TYPE0'] = $type[$j];
530 $messages[$j]['FLAG_DELETED'] = $flag_deleted[$j];
531 $messages[$j]['FLAG_ANSWERED'] = $flag_answered[$j];
532 $messages[$j]['FLAG_SEEN'] = $flag_seen[$j];
533 $messages[$j]['FLAG_FLAGGED'] = $flag_flagged[$j];
537 * fix SUBJECT-SORT to remove Re:
541 * TODO: i18n should be incorporated here. E.g. we catch the ones
542 * we know about, but also define in i18n what the localized
543 * "Re: " is for this or that locale.
545 if (preg_match("/^(vedr|sv|re|aw):\s*(.*)$/si",
546 $messages[$j]['SUBJECT-SORT'], $matches)){
547 $messages[$j]['SUBJECT-SORT'] = $matches[2];
555 /* Generic function to convert the msgs array into an HTML table. */
556 function displayMessageArray($imapConnection, $num_msgs, $start_msg,
557 $msort, $mailbox, $sort, $color,
558 $show_num, $where=0, $what=0) {
559 global $imapServerAddress, $use_mailbox_cache,
560 $index_order, $checkall,
561 $indent_array, $thread_sort_messages, $allow_server_sort,
562 $server_sort_order, $PHP_SELF;
564 $end_msg = getEndMessage(&$start_msg, $show_num, $num_msgs);
566 $urlMailbox = urlencode($mailbox);
568 /* get indent level for subject display */
569 if ($thread_sort_messages == 1 ) {
570 $indent_array = get_parent_level($imapConnection);
574 $real_startMessage = $start_msg;
576 if ($end_msg - $start_msg < $show_num - 1) {
577 $end_msg = $end_msg - $start_msg +
1;
579 } else if ($start_msg > $show_num) {
580 $end_msg = $show_num;
584 $endVar = $end_msg +
1;
587 * Loop through and display the info for each message.
588 * ($t is used for the checkbox number)
592 /* messages display */
593 echo html_tag( 'table' ,'' , '', '', 'border="0" width="100%" cellpadding="1" cellspacing="0"' );
594 if ($num_msgs == 0) {
595 /* if there's no messages in this folder */
598 "<BR><b>" . _("THIS FOLDER IS EMPTY") . "</b><BR> ",
601 'COLSPAN="' . count($index_order) . '"'
604 } elseif ($start_msg == $end_msg) {
605 /* if there's only one message in the box, handle it differently. */
617 } while (isset ($key) && ($k < $i));
618 printMessageInfo($imapConnection, $t, $i, $key, $mailbox,
628 } while (isset ($key) && ($k < $i));
630 printMessageInfo($imapConnection, $t, $i, $key, $mailbox,
636 } while ($i && $i < $endVar);
642 * Displays the standard message list header. To finish the table,
643 * you need to do a "</table></table>";
645 * $moveURL is the URL to submit the delete/move form to
646 * $mailbox is the current mailbox
647 * $sort is the current sorting method (-1 for no sorting available [searches])
648 * $Message is a message that is centered on top of the list
649 * $More is a second line that is left aligned
652 function mail_message_listing_beginning ($imapConnection,
653 $mailbox = '', $sort = -1,
655 $paginator = ' ',
657 global $color, $auto_expunge, $base_uri, $thread_sort_messages,
658 $allow_thread_sort, $allow_server_sort, $server_sort_order,
661 $urlMailbox = urlencode($mailbox);
663 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
664 $source_url = $regs[1];
666 $source_url = $PHP_SELF;
672 $moveURL = "move_messages.php?msg=$msg&mailbox=$urlMailbox"
673 . "&startMessage=$start_msg";
676 * This is the beginning of the message list table.
677 * It wraps around all messages
680 echo "<FORM name=\"messageList\" method=post action=\"$moveURL\">\n"
681 . html_tag( 'table' ,'' , '', '', 'border="0" width="100%" cellpadding="1" cellspacing="0"' ) .
686 html_tag( 'td', $paginator, 'left' ) .
687 html_tag( 'td', $msg_cnt_str, 'right' )
689 , '', $color[4], 'border="0" width="100%" cellpadding="2" cellspacing="0"' )
692 . html_tag( 'tr' ) . "\n"
693 . html_tag( 'td' ,'' , 'left', $color[0], '' )
694 . html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="0" cellspacing="0"' )
696 getSmallStringCell(_("Move Selected To:"), 'left') .
697 getSmallStringCell(_("Transform Selected Messages"), 'right')
699 . html_tag( 'tr' ) ."\n"
700 . html_tag( 'td', '', 'left', '', 'valign="middle" nowrap' );
701 getMbxList($imapConnection);
702 echo getButton('SUBMIT', 'moveButton',_("Move")) . ' '."\n";
703 echo getButton('SUBMIT', 'attache',_("Forward")) . ' '."\n";
706 . html_tag( 'td', '', 'right', '', 'nowrap' );
708 if (!$auto_expunge) {
709 echo getButton('SUBMIT', 'expungeButton',_("Expunge"))
710 .' ' . _("mailbox") . ' '."\n";
713 echo getButton('SUBMIT', 'markRead',_("Read")) ."\n";
714 echo getButton('SUBMIT', 'markUnread',_("Unread")) ."\n";
715 echo getButton('SUBMIT', 'delete',_("Delete")) .' '."\n";
719 /* draws thread sorting links */
720 if ($allow_thread_sort == TRUE) {
721 if ($thread_sort_messages == 1 ) {
723 $thread_name = _("Unthread View");
725 elseif ($thread_sort_messages == 0) {
727 $thread_name = _("Thread View");
729 echo html_tag( 'tr' ,
731 ' <a href=' . $source_url . '?sort='
732 . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
733 . '&mailbox=' . urlencode($mailbox) . '><small>' . $thread_name
734 . '</a></small> '
743 do_hook('mailbox_form_before');
747 . html_tag( 'td' ,'' , '', $color[0], '' );
748 if ($GLOBALS['alt_index_colors']){
753 echo html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="2" cellspacing="'. $cellspacing .'"' );
755 /* if using server sort we highjack the
756 * the $sort var and use $server_sort_order
757 * instead. but here we reset sort for a bit
760 if ($allow_server_sort == TRUE) {
761 $sort = $server_sort_order;
765 function mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color) {
767 echo html_tag( 'table',
772 html_tag( 'td', $paginator_str ) .
773 html_tag( 'td', $msg_cnt_str, 'right' )
775 , '', $color[4], 'width="100%" cellpadding="1" cellspacing="1"' )
778 , '', $color[9], 'width="100%" cellpadding="1" cellspacing="1"' );
781 /* End of message-list table */
783 do_hook('mailbox_index_after');
788 function printHeader($mailbox, $sort, $color, $showsort=true) {
790 echo html_tag( 'tr' ,'' , 'center', $color[5] );
791 for ($i=1; $i <= count($index_order); $i++
) {
792 switch ($index_order[$i]) {
793 case 1: /* checkbox */
795 echo html_tag( 'td' ,' ' , '', '', 'width="1%"' );
798 if (handleAsSent($mailbox)) {
799 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
800 . '<b>' . _("To") . '</b>';
802 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
803 . '<b>' . _("From") . '</b>';
806 ShowSortButton($sort, $mailbox, 2, 3);
811 echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
812 . '<b>' . _("Date") . '</b>';
814 ShowSortButton($sort, $mailbox, 0, 1);
818 case 4: /* subject */
819 echo html_tag( 'td' ,'' , 'left', '', '' )
820 . '<b>' . _("Subject") . '</b>';
822 ShowSortButton($sort, $mailbox, 4, 5);
827 echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%"' );
836 * This function shows the sort button. Isn't this a good comment?
838 function ShowSortButton($sort, $mailbox, $Up, $Down ) {
840 /* Figure out which image we want to use. */
841 if ($sort != $Up && $sort != $Down) {
842 $img = 'sort_none.png';
844 } elseif ($sort == $Up) {
845 $img = 'up_pointer.png';
848 $img = 'down_pointer.png';
852 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
853 $source_url = $regs[1];
855 $source_url = $PHP_SELF;
858 /* Now that we have everything figured out, show the actual button. */
859 echo ' <a href="' . $source_url .'?newsort=' . $which
860 . '&startMessage=1&mailbox=' . urlencode($mailbox)
861 . '"><IMG SRC="../images/' . $img
862 . '" BORDER=0 WIDTH=12 HEIGHT=10 ALT="sort"></a>';
865 function get_selectall_link($start_msg, $sort) {
866 global $checkall, $what, $where, $mailbox, $javascript_on;
867 global $PHP_SELF, $PG_SHOWNUM;
870 if ($javascript_on) {
872 '<script language="JavaScript" type="text/javascript">'
874 . "function CheckAll() {\n"
875 . " for (var i = 0; i < document.messageList.elements.length; i++) {\n"
876 . " if(document.messageList.elements[i].type == 'checkbox'){\n"
877 . " document.messageList.elements[i].checked = "
878 . " !(document.messageList.elements[i].checked);\n"
883 . '</script><a href="#" onClick="CheckAll();">' . _("Toggle All")
886 if (strpos($PHP_SELF, "?")) {
887 $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($mailbox)
888 . "&startMessage=$start_msg&sort=$sort&checkall=";
890 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
891 . "&startMessage=$start_msg&sort=$sort&checkall=";
893 if (isset($checkall) && $checkall == '1') {
899 if (isset($where) && isset($what)) {
900 $result .= '&where=' . urlencode($where)
901 . '&what=' . urlencode($what);
906 if (isset($checkall) && ($checkall == '1')) {
907 $result .= _("Unselect All");
909 $result .= _("Select All");
915 /* Return our final result. */
920 * This function computes the "Viewing Messages..." string.
922 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
923 /* Compute the $msg_cnt_str. */
925 if ($start_msg < $end_msg) {
926 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"),
927 $start_msg, $end_msg, $num_msgs);
928 } else if ($start_msg == $end_msg) {
929 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
933 /* Return our result string. */
938 * Generate a paginator link.
940 function get_paginator_link($box, $start_msg, $use, $text) {
943 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
944 $source_url = $regs[1];
946 $source_url = $PHP_SELF;
949 $result = '<A HREF="'. $source_url . "?use_mailbox_cache=$use"
950 . "&startMessage=$start_msg&mailbox=$box\" "
951 . "TARGET=\"right\">$text</A>";
956 * This function computes the paginator string.
958 function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
960 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
962 /* Initialize paginator string chunks. */
969 $box = urlencode($box);
971 /* Create simple strings that will be creating the paginator. */
972 $spc = ' '; /* This will be used as a space. */
973 $sep = '|'; /* This will be used as a seperator. */
975 /* Get some paginator preference values. */
976 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON
);
977 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
);
979 /* Make sure that our start message number is not too big. */
980 $start_msg = min($start_msg, $num_msgs);
982 /* Decide whether or not we will use the mailbox cache. */
983 /* Not sure why $use_mailbox_cache is even passed in. */
990 /* Compute the starting message of the previous and next page group. */
991 $next_grp = $start_msg +
$show_num;
992 $prev_grp = $start_msg - $show_num;
994 /* Compute the basic previous and next strings. */
995 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
996 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
997 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
998 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
999 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1000 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
1001 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
1002 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
1003 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1006 /* Page selector block. Following code computes page links. */
1007 if ($pg_sel && ($num_msgs > $show_num)) {
1008 /* Most importantly, what is the current page!!! */
1009 $cur_pg = intval($start_msg / $show_num) +
1;
1011 /* Compute total # of pages and # of paginator page links. */
1012 $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
1013 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
1015 /* Compute the size of the four quarters of the page links. */
1017 /* If we can, just show all the pages. */
1018 if (($tot_pgs - 1) <= $pg_max) {
1019 $q1_pgs = $cur_pg - 1;
1020 $q2_pgs = $q3_pgs = 0;
1021 $q4_pgs = $tot_pgs - $cur_pg;
1023 /* Otherwise, compute some magic to choose the four quarters. */
1026 * Compute the magic base values. Added together,
1027 * these values will always equal to the $pag_pgs.
1028 * NOTE: These are DEFAULT values and do not take
1029 * the current page into account. That is below.
1031 $q1_pgs = floor($vis_pgs/4);
1032 $q2_pgs = round($vis_pgs/4, 0);
1033 $q3_pgs = ceil($vis_pgs/4);
1034 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
1036 /* Adjust if the first quarter contains the current page. */
1037 if (($cur_pg - $q1_pgs) < 1) {
1038 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) +
$q2_pgs;
1039 $q1_pgs = $cur_pg - 1;
1041 $q3_pgs +
= ceil($extra_pgs / 2);
1042 $q4_pgs +
= floor($extra_pgs / 2);
1044 /* Adjust if the first and second quarters intersect. */
1045 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
1046 $extra_pgs = $q2_pgs;
1047 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1048 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1049 $q3_pgs +
= ceil($extra_pgs / 2);
1050 $q4_pgs +
= floor($extra_pgs / 2);
1052 /* Adjust if the fourth quarter contains the current page. */
1053 } else if (($cur_pg +
$q4_pgs) >= $tot_pgs) {
1054 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) +
$q3_pgs;
1056 $q4_pgs = $tot_pgs - $cur_pg;
1057 $q1_pgs +
= floor($extra_pgs / 2);
1058 $q2_pgs +
= ceil($extra_pgs / 2);
1060 /* Adjust if the third and fourth quarter intersect. */
1061 } else if (($cur_pg +
$q3_pgs +
1) >= ($tot_pgs - $q4_pgs +
1)) {
1062 $extra_pgs = $q3_pgs;
1063 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1064 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1065 $q1_pgs +
= floor($extra_pgs / 2);
1066 $q2_pgs +
= ceil($extra_pgs / 2);
1071 * I am leaving this debug code here, commented out, because
1072 * it is a really nice way to see what the above code is doing.
1073 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
1074 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
1077 /* Print out the page links from the compute page quarters. */
1079 /* Start with the first quarter. */
1080 if (($q1_pgs == 0) && ($cur_pg > 1)) {
1081 $pg_str .= "...$spc";
1083 for ($pg = 1; $pg <= $q1_pgs; ++
$pg) {
1084 $start = (($pg-1) * $show_num) +
1;
1085 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1087 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
1088 $pg_str .= "...$spc";
1092 /* Continue with the second quarter. */
1093 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++
$pg) {
1094 $start = (($pg-1) * $show_num) +
1;
1095 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1098 /* Now print the current page. */
1099 $pg_str .= $cur_pg . $spc;
1101 /* Next comes the third quarter. */
1102 for ($pg = $cur_pg +
1; $pg <= $cur_pg +
$q3_pgs; ++
$pg) {
1103 $start = (($pg-1) * $show_num) +
1;
1104 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1107 /* And last, print the forth quarter page links. */
1108 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
1109 $pg_str .= "...$spc";
1111 if (($tot_pgs - $q4_pgs) > ($cur_pg +
$q3_pgs)) {
1112 $pg_str .= "...$spc";
1114 for ($pg = $tot_pgs - $q4_pgs +
1; $pg <= $tot_pgs; ++
$pg) {
1115 $start = (($pg-1) * $show_num) +
1;
1116 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1119 } else if ($PG_SHOWNUM == 999999) {
1120 $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
1121 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1122 . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc;
1125 /* If necessary, compute the 'show all' string. */
1126 if (($prv_str != '') ||
($nxt_str != '')) {
1127 $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
1128 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1129 . "TARGET=\"right\">" . _("Show All") . '</A>';
1132 /* Last but not least, get the value for the toggle all link. */
1133 $tgl_str = get_selectall_link($start_msg, $sort);
1135 /* Put all the pieces of the paginator string together. */
1137 * Hairy code... But let's leave it like it is since I am not certain
1138 * a different approach would be any easier to read. ;)
1141 $result .= ($prv_str != '' ?
$prv_str . $spc . $sep . $spc : '');
1142 $result .= ($nxt_str != '' ?
$nxt_str . $spc . $sep . $spc : '');
1143 $result .= ($pg_str != '' ?
$pg_str : '');
1144 $result .= ($all_str != '' ?
$sep . $spc . $all_str . $spc : '');
1145 $result .= ($result != '' ?
$sep . $spc . $tgl_str: $tgl_str);
1147 /* If the resulting string is blank, return a non-breaking space. */
1148 if ($result == '') {
1152 /* Return our final magical paginator string. */
1156 function processSubject($subject) {
1157 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1159 return _("(no subject)");
1161 if (strlen($subject) <= 55)
1164 $ent_strlen=strlen($subject);
1168 * see if this is entities-encoded string
1169 * If so, Iterate through the whole string, find out
1170 * the real number of characters, and if more
1171 * than 55, substr with an updated trim value.
1173 while ( (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1174 (($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false) ) {
1175 $trim_val +
= ($ent_loc_end-$ent_loc)+
1;
1176 $ent_strlen -= $ent_loc_end-$ent_loc;
1177 $ent_offset = $ent_loc_end+
1;
1180 if ($ent_strlen <= 55){
1184 return substr($subject, 0, $trim_val) . '...';
1187 function getMbxList($imapConnection) {
1188 global $lastTargetMailbox;
1189 echo ' <small> <tt><select name="targetMailbox">';
1190 $boxes = sqimap_mailbox_list($imapConnection);
1191 foreach ($boxes as $boxes_part) {
1192 if (!in_array('noselect', $boxes_part['flags'])) {
1193 $box = $boxes_part['unformatted'];
1194 $box2 = str_replace(' ', ' ', imap_utf7_decode_local($boxes_part['unformatted-disp']));
1195 if( $box2 == 'INBOX' ) {
1198 if ($lastTargetMailbox == $box) {
1199 echo " <OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
1202 echo " <OPTION VALUE=\"$box\">$box2</OPTION>\n";
1206 echo ' </SELECT></TT> ';
1209 function getButton($type, $name, $value) {
1210 return '<INPUT TYPE="'.$type.'" NAME="'.$name.'" VALUE="'.$value . '">';
1213 function getSmallStringCell($string, $align) {
1214 return html_tag( 'td',
1215 '<small>' . $string . ': </small>',
1221 function getEndMessage($start_msg, $show_num, $num_msgs) {
1222 if ($start_msg +
($show_num - 1) < $num_msgs){
1223 $end_msg = $start_msg +
($show_num - 1);
1225 $end_msg = $num_msgs;
1228 if ($end_msg < $start_msg) {
1229 $start_msg = $start_msg - $show_num;
1230 if ($start_msg < 1) {
1237 function handleAsSent($mailbox) {
1238 global $sent_folder, $draft_folder, $handleAsSent_result;
1240 /* First check if this is the sent or draft folder. */
1241 $handleAsSent_result = (($mailbox == $sent_folder)
1242 ||
($mailbox == $draft_folder));
1244 /* Then check the result of the handleAsSent hook. */
1245 do_hook('check_handleAsSent_result', $mailbox);
1247 /* And return the result. */
1248 return ($handleAsSent_result);