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(SM_PATH
. 'functions/strings.php');
16 require_once(SM_PATH
. 'functions/html.php');
17 require_once(SM_PATH
. 'class/html.class.php');
18 require_once(SM_PATH
. 'functions/imap_mailbox.php');
20 /* Default value for page_selector_max. */
21 define('PG_SEL_MAX', 10);
23 function printMessageInfo($imapConnection, $t, $not_last=true, $key, $mailbox,
24 $start_msg, $where, $what) {
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>';
112 if ($where && $what) {
113 $searchstr = '&where='.$where.'&what='.$what;
118 * AAAAH! Make my eyes stop bleeding!
121 if (sizeof($message_highlight_list)){
122 foreach ($message_highlight_list as $message_highlight_list_part) {
123 if (trim($message_highlight_list_part['value']) != '') {
124 $high_val = strtolower($message_highlight_list_part['value']);
125 $match_type = strtoupper($message_highlight_list_part['match_type']);
126 if ($match_type == 'TO_CC') {
127 if (strstr('^^' . strtolower($msg['TO']), $high_val) ||
128 strstr('^^' . strtolower($msg['CC']), $high_val)) {
129 $hlt_color = $message_highlight_list_part['color'];
133 if (strstr('^^' . strtolower($msg[$match_type]), $high_val)) {
134 $hlt_color = $message_highlight_list_part['color'];
142 if (!isset($hlt_color)) {
143 $hlt_color = $color_string;
145 $checked = ($checkall == 1) ?
true : false;
147 if (sizeof($index_order)) {
148 foreach ($index_order as $index_order_part) {
149 switch ($index_order_part) {
150 case 1: /* checkbox */
152 "<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,
167 $bold . $flag . $fontstr . $msg['DATE_STRING'] .
168 $fontstr_end . $flag_end . $bold_end,
174 case 4: /* subject */
176 if ($thread_sort_messages == 1) {
177 if (isset($indent_array[$msg["ID"]])) {
178 $td_str .= str_repeat(" ",$indent_array[$msg['ID']]);
181 $td_str .= '<a href="read_body.php?mailbox='.$urlMailbox
182 . '&passed_id='. $msg["ID"]
183 . '&startMessage='.$start_msg.$searchstr.'"';
184 do_hook("subject_link");
185 if ($subject != $msg['SUBJECT']) {
186 $title = get_html_translation_table(HTML_SPECIALCHARS
);
187 $title = array_flip($title);
188 $title = strtr($msg['SUBJECT'], $title);
189 $title = str_replace('"', "''", $title);
190 $td_str .= " title=\"$title\"";
192 $td_str .= ">$flag$subject$flag_end</a>$bold_end";
193 echo html_tag( 'td', $td_str, 'left', $hlt_color );
198 $td_str = "<b><small>";
200 if (isset($msg['FLAG_ANSWERED']) && $msg['FLAG_ANSWERED'] == true) {
204 if ($msg['TYPE0'] == 'multipart') {
208 if ($default_use_priority) {
209 if ( ($msg['PRIORITY'] == 1) ||
($msg['PRIORITY'] == 2) ) {
210 $td_str .= "<font color=\"$color[1]\">!</font>";
213 if ($msg['PRIORITY'] == 5) {
214 $td_str .= "<font color=\"$color[8]\">?</font>";
218 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'] == true) {
219 $td_str .= "<font color=\"$color[1]\">D</font>";
225 $td_str .= '</small></b>';
235 $bold . $fontstr . show_readable_size($msg['SIZE']) .
236 $fontstr_end . $bold_end,
245 echo '</tr>'."\n".'<tr><td COLSPAN="'.$col. '" BGCOLOR="'.
246 $color[0].'" HEIGHT="1"></td></tr>'."\n";
252 function getServerSortMessages($imapConnection, $start_msg, $show_num,
253 $num_msgs, $server_sort_order, $mbxresponse) {
254 $id = sqimap_get_sort_order($imapConnection, $server_sort_order,$mbxresponse);
256 if ($start_msg +
($show_num - 1) < $num_msgs) {
257 $end_msg = $start_msg +
($show_num-1);
259 $end_msg = $num_msgs;
261 $id = array_slice($id, ($start_msg-1), ($end_msg));
263 $end = $start_msg +
$show_num - 1;
264 if ($num_msgs < $show_num) {
265 $end_loop = $num_msgs;
266 } else if ($end > $num_msgs) {
267 $end_loop = $num_msgs - $start_msg +
1;
269 $end_loop = $show_num;
271 return fillMessageArray($imapConnection,$id,$end_loop);
277 function getSelfSortMessages($imapConnection, $start_msg, $show_num,
278 $num_msgs, $sort, $mbxresponse) {
280 if ($num_msgs >= 1) {
281 $id = sqimap_get_php_sort_order ($imapConnection, $mbxresponse);
286 /* if it's not sorted */
287 if ($start_msg +
($show_num - 1) < $num_msgs) {
288 $end_msg = $start_msg +
($show_num - 1);
290 $end_msg = $num_msgs;
292 if ($end_msg < $start_msg) {
293 $start_msg = $start_msg - $show_num;
294 if ($start_msg < 1) {
298 $id = array_slice(array_reverse($id), ($start_msg-1), ($end_msg));
299 $end = $start_msg +
$show_num - 1;
300 if ($num_msgs < $show_num) {
301 $end_loop = $num_msgs;
302 } else if ($end > $num_msgs) {
303 $end_loop = $num_msgs - $start_msg +
1;
305 $end_loop = $show_num;
308 $msgs = fillMessageArray($imapConnection,$id,$end_loop);
316 * This function loops through a group of messages in the mailbox
317 * and shows them to the user.
319 function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
320 $start_msg, $sort, $color, $show_num,
321 $use_cache, $mode='') {
322 global $msgs, $msort, $auto_expunge, $thread_sort_messages,
323 $allow_server_sort, $server_sort_order;
325 /* If autoexpunge is turned on, then do it now. */
326 $mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox);
328 /* If autoexpunge is turned on, then do it now. */
329 if ($auto_expunge == true) {
330 $exp_cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, false, '');
331 $mbxresponse['EXISTS'] = $mbxresponse['EXISTS'] - $exp_cnt;
332 $num_msgs = $mbxresponse['EXISTS'];
335 if ($mbxresponse['EXISTS'] > 0) {
336 /* if $start_msg is lower than $num_msgs, we probably deleted all messages
337 * in the last page. We need to re-adjust the start_msg
340 if($start_msg > $num_msgs) {
341 $start_msg -= $show_num;
347 /* This code and the next if() block check for
348 * server-side sorting methods. The $id array is
349 * formatted and $sort is set to 6 to disable
350 * SM internal sorting
353 if ($thread_sort_messages == 1) {
355 } elseif ($allow_server_sort == 1) {
356 $mode = 'serversort';
363 sqsession_unregister('msort');
364 sqsession_unregister('msgs');
365 $msgs = getThreadMessages($imapConnection, $start_msg, $show_num,
367 if ($msgs === false) {
368 echo '<b><small><center><font color=red>' .
369 _("Thread sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
370 '</center></small></b>';
371 $thread_sort_messages = 0;
372 $msort = $msgs = array();
373 sqsession_register($msort, 'msort');
374 sqsession_register($msgs, 'msgs');
378 sqsession_register($msort, 'msort');
379 sqsession_register($msgs, 'msgs');
383 $msgs = getServerSortMessages($imapConnection, $start_msg, $show_num,
384 $num_msgs, $sort, $mbxresponse);
385 if ($msgs === false) {
386 echo '<b><small><center><font color=red>' .
387 _( "Server-side sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
388 '</center></small></b>';
389 $sort = $server_sort_order;
390 $allow_server_sort = FALSE;
391 $msort = $msgs = array();
392 sqsession_register($msort, 'msort');
393 sqsession_register($msgs, 'msgs');
398 sqsession_register($msort, 'msort');
399 sqsession_register($msgs, 'msgs');
404 sqsession_unregister('msgs');
405 sqsession_unregister('msort');
406 $msgs = getSelfSortMessages($imapConnection, $start_msg, $show_num,
407 $num_msgs, $sort, $mbxresponse);
408 $msort = calc_msort($msgs, $sort);
409 sqsession_register($msort, 'msort');
410 sqsession_register($msgs, 'msgs');
414 } /* if exists > 0 */
416 $res = getEndMessage($start_msg, $show_num, $num_msgs);
417 $start_msg = $res[0];
420 $paginator_str = get_paginator_str($mailbox, $start_msg, $end_msg,
421 $num_msgs, $show_num, $sort);
423 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
425 do_hook('mailbox_index_before');
427 mail_message_listing_beginning($imapConnection, $mailbox, $sort,
428 $msg_cnt_str, $paginator_str, $start_msg);
431 echo '<table bgcolor="' . $color[0] . '" border="0" width="100%" cellpadding="1" cellspacing="0"><tr><td>';
432 printHeader($mailbox, $srt, $color, !$thread_sort_messages);
434 displayMessageArray($imapConnection, $num_msgs, $start_msg,
435 $msort, $mailbox, $sort, $color, $show_num, 0, 0);
437 mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color);
438 echo '</td></tr></table>';
441 * TODO: Switch to using $_SESSION[] whenever we ditch the 4.0.x series.
445 function calc_msort($msgs, $sort) {
455 if (($sort == 0) ||
($sort == 1)) {
456 $msort = array_cleave ($msgs, 'TIME_STAMP');
457 } elseif (($sort == 2) ||
($sort == 3)) {
458 $msort = array_cleave ($msgs, 'FROM-SORT');
459 } elseif (($sort == 4) ||
($sort == 5)) {
460 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
474 function fillMessageArray($imapConnection, $id, $count) {
475 $msgs_list = sqimap_get_small_header_list($imapConnection, $id);
477 if (sizeof($msgs_list)) {
478 foreach ($msgs_list as $hdr) {
479 $unique_id[] = $hdr->uid
;
480 $from[] = $hdr->from
;
481 $date[] = $hdr->date
;
482 $subject[] = $hdr->subject
;
484 $priority[] = $hdr->priority
;
486 $size[] = $hdr->size
;
487 $type[] = $hdr->type0
;
488 $flag_deleted[] = $hdr->flag_deleted
;
489 $flag_answered[] = $hdr->flag_answered
;
490 $flag_seen[] = $hdr->flag_seen
;
491 $flag_flagged[] = $hdr->flag_flagged
;
495 for($j = 0; $j < $count; ++
$j) {
496 if (isset($date[$j])) {
497 $date[$j] = str_replace(' ', ' ', $date[$j]);
498 $tmpdate = explode(' ', trim($date[$j]));
500 $tmpdate = $date = array('', '', '', '', '', '');
502 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
503 $messages[$j]['DATE_STRING'] =
504 getDateString($messages[$j]['TIME_STAMP']);
505 $messages[$j]['ID'] = $unique_id[$j];
506 $messages[$j]['FROM'] = decodeHeader($from[$j]);
507 $messages[$j]['FROM-SORT'] =
508 strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
509 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
510 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
511 $messages[$j]['TO'] = decodeHeader($to[$j]);
512 $messages[$j]['PRIORITY'] = $priority[$j];
513 $messages[$j]['CC'] = $cc[$j];
514 $messages[$j]['SIZE'] = $size[$j];
515 $messages[$j]['TYPE0'] = $type[$j];
516 $messages[$j]['FLAG_DELETED'] = $flag_deleted[$j];
517 $messages[$j]['FLAG_ANSWERED'] = $flag_answered[$j];
518 $messages[$j]['FLAG_SEEN'] = $flag_seen[$j];
519 $messages[$j]['FLAG_FLAGGED'] = $flag_flagged[$j];
522 * fix SUBJECT-SORT to remove Re:
526 * TODO: i18n should be incorporated here. E.g. we catch the ones
527 * we know about, but also define in i18n what the localized
528 * "Re: " is for this or that locale.
530 if (preg_match("/^(vedr|sv|re|aw):\s*(.*)$/si",
531 $messages[$j]['SUBJECT-SORT'], $matches)){
532 $messages[$j]['SUBJECT-SORT'] = $matches[2];
539 /* Generic function to convert the msgs array into an HTML table. */
540 function displayMessageArray($imapConnection, $num_msgs, $start_msg,
541 $msort, $mailbox, $sort, $color,
542 $show_num, $where=0, $what=0) {
543 global $imapServerAddress, $use_mailbox_cache,
544 $index_order, $checkall,
545 $indent_array, $thread_sort_messages, $allow_server_sort,
546 $server_sort_order, $PHP_SELF;
548 $res = getEndMessage($start_msg, $show_num, $num_msgs);
549 $start_msg = $res[0];
552 $urlMailbox = urlencode($mailbox);
554 /* get indent level for subject display */
555 if ($thread_sort_messages == 1 ) {
556 $indent_array = get_parent_level($imapConnection);
559 $real_startMessage = $start_msg;
561 if ($end_msg - $start_msg < $show_num - 1) {
562 $end_msg = $end_msg - $start_msg +
1;
564 } else if ($start_msg > $show_num) {
565 $end_msg = $show_num;
569 $endVar = $end_msg +
1;
572 * Loop through and display the info for each message.
573 * ($t is used for the checkbox number)
577 /* messages display */
579 if ($num_msgs == 0) {
580 /* if there's no messages in this folder */
583 "<BR><b>" . _("THIS FOLDER IS EMPTY") . "</b><BR> ",
586 'COLSPAN="' . count($index_order) . '"'
589 } elseif ($start_msg == $end_msg) {
590 /* if there's only one message in the box, handle it differently. */
602 } while (isset ($key) && ($k < $i));
603 printMessageInfo($imapConnection, $t, true, $key, $mailbox,
604 $real_startMessage, $where, $what);
613 } while (isset ($key) && ($k < $i));
616 if (!$i ||
$i == $endVar-1) $not_last = false;
617 printMessageInfo($imapConnection, $t, $not_last, $key, $mailbox,
618 $real_startMessage, $where, $what);
623 } while ($i && $i < $endVar);
629 * Displays the standard message list header. To finish the table,
630 * you need to do a "</table></table>";
632 * $moveURL is the URL to submit the delete/move form to
633 * $mailbox is the current mailbox
634 * $sort is the current sorting method (-1 for no sorting available [searches])
635 * $Message is a message that is centered on top of the list
636 * $More is a second line that is left aligned
639 function mail_message_listing_beginning ($imapConnection,
640 $mailbox = '', $sort = -1,
642 $paginator = ' ',
644 global $color, $auto_expunge, $base_uri, $thread_sort_messages,
645 $allow_thread_sort, $allow_server_sort, $server_sort_order,
648 $php_self = $PHP_SELF;
649 /* fix for incorrect $PHP_SELF */
650 if (strpos($php_self, 'move_messages.php')) {
651 $php_self = str_replace('move_messages.php', 'right_main.php', $php_self);
653 $urlMailbox = urlencode($mailbox);
655 if (preg_match('/^(.+)\?.+$/',$php_self,$regs)) {
656 $source_url = $regs[1];
658 $source_url = $php_self;
664 $moveURL = "move_messages.php?msg=$msg&mailbox=$urlMailbox"
665 . "&startMessage=$start_msg";
667 * This is the beginning of the message list table.
668 * It wraps around all messages
671 echo "<FORM name=\"messageList\" method=post action=\"$moveURL\">\n"
672 . html_tag( 'table' ,'' , '', '', 'border="0" width="100%" cellpadding="1" cellspacing="0"' ) .
677 html_tag( 'td', $paginator, 'left' ) .
678 html_tag( 'td', $msg_cnt_str, 'right' )
680 , '', $color[4], 'border="0" width="100%" cellpadding="2" cellspacing="0"' )
683 . html_tag( 'tr' ) . "\n"
684 . html_tag( 'td' ,'' , 'left', $color[0], '' )
685 . html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="0" cellspacing="0"' )
687 getSmallStringCell(' ' . _("Move Selected To"), 'left') .
688 getSmallStringCell(_("Transform Selected Messages"), 'right')
690 . html_tag( 'tr' ) ."\n"
691 . html_tag( 'td', '', 'left', '', 'valign="middle" nowrap' );
692 getMbxList($imapConnection);
693 echo getButton('SUBMIT', 'moveButton',_("Move")) . "\n";
694 echo getButton('SUBMIT', 'attache',_("Forward")) . "\n";
697 . html_tag( 'td', '', 'right', '', 'nowrap' );
699 if (!$auto_expunge) {
700 echo getButton('SUBMIT', 'expungeButton',_("Expunge"))
701 .' ' . _("mailbox") . "\n";
704 echo getButton('SUBMIT', 'markRead',_("Read"));
705 echo getButton('SUBMIT', 'markUnread',_("Unread"));
706 echo getButton('SUBMIT', 'delete',_("Delete")) ." \n";
707 if (!strpos($php_self,'mailbox')) {
708 $location = $php_self.'?mailbox=INBOX&startMessage=1';
710 $location = $php_self;
712 echo '<INPUT TYPE="HIDDEN" NAME="location" VALUE="'.$location.'">';
716 /* draws thread sorting links */
717 if ($allow_thread_sort == TRUE) {
718 if ($thread_sort_messages == 1 ) {
720 $thread_name = _("Unthread View");
721 } elseif ($thread_sort_messages == 0) {
723 $thread_name = _("Thread View");
725 echo html_tag( 'tr' ,
727 ' <a href=' . $source_url . '?sort='
728 . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
729 . '&mailbox=' . urlencode($mailbox) . '><small>' . $thread_name
730 . '</a></small> '
738 do_hook('mailbox_form_before');
742 . html_tag( 'td' ,'' , '', $color[0], '' );
744 /* if using server sort we highjack the
745 * the $sort var and use $server_sort_order
746 * instead. but here we reset sort for a bit
749 if ($allow_server_sort == TRUE) {
750 $sort = $server_sort_order;
754 function mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color) {
756 echo html_tag( 'table',
761 html_tag( 'td', $paginator_str ) .
762 html_tag( 'td', $msg_cnt_str, 'right' )
764 , '', $color[4], 'width="100%" cellpadding="1" cellspacing="1"' )
767 , '', $color[9], 'width="100%" cellpadding="1" cellspacing="1"' );
770 /* End of message-list table */
772 do_hook('mailbox_index_after');
776 function printHeader($mailbox, $sort, $color, $showsort=true) {
778 echo html_tag( 'table' ,'' , '', $color[4], 'border="0" width="100%" cellpadding="1" cellspacing="0"' );
779 echo html_tag( 'tr' ,'' , 'center', $color[5] );
780 for ($i = 1; $i <= count($index_order); $i++
) {
781 switch ($index_order[$i]) {
782 case 1: /* checkbox */
784 echo html_tag( 'td' ,' ' , '', '', 'width="1%"' );
787 if (handleAsSent($mailbox)) {
788 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
789 . '<b>' . _("To") . '</b>';
791 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
792 . '<b>' . _("From") . '</b>';
795 ShowSortButton($sort, $mailbox, 2, 3);
800 echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
801 . '<b>' . _("Date") . '</b>';
803 ShowSortButton($sort, $mailbox, 0, 1);
807 case 4: /* subject */
808 echo html_tag( 'td' ,'' , 'left', '', '' )
809 . '<b>' . _("Subject") . '</b>';
811 ShowSortButton($sort, $mailbox, 4, 5);
816 echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%"' );
825 * This function shows the sort button. Isn't this a good comment?
827 function ShowSortButton($sort, $mailbox, $Up, $Down ) {
829 /* Figure out which image we want to use. */
830 if ($sort != $Up && $sort != $Down) {
831 $img = 'sort_none.png';
833 } elseif ($sort == $Up) {
834 $img = 'up_pointer.png';
837 $img = 'down_pointer.png';
841 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
842 $source_url = $regs[1];
844 $source_url = $PHP_SELF;
847 /* Now that we have everything figured out, show the actual button. */
848 echo ' <a href="' . $source_url .'?newsort=' . $which
849 . '&startMessage=1&mailbox=' . urlencode($mailbox)
850 . '"><IMG SRC="../images/' . $img
851 . '" BORDER=0 WIDTH=12 HEIGHT=10 ALT="sort"></a>';
854 function get_selectall_link($start_msg, $sort) {
855 global $checkall, $what, $where, $mailbox, $javascript_on;
856 global $PHP_SELF, $PG_SHOWNUM;
859 if ($javascript_on) {
860 $result = '<script language="JavaScript" type="text/javascript">'
862 . "function CheckAll() {\n"
863 . " for (var i = 0; i < document.messageList.elements.length; i++) {\n"
864 . " if(document.messageList.elements[i].type == 'checkbox'){\n"
865 . " document.messageList.elements[i].checked = "
866 . " !(document.messageList.elements[i].checked);\n"
871 . '</script><a href="#" onClick="CheckAll();">' . _("Toggle All")
874 if (strpos($PHP_SELF, "?")) {
875 $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($mailbox)
876 . "&startMessage=$start_msg&sort=$sort&checkall=";
878 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
879 . "&startMessage=$start_msg&sort=$sort&checkall=";
881 if (isset($checkall) && $checkall == '1') {
887 if (isset($where) && isset($what)) {
888 $result .= '&where=' . urlencode($where)
889 . '&what=' . urlencode($what);
893 if (isset($checkall) && ($checkall == '1')) {
894 $result .= _("Unselect All");
896 $result .= _("Select All");
901 /* Return our final result. */
906 * This function computes the "Viewing Messages..." string.
908 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
909 /* Compute the $msg_cnt_str. */
911 if ($start_msg < $end_msg) {
912 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"),
913 $start_msg, $end_msg, $num_msgs);
914 } else if ($start_msg == $end_msg) {
915 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
919 /* Return our result string. */
924 * Generate a paginator link.
926 function get_paginator_link($box, $start_msg, $use, $text) {
929 $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
930 . "&startMessage=$start_msg&mailbox=$box\" "
931 . "TARGET=\"right\">$text</A>";
934 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
935 $source_url = $regs[1];
937 $source_url = $PHP_SELF;
940 $result = '<A HREF="'. $source_url . "?use_mailbox_cache=$use"
941 . "&startMessage=$start_msg&mailbox=$box\" "
942 . "TARGET=\"right\">$text</A>";
948 * This function computes the paginator string.
950 function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
952 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
954 /* Initialize paginator string chunks. */
961 $box = urlencode($box);
963 /* Create simple strings that will be creating the paginator. */
964 $spc = ' '; /* This will be used as a space. */
965 $sep = '|'; /* This will be used as a seperator. */
967 /* Get some paginator preference values. */
968 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON
);
969 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
);
971 /* Make sure that our start message number is not too big. */
972 $start_msg = min($start_msg, $num_msgs);
974 /* Decide whether or not we will use the mailbox cache. */
975 /* Not sure why $use_mailbox_cache is even passed in. */
982 /* Compute the starting message of the previous and next page group. */
983 $next_grp = $start_msg +
$show_num;
984 $prev_grp = $start_msg - $show_num;
986 /* Compute the basic previous and next strings. */
987 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
988 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
989 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
990 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
991 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
992 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
993 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
994 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
995 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
998 /* Page selector block. Following code computes page links. */
999 if ($pg_sel && ($num_msgs > $show_num)) {
1000 /* Most importantly, what is the current page!!! */
1001 $cur_pg = intval($start_msg / $show_num) +
1;
1003 /* Compute total # of pages and # of paginator page links. */
1004 $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
1005 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
1007 /* Compute the size of the four quarters of the page links. */
1009 /* If we can, just show all the pages. */
1010 if (($tot_pgs - 1) <= $pg_max) {
1011 $q1_pgs = $cur_pg - 1;
1012 $q2_pgs = $q3_pgs = 0;
1013 $q4_pgs = $tot_pgs - $cur_pg;
1015 /* Otherwise, compute some magic to choose the four quarters. */
1018 * Compute the magic base values. Added together,
1019 * these values will always equal to the $pag_pgs.
1020 * NOTE: These are DEFAULT values and do not take
1021 * the current page into account. That is below.
1023 $q1_pgs = floor($vis_pgs/4);
1024 $q2_pgs = round($vis_pgs/4, 0);
1025 $q3_pgs = ceil($vis_pgs/4);
1026 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
1028 /* Adjust if the first quarter contains the current page. */
1029 if (($cur_pg - $q1_pgs) < 1) {
1030 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) +
$q2_pgs;
1031 $q1_pgs = $cur_pg - 1;
1033 $q3_pgs +
= ceil($extra_pgs / 2);
1034 $q4_pgs +
= floor($extra_pgs / 2);
1036 /* Adjust if the first and second quarters intersect. */
1037 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
1038 $extra_pgs = $q2_pgs;
1039 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1040 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1041 $q3_pgs +
= ceil($extra_pgs / 2);
1042 $q4_pgs +
= floor($extra_pgs / 2);
1044 /* Adjust if the fourth quarter contains the current page. */
1045 } else if (($cur_pg +
$q4_pgs) >= $tot_pgs) {
1046 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) +
$q3_pgs;
1048 $q4_pgs = $tot_pgs - $cur_pg;
1049 $q1_pgs +
= floor($extra_pgs / 2);
1050 $q2_pgs +
= ceil($extra_pgs / 2);
1052 /* Adjust if the third and fourth quarter intersect. */
1053 } else if (($cur_pg +
$q3_pgs +
1) >= ($tot_pgs - $q4_pgs +
1)) {
1054 $extra_pgs = $q3_pgs;
1055 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1056 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1057 $q1_pgs +
= floor($extra_pgs / 2);
1058 $q2_pgs +
= ceil($extra_pgs / 2);
1063 * I am leaving this debug code here, commented out, because
1064 * it is a really nice way to see what the above code is doing.
1065 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
1066 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
1069 /* Print out the page links from the compute page quarters. */
1071 /* Start with the first quarter. */
1072 if (($q1_pgs == 0) && ($cur_pg > 1)) {
1073 $pg_str .= "...$spc";
1075 for ($pg = 1; $pg <= $q1_pgs; ++
$pg) {
1076 $start = (($pg-1) * $show_num) +
1;
1077 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1079 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
1080 $pg_str .= "...$spc";
1084 /* Continue with the second quarter. */
1085 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++
$pg) {
1086 $start = (($pg-1) * $show_num) +
1;
1087 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1090 /* Now print the current page. */
1091 $pg_str .= $cur_pg . $spc;
1093 /* Next comes the third quarter. */
1094 for ($pg = $cur_pg +
1; $pg <= $cur_pg +
$q3_pgs; ++
$pg) {
1095 $start = (($pg-1) * $show_num) +
1;
1096 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1099 /* And last, print the forth quarter page links. */
1100 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
1101 $pg_str .= "...$spc";
1103 if (($tot_pgs - $q4_pgs) > ($cur_pg +
$q3_pgs)) {
1104 $pg_str .= "...$spc";
1106 for ($pg = $tot_pgs - $q4_pgs +
1; $pg <= $tot_pgs; ++
$pg) {
1107 $start = (($pg-1) * $show_num) +
1;
1108 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1111 } else if ($PG_SHOWNUM == 999999) {
1112 $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
1113 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1114 . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc;
1117 /* If necessary, compute the 'show all' string. */
1118 if (($prv_str != '') ||
($nxt_str != '')) {
1119 $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
1120 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1121 . "TARGET=\"right\">" . _("Show All") . '</A>';
1124 /* Last but not least, get the value for the toggle all link. */
1125 $tgl_str = get_selectall_link($start_msg, $sort);
1127 /* Put all the pieces of the paginator string together. */
1129 * Hairy code... But let's leave it like it is since I am not certain
1130 * a different approach would be any easier to read. ;)
1133 $result .= ($prv_str != '' ?
$prv_str . $spc . $sep . $spc : '');
1134 $result .= ($nxt_str != '' ?
$nxt_str . $spc . $sep . $spc : '');
1135 $result .= ($pg_str != '' ?
$pg_str : '');
1136 $result .= ($all_str != '' ?
$sep . $spc . $all_str . $spc : '');
1137 $result .= ($result != '' ?
$sep . $spc . $tgl_str: $tgl_str);
1139 /* If the resulting string is blank, return a non-breaking space. */
1140 if ($result == '') {
1144 /* Return our final magical paginator string. */
1148 function processSubject($subject) {
1149 global $languages, $squirrelmail_language;
1150 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1152 return _("(no subject)");
1154 if (strlen($subject) <= 55)
1157 $ent_strlen = strlen($subject);
1161 * see if this is entities-encoded string
1162 * If so, Iterate through the whole string, find out
1163 * the real number of characters, and if more
1164 * than 55, substr with an updated trim value.
1166 while ( (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1167 (($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false) ) {
1168 $trim_val +
= ($ent_loc_end-$ent_loc)+
1;
1169 $ent_strlen -= $ent_loc_end-$ent_loc;
1170 $ent_offset = $ent_loc_end+
1;
1173 if ($ent_strlen <= 55){
1177 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
1178 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
1179 return $languages[$squirrelmail_language]['XTRA_CODE']('strimwidth', $subject, $trim_val);
1182 return substr($subject, 0, $trim_val) . '...';
1185 function getMbxList($imapConnection) {
1186 global $lastTargetMailbox;
1187 echo ' <small> <tt><select name="targetMailbox">';
1188 $boxes = sqimap_mailbox_list($imapConnection);
1189 foreach ($boxes as $boxes_part) {
1190 if (!in_array('noselect', $boxes_part['flags'])) {
1191 $box = $boxes_part['unformatted'];
1192 $box2 = str_replace(' ', ' ', imap_utf7_decode_local($boxes_part['unformatted-disp']));
1193 if($box2 == 'INBOX') {
1196 if ($lastTargetMailbox == $box) {
1197 echo " <OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
1199 echo " <OPTION VALUE=\"$box\">$box2</OPTION>\n";
1203 echo ' </SELECT></TT> ';
1206 function getButton($type, $name, $value) {
1207 return '<INPUT TYPE="'.$type.'" NAME="'.$name.'" VALUE="'.$value . '">';
1210 function getSmallStringCell($string, $align) {
1211 return html_tag('td',
1212 '<small>' . $string . ': </small>',
1218 function getEndMessage($start_msg, $show_num, $num_msgs) {
1219 if ($start_msg +
($show_num - 1) < $num_msgs){
1220 $end_msg = $start_msg +
($show_num - 1);
1222 $end_msg = $num_msgs;
1225 if ($end_msg < $start_msg) {
1226 $start_msg = $start_msg - $show_num;
1227 if ($start_msg < 1) {
1231 return (array($start_msg,$end_msg));
1234 function handleAsSent($mailbox) {
1235 global $sent_folder, $draft_folder, $handleAsSent_result;
1237 /* First check if this is the sent or draft folder. */
1238 $handleAsSent_result = (($mailbox == $sent_folder)
1239 ||
($mailbox == $draft_folder));
1241 /* Then check the result of the handleAsSent hook. */
1242 do_hook('check_handleAsSent_result', $mailbox);
1244 /* And return the result. */
1245 return ($handleAsSent_result);