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, $i, $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 if ($message_highlight_list_part['match_type'] == 'to_cc') {
125 if (strstr('^^' . strtolower($msg['TO']),
126 strtolower($message_highlight_list_part['value']))
127 ||
strstr('^^'.strtolower($msg['CC']),
128 strtolower($message_highlight_list_part['value']))) {
129 $hlt_color = $message_highlight_list_part['color'];
133 if (strstr('^^' . strtolower($msg[strtoupper($message_highlight_list_part['match_type'])]),
134 strtolower($message_highlight_list_part['value']))) {
135 $hlt_color = $message_highlight_list_part['color'];
142 if (!isset($hlt_color)) {
143 $hlt_color = $color_string;
146 $checked = ($checkall == 1) ?
' checked' : '';
153 if (sizeof($index_order)){
154 foreach ($index_order as $index_order_part) {
155 switch ($index_order_part) {
156 case 1: /* checkbox */
158 "<input type=checkbox name=\"msg[$t]\" value=\"".$msg['ID']."\"$checked>",
165 $italic . $bold . $flag . $fontstr . $senderName .
166 $fontstr_end . $flag_end . $bold_end . $italic_end,
173 $bold . $flag . $fontstr . $msg['DATE_STRING'] .
174 $fontstr_end . $flag_end . $bold_end,
180 case 4: /* subject */
182 if ($thread_sort_messages == 1) {
183 if (isset($indent_array[$msg["ID"]])) {
184 $td_str .= str_repeat(" ",$indent_array[$msg['ID']]);
187 $td_str .= '<a href="read_body.php?mailbox='.$urlMailbox
188 .'&passed_id='. $msg["ID"]
189 . '&startMessage='.$start_msg.$searchstr.'"';
190 do_hook("subject_link");
191 if ($subject != $msg['SUBJECT']) {
192 $title = get_html_translation_table(HTML_SPECIALCHARS
);
193 $title = array_flip($title);
194 $title = strtr($msg['SUBJECT'], $title);
195 $title = str_replace('"', "''", $title);
196 $td_str .= " title=\"$title\"";
198 $td_str .= ">$flag$subject$flag_end</a>$bold_end";
199 echo html_tag( 'td', $td_str, 'left', $hlt_color );
204 $td_str = "<b><small>";
206 if (isset($msg['FLAG_ANSWERED']) && $msg['FLAG_ANSWERED'] == true) {
210 if ($msg['TYPE0'] == 'multipart') {
214 if ($default_use_priority) {
215 if ( ($msg['PRIORITY'] == 1) ||
($msg['PRIORITY'] == 2) ) {
216 $td_str .= "<font color=\"$color[1]\">!</font>";
219 if ($msg['PRIORITY'] == 5) {
220 $td_str .= "<font color=\"$color[8]\">?</font>";
224 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'] == true) {
225 $td_str .= "<font color=\"$color[1]\">D</font>";
231 $td_str .= '</small></b>';
242 $bold . $fontstr . show_readable_size($msg['SIZE']) .
243 $fontstr_end . $bold_end,
251 echo '</tr>'."\n".'<tr><td colspan="'.$col.'" BGCOLOR="'.
252 $color[0].'" HEIGHT="1"></td></tr>'."\n";
255 function getThreadMessages($imapConnection, $start_msg, $show_num, $num_msgs) {
256 $id = get_thread_sort($imapConnection);
258 if ($start_msg +
($show_num - 1) < $num_msgs) {
259 $end_msg = $start_msg +
($show_num-1);
261 $end_msg = $num_msgs;
263 $id = array_slice($id, ($start_msg-1), ($end_msg));
265 $end = $start_msg +
$show_num - 1;
266 if ($num_msgs < $show_num) {
267 $end_loop = $num_msgs;
268 } else if ($end > $num_msgs) {
269 $end_loop = $num_msgs - $start_msg +
1;
271 $end_loop = $show_num;
273 return fillMessageArray($imapConnection,$id,$end_loop);
279 function getServerSortMessages($imapConnection, $start_msg, $show_num,
280 $num_msgs, $server_sort_order, $mbxresponse) {
281 $id = sqimap_get_sort_order($imapConnection, $server_sort_order,$mbxresponse);
283 if ($start_msg +
($show_num - 1) < $num_msgs) {
284 $end_msg = $start_msg +
($show_num-1);
286 $end_msg = $num_msgs;
288 $id = array_slice($id, ($start_msg-1), ($end_msg));
290 $end = $start_msg +
$show_num - 1;
291 if ($num_msgs < $show_num) {
292 $end_loop = $num_msgs;
293 } else if ($end > $num_msgs) {
294 $end_loop = $num_msgs - $start_msg +
1;
296 $end_loop = $show_num;
298 return fillMessageArray($imapConnection,$id,$end_loop);
304 function getSelfSortMessages($imapConnection, $start_msg, $show_num,
305 $num_msgs, $sort, $mbxresponse) {
307 if ($num_msgs >= 1) {
308 $id = sqimap_get_php_sort_order ($imapConnection, $mbxresponse);
313 /* if it's not sorted */
314 if ($start_msg +
($show_num - 1) < $num_msgs) {
315 $end_msg = $start_msg +
($show_num - 1);
317 $end_msg = $num_msgs;
319 if ($end_msg < $start_msg) {
320 $start_msg = $start_msg - $show_num;
321 if ($start_msg < 1) {
325 $id = array_slice(array_reverse($id), ($start_msg-1), ($end_msg));
326 $end = $start_msg +
$show_num - 1;
327 if ($num_msgs < $show_num) {
328 $end_loop = $num_msgs;
329 } else if ($end > $num_msgs) {
330 $end_loop = $num_msgs - $start_msg +
1;
332 $end_loop = $show_num;
335 $msgs = fillMessageArray($imapConnection,$id,$end_loop);
343 * This function loops through a group of messages in the mailbox
344 * and shows them to the user.
346 function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
347 $start_msg, $sort, $color, $show_num,
348 $use_cache, $mode='') {
349 global $msgs, $msort, $auto_expunge, $thread_sort_messages,
350 $allow_server_sort, $server_sort_order;
352 /* If autoexpunge is turned on, then do it now. */
353 $mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox);
355 /* If autoexpunge is turned on, then do it now. */
356 if ($auto_expunge == true) {
357 $exp_cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, false, '');
358 $mbxresponse['EXISTS'] = $mbxresponse['EXISTS'] - $exp_cnt;
359 $num_msgs = $mbxresponse['EXISTS'];
362 if ($mbxresponse['EXISTS']>0) {
363 /* if $start_msg is lower than $num_msgs, we probably deleted all messages
364 * in the last page. We need to re-adjust the start_msg
367 if($start_msg > $num_msgs) {
368 $start_msg -= $show_num;
374 /* This code and the next if() block check for
375 * server-side sorting methods. The $id array is
376 * formatted and $sort is set to 6 to disable
377 * SM internal sorting
380 if ($thread_sort_messages == 1) {
382 } elseif ($allow_server_sort == 1) {
383 $mode = 'serversort';
390 sqsession_unregister('msort');
391 sqsession_unregister('msgs');
392 $msgs = getThreadMessages($imapConnection, $start_msg, $show_num,
394 if ($msgs === false) {
395 echo '<b><small><center><font color=red>' .
396 _("Thread sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
397 '</center></small></b>';
398 $thread_sort_messages = 0;
399 $msort = $msgs = array();
400 sqsession_register($msort, 'msort');
401 sqsession_register($msgs, 'msgs');
405 sqsession_register($msort, 'msort');
406 sqsession_register($msgs, 'msgs');
411 $msgs = getServerSortMessages($imapConnection, $start_msg, $show_num,
412 $num_msgs, $sort, $mbxresponse);
413 if ($msgs === false) {
414 echo '<b><small><center><font color=red>' .
415 _( "Server-side sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
416 '</center></small></b>';
417 $sort = $server_sort_order;
418 $allow_server_sort = FALSE;
419 $msort = $msgs = array();
420 sqsession_register($msort, 'msort');
421 sqsession_register($msgs, 'msgs');
426 sqsession_register($msort, 'msort');
427 sqsession_register($msgs, 'msgs');
432 sqsession_unregister('msgs');
433 sqsession_unregister('msort');
434 $msgs= getSelfSortMessages($imapConnection, $start_msg, $show_num,
435 $num_msgs, $sort, $mbxresponse);
436 $msort = calc_msort($msgs, $sort);
437 sqsession_register($msort, 'msort');
438 sqsession_register($msgs, 'msgs');
442 } /* if exists > 0 */
444 $res = getEndMessage($start_msg, $show_num, $num_msgs);
445 $start_msg = $res[0];
448 $paginator_str = get_paginator_str($mailbox, $start_msg, $end_msg,
449 $num_msgs, $show_num, $sort);
451 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
453 do_hook('mailbox_index_before');
455 mail_message_listing_beginning($imapConnection, $mailbox, $sort,
456 $msg_cnt_str, $paginator_str, $start_msg);
459 echo '<table bgcolor="' . $color[0] . '" border="0" width="100%" cellpadding="1" cellspacing="0"><tr><td>';
460 printHeader($mailbox, $srt, $color, !$thread_sort_messages);
462 displayMessageArray($imapConnection, $num_msgs, $start_msg,
463 $msort, $mailbox, $sort, $color, $show_num,0,0);
465 mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color);
466 echo '</td></tr></table>';
469 * TODO: Switch to using $_SESSION[] whenever we ditch the 4.0.x series.
473 function calc_msort($msgs, $sort) {
483 if (($sort == 0) ||
($sort == 1)) {
484 $msort = array_cleave ($msgs, 'TIME_STAMP');
485 } elseif (($sort == 2) ||
($sort == 3)) {
486 $msort = array_cleave ($msgs, 'FROM-SORT');
487 } elseif (($sort == 4) ||
($sort == 5)) {
488 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
502 function fillMessageArray($imapConnection,$id,$count) {
503 $msgs_list = sqimap_get_small_header_list($imapConnection, $id);
505 if (sizeof($msgs_list)){
506 foreach ($msgs_list as $hdr) {
507 $unique_id[] = $hdr->uid
;
508 $from[] = $hdr->from
;
509 $date[] = $hdr->date
;
510 $subject[] = $hdr->subject
;
512 $priority[] = $hdr->priority
;
514 $size[] = $hdr->size
;
515 $type[] = $hdr->type0
;
516 $flag_deleted[] = $hdr->flag_deleted
;
517 $flag_answered[] = $hdr->flag_answered
;
518 $flag_seen[] = $hdr->flag_seen
;
519 $flag_flagged[] = $hdr->flag_flagged
;
524 while ($j < $count) {
526 if (isset($date[$j])) {
527 $date[$j] = str_replace(' ', ' ', $date[$j]);
528 $tmpdate = explode(' ', trim($date[$j]));
530 $tmpdate = $date = array('', '', '', '', '', '');
532 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
533 $messages[$j]['DATE_STRING'] =
534 getDateString($messages[$j]['TIME_STAMP']);
535 $messages[$j]['ID'] = $unique_id[$j];
536 $messages[$j]['FROM'] = decodeHeader($from[$j]);
537 $messages[$j]['FROM-SORT'] =
538 strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
539 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
540 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
541 $messages[$j]['TO'] = decodeHeader($to[$j]);
542 $messages[$j]['PRIORITY'] = $priority[$j];
543 $messages[$j]['CC'] = $cc[$j];
544 $messages[$j]['SIZE'] = $size[$j];
545 $messages[$j]['TYPE0'] = $type[$j];
546 $messages[$j]['FLAG_DELETED'] = $flag_deleted[$j];
547 $messages[$j]['FLAG_ANSWERED'] = $flag_answered[$j];
548 $messages[$j]['FLAG_SEEN'] = $flag_seen[$j];
549 $messages[$j]['FLAG_FLAGGED'] = $flag_flagged[$j];
553 * fix SUBJECT-SORT to remove Re:
557 * TODO: i18n should be incorporated here. E.g. we catch the ones
558 * we know about, but also define in i18n what the localized
559 * "Re: " is for this or that locale.
561 if (preg_match("/^(vedr|sv|re|aw):\s*(.*)$/si",
562 $messages[$j]['SUBJECT-SORT'], $matches)){
563 $messages[$j]['SUBJECT-SORT'] = $matches[2];
571 /* Generic function to convert the msgs array into an HTML table. */
572 function displayMessageArray($imapConnection, $num_msgs, $start_msg,
573 $msort, $mailbox, $sort, $color,
574 $show_num, $where=0, $what=0) {
575 global $imapServerAddress, $use_mailbox_cache,
576 $index_order, $checkall,
577 $indent_array, $thread_sort_messages, $allow_server_sort,
578 $server_sort_order, $PHP_SELF;
580 $res = getEndMessage($start_msg, $show_num, $num_msgs);
581 $start_msg = $res[0];
584 $urlMailbox = urlencode($mailbox);
586 /* get indent level for subject display */
587 if ($thread_sort_messages == 1 ) {
588 $indent_array = get_parent_level($imapConnection);
592 $real_startMessage = $start_msg;
594 if ($end_msg - $start_msg < $show_num - 1) {
595 $end_msg = $end_msg - $start_msg +
1;
597 } else if ($start_msg > $show_num) {
598 $end_msg = $show_num;
602 $endVar = $end_msg +
1;
605 * Loop through and display the info for each message.
606 * ($t is used for the checkbox number)
610 /* messages display */
612 if ($num_msgs == 0) {
613 /* if there's no messages in this folder */
616 "<BR><b>" . _("THIS FOLDER IS EMPTY") . "</b><BR> ",
619 'COLSPAN="' . count($index_order) . '"'
622 } elseif ($start_msg == $end_msg) {
623 /* if there's only one message in the box, handle it differently. */
635 } while (isset ($key) && ($k < $i));
636 printMessageInfo($imapConnection, $t, $i, $key, $mailbox,
637 $real_startMessage, $where, $what);
646 } while (isset ($key) && ($k < $i));
648 printMessageInfo($imapConnection, $t, $i, $key, $mailbox,
649 $real_startMessage, $where, $what);
654 } while ($i && $i < $endVar);
660 * Displays the standard message list header. To finish the table,
661 * you need to do a "</table></table>";
663 * $moveURL is the URL to submit the delete/move form to
664 * $mailbox is the current mailbox
665 * $sort is the current sorting method (-1 for no sorting available [searches])
666 * $Message is a message that is centered on top of the list
667 * $More is a second line that is left aligned
670 function mail_message_listing_beginning ($imapConnection,
671 $mailbox = '', $sort = -1,
673 $paginator = ' ',
675 global $color, $auto_expunge, $base_uri, $thread_sort_messages,
676 $allow_thread_sort, $allow_server_sort, $server_sort_order,
679 $php_self = $PHP_SELF;
680 /* fix for incorrect $PHP_SELF */
681 if (strpos($php_self, 'move_messages.php')) {
682 $php_self = str_replace('move_messages.php', 'right_main.php', $php_self);
684 $urlMailbox = urlencode($mailbox);
686 if (preg_match('/^(.+)\?.+$/',$php_self,$regs)) {
687 $source_url = $regs[1];
689 $source_url = $php_self;
695 $moveURL = "move_messages.php?msg=$msg&mailbox=$urlMailbox"
696 . "&startMessage=$start_msg";
698 * This is the beginning of the message list table.
699 * It wraps around all messages
702 echo "<FORM name=\"messageList\" method=post action=\"$moveURL\">\n"
703 . html_tag( 'table' ,'' , '', '', 'border="0" width="100%" cellpadding="1" cellspacing="0"' ) .
708 html_tag( 'td', $paginator, 'left' ) .
709 html_tag( 'td', $msg_cnt_str, 'right' )
711 , '', $color[4], 'border="0" width="100%" cellpadding="2" cellspacing="0"' )
714 . html_tag( 'tr' ) . "\n"
715 . html_tag( 'td' ,'' , 'left', $color[0], '' )
716 . html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="0" cellspacing="0"' )
718 getSmallStringCell(' ' . _("Move Selected To"), 'left') .
719 getSmallStringCell(_("Transform Selected Messages"), 'right')
721 . html_tag( 'tr' ) ."\n"
722 . html_tag( 'td', '', 'left', '', 'valign="middle" nowrap' );
723 getMbxList($imapConnection);
724 echo getButton('SUBMIT', 'moveButton',_("Move")) . "\n";
725 echo getButton('SUBMIT', 'attache',_("Forward")) . "\n";
728 . html_tag( 'td', '', 'right', '', 'nowrap' );
730 if (!$auto_expunge) {
731 echo getButton('SUBMIT', 'expungeButton',_("Expunge"))
732 .' ' . _("mailbox") . "\n";
735 echo getButton('SUBMIT', 'markRead',_("Read"));
736 echo getButton('SUBMIT', 'markUnread',_("Unread"));
737 echo getButton('SUBMIT', 'delete',_("Delete")) ." \n";
738 if (!strpos($php_self,'mailbox')) {
739 $location = $php_self.'?mailbox=INBOX&startMessage=1';
741 $location = $php_self;
743 echo '<INPUT TYPE="HIDDEN" NAME="location" VALUE="'.$location.'">';
747 /* draws thread sorting links */
748 if ($allow_thread_sort == TRUE) {
749 if ($thread_sort_messages == 1 ) {
751 $thread_name = _("Unthread View");
753 elseif ($thread_sort_messages == 0) {
755 $thread_name = _("Thread View");
757 echo html_tag( 'tr' ,
759 ' <a href=' . $source_url . '?sort='
760 . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
761 . '&mailbox=' . urlencode($mailbox) . '><small>' . $thread_name
762 . '</a></small> '
771 do_hook('mailbox_form_before');
775 . html_tag( 'td' ,'' , '', $color[0], '' );
777 /* if using server sort we highjack the
778 * the $sort var and use $server_sort_order
779 * instead. but here we reset sort for a bit
782 if ($allow_server_sort == TRUE) {
783 $sort = $server_sort_order;
787 function mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color) {
789 echo html_tag( 'table',
794 html_tag( 'td', $paginator_str ) .
795 html_tag( 'td', $msg_cnt_str, 'right' )
797 , '', $color[4], 'width="100%" cellpadding="1" cellspacing="1"' )
800 , '', $color[9], 'width="100%" cellpadding="1" cellspacing="1"' );
803 /* End of message-list table */
805 do_hook('mailbox_index_after');
810 function printHeader($mailbox, $sort, $color, $showsort=true) {
812 echo html_tag( 'table' ,'' , '', $color[4], 'border="0" width="100%" cellpadding="1" cellspacing="0"' );
813 echo html_tag( 'tr' ,'' , 'center', $color[5] );
814 for ($i=1; $i <= count($index_order); $i++
) {
815 switch ($index_order[$i]) {
816 case 1: /* checkbox */
818 echo html_tag( 'td' ,' ' , '', '', 'width="1%"' );
821 if (handleAsSent($mailbox)) {
822 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
823 . '<b>' . _("To") . '</b>';
825 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
826 . '<b>' . _("From") . '</b>';
829 ShowSortButton($sort, $mailbox, 2, 3);
834 echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
835 . '<b>' . _("Date") . '</b>';
837 ShowSortButton($sort, $mailbox, 0, 1);
841 case 4: /* subject */
842 echo html_tag( 'td' ,'' , 'left', '', '' )
843 . '<b>' . _("Subject") . '</b>';
845 ShowSortButton($sort, $mailbox, 4, 5);
850 echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%"' );
859 * This function shows the sort button. Isn't this a good comment?
861 function ShowSortButton($sort, $mailbox, $Up, $Down ) {
863 /* Figure out which image we want to use. */
864 if ($sort != $Up && $sort != $Down) {
865 $img = 'sort_none.png';
867 } elseif ($sort == $Up) {
868 $img = 'up_pointer.png';
871 $img = 'down_pointer.png';
875 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
876 $source_url = $regs[1];
878 $source_url = $PHP_SELF;
881 /* Now that we have everything figured out, show the actual button. */
882 echo ' <a href="' . $source_url .'?newsort=' . $which
883 . '&startMessage=1&mailbox=' . urlencode($mailbox)
884 . '"><IMG SRC="../images/' . $img
885 . '" BORDER=0 WIDTH=12 HEIGHT=10 ALT="sort"></a>';
888 function get_selectall_link($start_msg, $sort) {
889 global $checkall, $what, $where, $mailbox, $javascript_on;
890 global $PHP_SELF, $PG_SHOWNUM;
893 if ($javascript_on) {
895 '<script language="JavaScript" type="text/javascript">'
897 . "function CheckAll() {\n"
898 . " for (var i = 0; i < document.messageList.elements.length; i++) {\n"
899 . " if(document.messageList.elements[i].type == 'checkbox'){\n"
900 . " document.messageList.elements[i].checked = "
901 . " !(document.messageList.elements[i].checked);\n"
906 . '</script><a href="#" onClick="CheckAll();">' . _("Toggle All")
909 if (strpos($PHP_SELF, "?")) {
910 $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($mailbox)
911 . "&startMessage=$start_msg&sort=$sort&checkall=";
913 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
914 . "&startMessage=$start_msg&sort=$sort&checkall=";
916 if (isset($checkall) && $checkall == '1') {
922 if (isset($where) && isset($what)) {
923 $result .= '&where=' . urlencode($where)
924 . '&what=' . urlencode($what);
929 if (isset($checkall) && ($checkall == '1')) {
930 $result .= _("Unselect All");
932 $result .= _("Select All");
938 /* Return our final result. */
943 * This function computes the "Viewing Messages..." string.
945 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
946 /* Compute the $msg_cnt_str. */
948 if ($start_msg < $end_msg) {
949 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"),
950 $start_msg, $end_msg, $num_msgs);
951 } else if ($start_msg == $end_msg) {
952 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
956 /* Return our result string. */
961 * Generate a paginator link.
963 function get_paginator_link($box, $start_msg, $use, $text) {
966 $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
967 . "&startMessage=$start_msg&mailbox=$box\" "
968 . "TARGET=\"right\">$text</A>";
971 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
972 $source_url = $regs[1];
974 $source_url = $PHP_SELF;
977 $result = '<A HREF="'. $source_url . "?use_mailbox_cache=$use"
978 . "&startMessage=$start_msg&mailbox=$box\" "
979 . "TARGET=\"right\">$text</A>";
985 * This function computes the paginator string.
987 function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
989 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
991 /* Initialize paginator string chunks. */
998 $box = urlencode($box);
1000 /* Create simple strings that will be creating the paginator. */
1001 $spc = ' '; /* This will be used as a space. */
1002 $sep = '|'; /* This will be used as a seperator. */
1004 /* Get some paginator preference values. */
1005 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON
);
1006 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
);
1008 /* Make sure that our start message number is not too big. */
1009 $start_msg = min($start_msg, $num_msgs);
1011 /* Decide whether or not we will use the mailbox cache. */
1012 /* Not sure why $use_mailbox_cache is even passed in. */
1019 /* Compute the starting message of the previous and next page group. */
1020 $next_grp = $start_msg +
$show_num;
1021 $prev_grp = $start_msg - $show_num;
1023 /* Compute the basic previous and next strings. */
1024 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
1025 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1026 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1027 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
1028 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1029 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
1030 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
1031 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
1032 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1035 /* Page selector block. Following code computes page links. */
1036 if ($pg_sel && ($num_msgs > $show_num)) {
1037 /* Most importantly, what is the current page!!! */
1038 $cur_pg = intval($start_msg / $show_num) +
1;
1040 /* Compute total # of pages and # of paginator page links. */
1041 $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
1042 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
1044 /* Compute the size of the four quarters of the page links. */
1046 /* If we can, just show all the pages. */
1047 if (($tot_pgs - 1) <= $pg_max) {
1048 $q1_pgs = $cur_pg - 1;
1049 $q2_pgs = $q3_pgs = 0;
1050 $q4_pgs = $tot_pgs - $cur_pg;
1052 /* Otherwise, compute some magic to choose the four quarters. */
1055 * Compute the magic base values. Added together,
1056 * these values will always equal to the $pag_pgs.
1057 * NOTE: These are DEFAULT values and do not take
1058 * the current page into account. That is below.
1060 $q1_pgs = floor($vis_pgs/4);
1061 $q2_pgs = round($vis_pgs/4, 0);
1062 $q3_pgs = ceil($vis_pgs/4);
1063 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
1065 /* Adjust if the first quarter contains the current page. */
1066 if (($cur_pg - $q1_pgs) < 1) {
1067 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) +
$q2_pgs;
1068 $q1_pgs = $cur_pg - 1;
1070 $q3_pgs +
= ceil($extra_pgs / 2);
1071 $q4_pgs +
= floor($extra_pgs / 2);
1073 /* Adjust if the first and second quarters intersect. */
1074 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
1075 $extra_pgs = $q2_pgs;
1076 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1077 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1078 $q3_pgs +
= ceil($extra_pgs / 2);
1079 $q4_pgs +
= floor($extra_pgs / 2);
1081 /* Adjust if the fourth quarter contains the current page. */
1082 } else if (($cur_pg +
$q4_pgs) >= $tot_pgs) {
1083 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) +
$q3_pgs;
1085 $q4_pgs = $tot_pgs - $cur_pg;
1086 $q1_pgs +
= floor($extra_pgs / 2);
1087 $q2_pgs +
= ceil($extra_pgs / 2);
1089 /* Adjust if the third and fourth quarter intersect. */
1090 } else if (($cur_pg +
$q3_pgs +
1) >= ($tot_pgs - $q4_pgs +
1)) {
1091 $extra_pgs = $q3_pgs;
1092 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1093 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1094 $q1_pgs +
= floor($extra_pgs / 2);
1095 $q2_pgs +
= ceil($extra_pgs / 2);
1100 * I am leaving this debug code here, commented out, because
1101 * it is a really nice way to see what the above code is doing.
1102 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
1103 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
1106 /* Print out the page links from the compute page quarters. */
1108 /* Start with the first quarter. */
1109 if (($q1_pgs == 0) && ($cur_pg > 1)) {
1110 $pg_str .= "...$spc";
1112 for ($pg = 1; $pg <= $q1_pgs; ++
$pg) {
1113 $start = (($pg-1) * $show_num) +
1;
1114 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1116 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
1117 $pg_str .= "...$spc";
1121 /* Continue with the second quarter. */
1122 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++
$pg) {
1123 $start = (($pg-1) * $show_num) +
1;
1124 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1127 /* Now print the current page. */
1128 $pg_str .= $cur_pg . $spc;
1130 /* Next comes the third quarter. */
1131 for ($pg = $cur_pg +
1; $pg <= $cur_pg +
$q3_pgs; ++
$pg) {
1132 $start = (($pg-1) * $show_num) +
1;
1133 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1136 /* And last, print the forth quarter page links. */
1137 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
1138 $pg_str .= "...$spc";
1140 if (($tot_pgs - $q4_pgs) > ($cur_pg +
$q3_pgs)) {
1141 $pg_str .= "...$spc";
1143 for ($pg = $tot_pgs - $q4_pgs +
1; $pg <= $tot_pgs; ++
$pg) {
1144 $start = (($pg-1) * $show_num) +
1;
1145 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1148 } else if ($PG_SHOWNUM == 999999) {
1149 $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
1150 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1151 . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc;
1154 /* If necessary, compute the 'show all' string. */
1155 if (($prv_str != '') ||
($nxt_str != '')) {
1156 $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
1157 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
1158 . "TARGET=\"right\">" . _("Show All") . '</A>';
1161 /* Last but not least, get the value for the toggle all link. */
1162 $tgl_str = get_selectall_link($start_msg, $sort);
1164 /* Put all the pieces of the paginator string together. */
1166 * Hairy code... But let's leave it like it is since I am not certain
1167 * a different approach would be any easier to read. ;)
1170 $result .= ($prv_str != '' ?
$prv_str . $spc . $sep . $spc : '');
1171 $result .= ($nxt_str != '' ?
$nxt_str . $spc . $sep . $spc : '');
1172 $result .= ($pg_str != '' ?
$pg_str : '');
1173 $result .= ($all_str != '' ?
$sep . $spc . $all_str . $spc : '');
1174 $result .= ($result != '' ?
$sep . $spc . $tgl_str: $tgl_str);
1176 /* If the resulting string is blank, return a non-breaking space. */
1177 if ($result == '') {
1181 /* Return our final magical paginator string. */
1185 function processSubject($subject) {
1186 global $languages, $squirrelmail_language;
1187 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1189 return _("(no subject)");
1191 if (strlen($subject) <= 55)
1194 $ent_strlen=strlen($subject);
1198 * see if this is entities-encoded string
1199 * If so, Iterate through the whole string, find out
1200 * the real number of characters, and if more
1201 * than 55, substr with an updated trim value.
1203 while ( (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1204 (($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false) ) {
1205 $trim_val +
= ($ent_loc_end-$ent_loc)+
1;
1206 $ent_strlen -= $ent_loc_end-$ent_loc;
1207 $ent_offset = $ent_loc_end+
1;
1210 if ($ent_strlen <= 55){
1214 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
1215 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
1216 return $languages[$squirrelmail_language]['XTRA_CODE']('strimwidth', $subject, $trim_val);
1219 return substr($subject, 0, $trim_val) . '...';
1222 function getMbxList($imapConnection) {
1223 global $lastTargetMailbox;
1224 echo ' <small> <tt><select name="targetMailbox">';
1225 $boxes = sqimap_mailbox_list($imapConnection);
1226 foreach ($boxes as $boxes_part) {
1227 if (!in_array('noselect', $boxes_part['flags'])) {
1228 $box = $boxes_part['unformatted'];
1229 $box2 = str_replace(' ', ' ', imap_utf7_decode_local($boxes_part['unformatted-disp']));
1230 if( $box2 == 'INBOX' ) {
1233 if ($lastTargetMailbox == $box) {
1234 echo " <OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
1237 echo " <OPTION VALUE=\"$box\">$box2</OPTION>\n";
1241 echo ' </SELECT></TT> ';
1244 function getButton($type, $name, $value) {
1245 return '<INPUT TYPE="'.$type.'" NAME="'.$name.'" VALUE="'.$value . '">';
1248 function getSmallStringCell($string, $align) {
1249 return html_tag( 'td',
1250 '<small>' . $string . ': </small>',
1256 function getEndMessage($start_msg, $show_num, $num_msgs) {
1257 if ($start_msg +
($show_num - 1) < $num_msgs){
1258 $end_msg = $start_msg +
($show_num - 1);
1260 $end_msg = $num_msgs;
1263 if ($end_msg < $start_msg) {
1264 $start_msg = $start_msg - $show_num;
1265 if ($start_msg < 1) {
1269 return (array($start_msg,$end_msg));
1272 function handleAsSent($mailbox) {
1273 global $sent_folder, $draft_folder, $handleAsSent_result;
1275 /* First check if this is the sent or draft folder. */
1276 $handleAsSent_result = (($mailbox == $sent_folder)
1277 ||
($mailbox == $draft_folder));
1279 /* Then check the result of the handleAsSent hook. */
1280 do_hook('check_handleAsSent_result', $mailbox);
1282 /* And return the result. */
1283 return ($handleAsSent_result);