Source for file mailbox_display.php

Documentation is available at mailbox_display.php

  1. <?php
  2.  
  3. /**
  4.  * mailbox_display.php
  5.  *
  6.  * This contains functions that display mailbox information, such as the
  7.  * table row that has sender, date, subject, etc...
  8.  *
  9.  * @copyright &copy; 1999-2006 The SquirrelMail Project Team
  10.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  11.  * @version $Id: mailbox_display.php,v 1.321.2.36 2006/09/30 06:50:27 tokul Exp $
  12.  * @package squirrelmail
  13.  */
  14.  
  15. /** The standard includes.. */
  16. require_once(SM_PATH . 'functions/strings.php');
  17. require_once(SM_PATH . 'functions/html.php');
  18. require_once(SM_PATH . 'class/html.class.php');
  19. require_once(SM_PATH . 'functions/imap_mailbox.php');
  20.  
  21. /* Constants:
  22.  *   PG_SEL_MAX:   default value for page_selector_max
  23.  *   SUBJ_TRIM_AT: the length at which we trim off subjects
  24.  */
  25. define('PG_SEL_MAX', 10);
  26. define('SUBJ_TRIM_AT', 55);
  27.  
  28. function elapsed($start)
  29. {
  30.    $end = microtime();
  31.    list($start2, $start1) = explode(" ", $start);
  32.    list($end2, $end1) = explode(" ", $end);
  33.    $diff1 = $end1 - $start1;
  34.    $diff2 = $end2 - $start2;
  35.    if( $diff2 < 0 ){
  36.        $diff1 -= 1;
  37.        $diff2 += 1.0;
  38.    }
  39.    return $diff2 + $diff1;
  40. }
  41.  
  42. function printMessageInfo($imapConnection, $t, $not_last=true, $key, $mailbox,
  43.                           $start_msg, $where, $what) {
  44.     global $checkall,
  45.            $color, $msgs, $msort, $td_str, $msg,
  46.            $default_use_priority,
  47.            $message_highlight_list,
  48.            $index_order,
  49.            $indent_array,   
  50.            
  51.            $pos,            
  52.            
  53.            $thread_sort_messages, 
  54.            
  55.            $server_sort_order, 
  56.            
  57.            $row_count,
  58.            $allow_server_sort, 
  59.            
  60.            $truncate_subject,
  61.            $truncate_sender;
  62.  
  63.     $color_string = $color[4];
  64.  
  65.     if ($GLOBALS['alt_index_colors']) {
  66.         if (!isset($row_count)) {
  67.             $row_count = 0;
  68.         }
  69.         $row_count++;
  70.         if ($row_count % 2) {
  71.             if (!isset($color[12])) {
  72.                 $color[12] = '#EAEAEA';
  73.             }
  74.             $color_string = $color[12];
  75.         }
  76.     }
  77.     $msg = $msgs[$key];
  78.  
  79.     if($mailbox == 'None') {
  80.         $boxes   = sqimap_mailbox_list($imapConnection);
  81.         $mailbox = $boxes[0]['unformatted'];
  82.         unset($boxes);
  83.     }
  84.     $urlMailbox = urlencode($mailbox);
  85.  
  86.     if (handleAsSent($mailbox)) {
  87.        $msg['FROM'] = $msg['TO'];
  88.     }
  89.     $msg['FROM'] = parseAddress($msg['FROM'],1);
  90.  
  91.  
  92.        /*
  93.         * This is done in case you're looking into Sent folders,
  94.         * because you can have multiple receivers.
  95.         */
  96.  
  97.     $senderNames = $msg['FROM'];
  98.     $senderName  = '';
  99.     $senderFrom = '';
  100.  
  101.  
  102.     if (sizeof($senderNames)){
  103.         foreach ($senderNames as $senderNames_part) {
  104.             if ($senderName != '') {
  105.                 $senderName .= ', ';
  106.             }
  107.  
  108.             if ($senderFrom != '') {
  109.                 $senderFrom .= ', ';
  110.             }
  111.  
  112.             if ($senderNames_part[1]) {
  113.                 $senderName .= decodeHeader($senderNames_part[1]);
  114.             } else {
  115.                 $senderName .= htmlspecialchars($senderNames_part[0]);
  116.             }
  117.  
  118.             $senderFrom .= htmlspecialchars($senderNames_part[0]);
  119.         }
  120.     }
  121.     $senderName = str_replace('&nbsp;',' ',$senderName);
  122.     echo html_tag( 'tr','','','','valign="top"') . "\n";
  123.  
  124.     if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
  125.         $flag = "<font color=\"$color[2]\">";
  126.         $flag_end = '</font>';
  127.     } else {
  128.         $flag = '';
  129.         $flag_end = '';
  130.     }
  131.     if (!isset($msg['FLAG_SEEN']) || ($msg['FLAG_SEEN'] == false)) {
  132.         $bold = '<b>';
  133.         $bold_end = '</b>';
  134.     } else {
  135.         $bold = '';
  136.         $bold_end = '';
  137.     }
  138.     if (handleAsSent($mailbox)) {
  139.         $italic = '<i>';
  140.         $italic_end = '</i>';
  141.     } else {
  142.         $italic = '';
  143.         $italic_end = '';
  144.     }
  145.     if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
  146.         $fontstr = "<font color=\"$color[9]\">";
  147.         $fontstr_end = '</font>';
  148.     } else {
  149.         $fontstr = '';
  150.         $fontstr_end = '';
  151.     }
  152.  
  153.     if ($where && $what) {
  154.         $searchstr = '&amp;where='.$where.'&amp;what='.$what;
  155.     } else {
  156.         $searchstr = '';
  157.     }
  158.  
  159.     if (is_array($message_highlight_list) && count($message_highlight_list)) {
  160.         $msg['TO'] = parseAddress($msg['TO']);
  161.         $msg['CC'] = parseAddress($msg['CC']);
  162.         foreach ($message_highlight_list as $message_highlight_list_part) {
  163.             if (trim($message_highlight_list_part['value']) != '') {
  164.                 $high_val   = strtolower($message_highlight_list_part['value']);
  165.                 $match_type = strtoupper($message_highlight_list_part['match_type']);
  166.                 if($match_type == 'TO_CC') {
  167.                     $match = array('TO', 'CC');
  168.                 } else {
  169.                     $match = array($match_type);
  170.                 }
  171.                 foreach($match as $match_type) {
  172.                     switch($match_type) {
  173.                         case('TO'):
  174.                         case('CC'):
  175.                         case('FROM'):
  176.                             foreach ($msg[$match_type] as $address) {
  177.                                 $address[0] = decodeHeader($address[0], true, false);
  178.                                 $address[1] = decodeHeader($address[1], true, false);
  179.                                 if (strstr('^^' . strtolower($address[0]), $high_val) ||
  180.                                     strstr('^^' . strtolower($address[1]), $high_val)) {
  181.                                     $hlt_color = $message_highlight_list_part['color'];
  182.                                     break 4;
  183.                                 }
  184.                             }
  185.                             break;
  186.                         default:
  187.                             $headertest = strtolower(decodeHeader($msg[$match_type], true, false));
  188.                             if (strstr('^^' . $headertest, $high_val)) {
  189.                                 $hlt_color = $message_highlight_list_part['color'];
  190.                                 break 3;
  191.                             }
  192.                             break;
  193.                     }
  194.                 }
  195.             }
  196.         }
  197.     }
  198.  
  199.     if (!isset($hlt_color)) {
  200.         $hlt_color = $color_string;
  201.     }
  202.     $checked = ($checkall == 1) ? ' CHECKED' : '';
  203.     $col = 0;
  204.     $msg['SUBJECT'] = decodeHeader($msg['SUBJECT']);
  205. //    $subject = processSubject($msg['SUBJECT'], $indent_array[$msg['ID']]);
  206.     $subject = truncateWithEntities(str_replace('&nbsp;',' ',$msg['SUBJECT']), $truncate_subject);
  207.     if (sizeof($index_order)) {
  208.         foreach ($index_order as $index_order_part) {
  209.             switch ($index_order_part) {
  210.             case 1: /* checkbox */
  211.                 echo html_tag( 'td',
  212.                                "<input type=checkbox name=\"msg[$t]\" value=\"".$msg['ID']."\"$checked>",
  213.                                'center',
  214.                                $hlt_color );
  215.                 break;
  216.             case 2: /* from */
  217.                 $from_xtra = '';
  218.                 $from_xtra = 'title="' . $senderFrom . '"';
  219.                 echo html_tag( 'td',
  220.                                $italic . $bold . $flag . $fontstr . truncateWithEntities($senderName, $truncate_sender) .
  221.                                $fontstr_end . $flag_end . $bold_end . $italic_end,
  222.                                'left',
  223.                                $hlt_color, $from_xtra );
  224.                 break;
  225.             case 3: /* date */
  226.                 $date_string = $msg['DATE_STRING'] . '';
  227.                 if ($date_string == '') {
  228.                     $date_string = _("Unknown date");
  229.                 }
  230.                 echo html_tag( 'td',
  231.                                $bold . $flag . $fontstr . $date_string .
  232.                                $fontstr_end . $flag_end . $bold_end,
  233.                                'center',
  234.                                $hlt_color,
  235.                                'nowrap' );
  236.                 break;
  237.             case 4: /* subject */
  238.                 $td_str = $bold;
  239.                 if ($thread_sort_messages == 1) {
  240.                     if (isset($indent_array[$msg['ID']])) {
  241.                         $td_str .= str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;",$indent_array[$msg['ID']]);
  242.                     }
  243.                 }
  244.                 $td_str .= '<a href="read_body.php?mailbox='.$urlMailbox
  245.                         .  '&amp;passed_id='. $msg["ID"]
  246.                         .  '&amp;startMessage='.$start_msg.$searchstr.'"';
  247.                 $td_str .= ' ' .concat_hook_function('subject_link', array($start_msg, $searchstr));
  248.                 if ($subject != $msg['SUBJECT']) {
  249.                     $title = get_html_translation_table(HTML_SPECIALCHARS);
  250.                     $title = array_flip($title);
  251.                     $title = strtr($msg['SUBJECT'], $title);
  252.                     $title = str_replace('"', "''", $title);
  253.                     $td_str .= " title=\"$title\"";
  254.                 }
  255.                 $td_str .= ">$flag$subject$flag_end</a>$bold_end";
  256.                 echo html_tag( 'td', $td_str, 'left', $hlt_color );
  257.                 break;
  258.             case 5: /* flags */
  259.                 $stuff = false;
  260.                 $td_str = "<b><small>";
  261.  
  262.                 if (isset($msg['FLAG_ANSWERED']) && $msg['FLAG_ANSWERED'] == true) {
  263.                     $td_str .= _("A");
  264.                     $stuff = true;
  265.                 }
  266.                 if ($msg['TYPE0'] == 'multipart') {
  267.                     $td_str .= '+';
  268.                     $stuff = true;
  269.                 }
  270.                 if ($default_use_priority) {
  271.                     if ( ($msg['PRIORITY'] == 1) || ($msg['PRIORITY'] == 2) ) {
  272.                         $td_str .= "<font color=\"$color[1]\">!</font>";
  273.                         $stuff = true;
  274.                     }
  275.                     if ($msg['PRIORITY'] == 5) {
  276.                         $td_str .= "<font color=\"$color[8]\">?</font>";
  277.                         $stuff = true;
  278.                     }
  279.                 }
  280.                 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'] == true) {
  281.                     $td_str .= "<font color=\"$color[1]\">D</font>";
  282.                     $stuff = true;
  283.                 }
  284.                 if (!$stuff) {
  285.                     $td_str .= '&nbsp;';
  286.                 }
  287.                 do_hook("msg_envelope");
  288.                 $td_str .= '</small></b>';
  289.                 echo html_tag( 'td',
  290.                                $td_str,
  291.                                'center',
  292.                                $hlt_color,
  293.                                'nowrap' );
  294.                 break;
  295.             case 6: /* size */
  296.                 echo html_tag( 'td',
  297.                                $bold . $fontstr . show_readable_size($msg['SIZE']) .
  298.                                $fontstr_end . $bold_end,
  299.                                'right',
  300.                                $hlt_color );
  301.                 break;
  302.             }
  303.             ++$col;
  304.         }
  305.     }
  306.     if ($not_last) {
  307.         echo '</tr>' . "\n" . '<tr><td colspan="' . $col . '" bgcolor="' .
  308.              $color[0] . '" height="1"></td></tr>' . "\n";
  309.     } else {
  310.         echo '</tr>'."\n";
  311.     }
  312. }
  313.  
  314. function getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id) {
  315.     if ($id != 'no') {
  316.         $id = array_slice($id, ($start_msg-1), $show_num);
  317.         $end = $start_msg + $show_num - 1;
  318.         if ($num_msgs < $show_num) {
  319.             $end_loop = $num_msgs;
  320.         } else if ($end > $num_msgs) {
  321.             $end_loop = $num_msgs - $start_msg + 1;
  322.         } else {
  323.             $end_loop = $show_num;
  324.         }
  325.         return fillMessageArray($imapConnection,$id,$end_loop,$show_num);
  326.     } else {
  327.         return false;
  328.     }
  329. }
  330.  
  331. function getThreadMessages($imapConnection, $start_msg, $show_num, $num_msgs) {
  332.     $id = get_thread_sort($imapConnection);
  333.     return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
  334. }
  335.  
  336. function getServerSortMessages($imapConnection, $start_msg, $show_num,
  337.                                $num_msgs, $server_sort_order, $mbxresponse) {
  338.     $id = sqimap_get_sort_order($imapConnection, $server_sort_order,$mbxresponse);
  339.     return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
  340. }
  341.  
  342. function getSelfSortMessages($imapConnection, $start_msg, $show_num,
  343.                               $num_msgs, $sort, $mbxresponse) {
  344.     $msgs = array();
  345.     if ($num_msgs >= 1) {
  346.         $id = sqimap_get_php_sort_order ($imapConnection, $mbxresponse);
  347.         if ($sort < 6 ) {
  348.             $end = $num_msgs;
  349.             $end_loop = $end;
  350.             /* set shownum to 999999 to fool sqimap_get_small_header_list
  351.                and rebuild the msgs_str to 1:* */
  352.             $show_num = 999999;
  353.         } else {
  354.             /* if it's not sorted */
  355.             if ($start_msg + ($show_num - 1) < $num_msgs) {
  356.                 $end_msg = $start_msg + ($show_num - 1);
  357.             } else {
  358.                 $end_msg = $num_msgs;
  359.             }
  360.             if ($end_msg < $start_msg) {
  361.                 $start_msg = $start_msg - $show_num;
  362.                 if ($start_msg < 1) {
  363.                     $start_msg = 1;
  364.                 }
  365.             }
  366.             $id = array_slice(array_reverse($id), ($start_msg-1), $show_num);
  367.             $end = $start_msg + $show_num - 1;
  368.             if ($num_msgs < $show_num) {
  369.                 $end_loop = $num_msgs;
  370.             } else if ($end > $num_msgs) {
  371.                 $end_loop = $num_msgs - $start_msg + 1;
  372.             } else {
  373.                 $end_loop = $show_num;
  374.             }
  375.         }
  376.         $msgs = fillMessageArray($imapConnection,$id,$end_loop, $show_num);
  377.     }
  378.     return $msgs;
  379. }
  380.  
  381.  
  382.  
  383. /*
  384.  * This function loops through a group of messages in the mailbox
  385.  * and shows them to the user.
  386.  */
  387. function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
  388.                                 $start_msg, $sort, $color, $show_num,
  389.                                 $use_cache, $mode='') {
  390.     global $msgs, $msort, $auto_expunge, $thread_sort_messages,
  391.            $allow_server_sort, $server_sort_order;
  392.  
  393.     /*
  394.      * For some reason, on PHP 4.3+, this being unset, and set in the session causes havoc
  395.      * so setting it to an empty array beforehand seems to clean up the issue, and stopping the
  396.      * "Your script possibly relies on a session side-effect which existed until PHP 4.2.3" error
  397.      */
  398.  
  399.     if (!isset($msort)) {
  400.         $msort = array();
  401.     }
  402.  
  403.     if (!isset($msgs)) {
  404.         $msgs = array();
  405.     }
  406.  
  407.     //$start = microtime();
  408.     /* If autoexpunge is turned on, then do it now. */
  409.     $mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox);
  410.     $srt = $sort;
  411.     /* If autoexpunge is turned on, then do it now. */
  412.     if ($auto_expunge == true) {
  413.         $exp_cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, false, '');
  414.         $mbxresponse['EXISTS'] = $mbxresponse['EXISTS'] - $exp_cnt;
  415.         $num_msgs = $mbxresponse['EXISTS'];
  416.     }
  417.  
  418.     if ($mbxresponse['EXISTS'] > 0) {
  419.         /* if $start_msg is lower than $num_msgs, we probably deleted all messages
  420.          * in the last page. We need to re-adjust the start_msg
  421.          */
  422.  
  423.         if($start_msg > $num_msgs) {
  424.             $start_msg -= $show_num;
  425.             if($start_msg < 1) {
  426.                 $start_msg = 1;
  427.             }
  428.         }
  429.  
  430.         /* This code and the next if() block check for
  431.          * server-side sorting methods. The $id array is
  432.          * formatted and $sort is set to 6 to disable
  433.          * SM internal sorting
  434.          */
  435.  
  436.         if ($thread_sort_messages == 1) {
  437.             $mode = 'thread';
  438.         } elseif ($allow_server_sort == 1) {
  439.             $mode = 'serversort';
  440.         } else {
  441.             $mode = '';
  442.         }
  443.  
  444.         if ($use_cache) {
  445.             sqgetGlobalVar('msgs', $msgs, SQ_SESSION);
  446.             sqgetGlobalVar('msort', $msort, SQ_SESSION);
  447.         } else {
  448.             sqsession_unregister('msort');
  449.             sqsession_unregister('msgs');
  450.         }
  451.         switch ($mode) {
  452.             case 'thread':
  453.                 $id   = get_thread_sort($imapConnection);
  454.                 $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
  455.                 if ($msgs === false) {
  456.                     echo '<b><small><center><font color=red>' .
  457.                         _("Thread sorting is not supported by your IMAP server.") . '<br />' .
  458.                         _("Please contact your system administrator and report this error.") .
  459.                         '</center></small></b>';
  460.                     $thread_sort_messages = 0;
  461.                     $msort = $msgs = array();
  462.                 } else {
  463.                     $msort= $msgs;
  464.                     $sort = 6;
  465.                 }
  466.                 break;
  467.             case 'serversort':
  468.                 $id   = sqimap_get_sort_order($imapConnection, $sort, $mbxresponse);
  469.                 $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
  470.                 if ($msgs === false) {
  471.                     echo '<b><small><center><font color=red>' .
  472.                         _( "Server-side sorting is not supported by your IMAP server.") . '<br />' .
  473.                         _("Please contact your system administrator and report this error.") .
  474.                         '</center></small></b>';
  475.                     $sort = $server_sort_order;
  476.                     $allow_server_sort = FALSE;
  477.                     $msort = $msgs = array();
  478.                     $id = array();
  479.                 } else {
  480.                     $msort = $msgs;
  481.                     $sort = 6;
  482.                 }
  483.                 break;
  484.             default:
  485.                 if (!$use_cache) {
  486.                     $msgs = getSelfSortMessages($imapConnection, $start_msg, $show_num,
  487.                                                 $num_msgs, $sort, $mbxresponse);
  488.                     $msort = calc_msort($msgs, $sort);
  489.                 } /* !use cache */
  490.                 break;
  491.         } // switch
  492.         sqsession_register($msort, 'msort');
  493.         sqsession_register($msgs,  'msgs');
  494.  
  495.     } /* if exists > 0 */
  496.  
  497.     $res = getEndMessage($start_msg, $show_num, $num_msgs);
  498.     $start_msg = $res[0];
  499.     $end_msg   = $res[1];
  500.  
  501.     if ($num_msgs > 0) {
  502.         $paginator_str = get_paginator_str($mailbox, $start_msg, $end_msg,
  503.                                            $num_msgs, $show_num, $sort);
  504.     } else {
  505.         $paginator_str = '';
  506.     }
  507.  
  508.     $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
  509.  
  510.     do_hook('mailbox_index_before');
  511.     echo '<table border="0" width="100%" cellpadding="0" cellspacing="0">';
  512.     echo '<tr><td>';
  513.  
  514.     mail_message_listing_beginning($imapConnection, $mailbox, $sort,
  515.                                   $msg_cnt_str, $paginator_str, $start_msg);
  516.     echo '</td></tr>';
  517.     /* line between the button area and the list */
  518.     echo '<tr><td height="5" bgcolor="'.$color[4].'"></td></tr>';
  519.  
  520.     echo '<tr><td>';
  521.     echo '    <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
  522.     echo '     <tr><td>';
  523.     echo '       <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[5].'">';
  524.     echo '<tr><td>';
  525.     printHeader($mailbox, $srt, $color, !$thread_sort_messages);
  526.  
  527.     displayMessageArray($imapConnection, $num_msgs, $start_msg,
  528.                         $msort, $mailbox, $sort, $color, $show_num,0,0);
  529.     echo '</td></tr></table></td></tr></table>';
  530.  
  531.     mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color);
  532.     echo '</td></tr></table>';
  533.     //$t = elapsed($start);
  534.     //echo("elapsed time = $t seconds\n");
  535. }
  536.  
  537. function calc_msort($msgs, $sort) {
  538.  
  539.     /*
  540.      * 0 = Date (up)
  541.      * 1 = Date (dn)
  542.      * 2 = Name (up)
  543.      * 3 = Name (dn)
  544.      * 4 = Subject (up)
  545.      * 5 = Subject (dn)
  546.      */
  547.  
  548.     if (($sort == 0) || ($sort == 1)) {
  549.         foreach ($msgs as $item) {
  550.             $msort[] = $item['TIME_STAMP'];
  551.         }
  552.     } elseif (($sort == 2) || ($sort == 3)) {
  553.         foreach ($msgs as $item) {
  554.             $msort[] = $item['FROM-SORT'];
  555.         }
  556.     } elseif (($sort == 4) || ($sort == 5)) {
  557.         foreach ($msgs as $item) {
  558.             $msort[] = $item['SUBJECT-SORT'];
  559.         }
  560.     } else {
  561.         $msort = $msgs;
  562.     }
  563.     if ($sort < 6) {
  564.         if ($sort % 2) {
  565.             asort($msort);
  566.         } else {
  567.             arsort($msort);
  568.         }
  569.     }
  570.     return $msort;
  571. }
  572.  
  573. function fillMessageArray($imapConnection, $id, $count, $show_num=false) {
  574.     return sqimap_get_small_header_list($imapConnection, $id, $show_num);
  575. }
  576.  
  577.  
  578. /* Generic function to convert the msgs array into an HTML table. */
  579. function displayMessageArray($imapConnection, $num_msgs, $start_msg,
  580.                              $msort, $mailbox, $sort, $color,
  581.                              $show_num, $where=0, $what=0) {
  582.     global $imapServerAddress, $use_mailbox_cache, $index_order,
  583.            $indent_array, $thread_sort_messages, $allow_server_sort,
  584.            $server_sort_order, $PHP_SELF;
  585.  
  586.     $res = getEndMessage($start_msg, $show_num, $num_msgs);
  587.     $start_msg = $res[0];
  588.     $end_msg   = $res[1];
  589.  
  590.     $urlMailbox = urlencode($mailbox);
  591.  
  592.     /* get indent level for subject display */
  593.     if ($thread_sort_messages == 1 && $num_msgs) {
  594.         $indent_array = get_parent_level($imapConnection);
  595.     }
  596.  
  597.     $real_startMessage = $start_msg;
  598.     if ($sort == 6) {
  599.         if ($end_msg - $start_msg < $show_num - 1) {
  600.             $end_msg = $end_msg - $start_msg + 1;
  601.             $start_msg = 1;
  602.         } else if ($start_msg > $show_num) {
  603.             $end_msg = $show_num;
  604.             $start_msg = 1;
  605.         }
  606.     }
  607.     $endVar = $end_msg + 1;
  608.  
  609.     /*
  610.      * Loop through and display the info for each message.
  611.      * ($t is used for the checkbox number)
  612.      */
  613.     $t = 0;
  614.  
  615.     /* messages display */
  616.  
  617.     if (!$num_msgs) {
  618.     /* if there's no messages in this folder */
  619.         echo html_tag( 'tr',
  620.                 html_tag( 'td',
  621.                           "<br><b>" . _("THIS FOLDER IS EMPTY") . "</b><br>&nbsp;",
  622.                           'center',
  623.                           $color[4],
  624.                           'colspan="' . count($index_order) . '"'
  625.                 )
  626.         );
  627.     } elseif ($start_msg == $end_msg) {
  628.     /* if there's only one message in the box, handle it differently. */
  629.         if ($sort != 6) {
  630.             $i = $start_msg;
  631.         } else {
  632.             $i = 1;
  633.         }
  634.         reset($msort);
  635.         $k = 0;
  636.         do {
  637.             $key = key($msort);
  638.             next($msort);
  639.             $k++;
  640.         } while (isset ($key) && ($k < $i));
  641.         printMessageInfo($imapConnection, $t, true, $key, $mailbox,
  642.                          $real_startMessage, $where, $what);
  643.     } else {
  644.         $i = $start_msg;
  645.         reset($msort);
  646.         $k = 0;
  647.         do {
  648.             $key = key($msort);
  649.             next($msort);
  650.             $k++;
  651.         } while (isset ($key) && ($k < $i));
  652.         $not_last = true;
  653.         do {
  654.             if (!$i || $i == $endVar-1) $not_last = false;
  655.                 printMessageInfo($imapConnection, $t, $not_last, $key, $mailbox,
  656.                                  $real_startMessage, $where, $what);
  657.             $key = key($msort);
  658.             $t++;
  659.             $i++;
  660.             next($msort);
  661.         } while ($i && $i < $endVar);
  662.     }
  663. }
  664.  
  665. /*
  666.  * Displays the standard message list header. To finish the table,
  667.  * you need to do a "</table></table>";
  668.  *
  669.  * $moveURL is the URL to submit the delete/move form to
  670.  * $mailbox is the current mailbox
  671.  * $sort is the current sorting method (-1 for no sorting available [searches])
  672.  * $Message is a message that is centered on top of the list
  673.  * $More is a second line that is left aligned
  674.  */
  675.  
  676. function mail_message_listing_beginning ($imapConnection,
  677.                                          $mailbox = '', $sort = -1,
  678.                                          $msg_cnt_str = '',
  679.                                          $paginator = '&nbsp;',
  680.                                          $start_msg = 1) {
  681.     global $color, $auto_expunge, $base_uri, $thread_sort_messages,
  682.            $allow_thread_sort, $allow_server_sort, $server_sort_order,
  683.            $PHP_SELF;
  684.  
  685.     $php_self = $PHP_SELF;
  686.     /* fix for incorrect $PHP_SELF */
  687.     if (strpos($php_self, 'move_messages.php')) {
  688.         $php_self = str_replace('move_messages.php', 'right_main.php', $php_self);
  689.     }
  690.     $urlMailbox = urlencode($mailbox);
  691.  
  692.     if (preg_match('/^(.+)\?.+$/',$php_self,$regs)) {
  693.         $source_url = $regs[1];
  694.     } else {
  695.         $source_url = $php_self;
  696.     }
  697.  
  698.     if (!isset($msg)) {
  699.         $msg = '';
  700.     }
  701.     $moveFields = '<input type="hidden" name="msg" value="'.htmlspecialchars($msg).'">' . "\n" .
  702.         '<input type="hidden" name="mailbox" value="'.htmlspecialchars($mailbox).'">' . "\n" .
  703.         '<input type="hidden" name="startMessage" value="'.htmlspecialchars($start_msg).'">' . "\n";
  704.  
  705.     /*
  706.      * This is the beginning of the message list table.
  707.      * It wraps around all messages
  708.      */
  709.     $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $mailbox);
  710.     $form_name = "FormMsgs" . $safe_name;
  711.     echo '<form name="' . $form_name . '" method="post" action="move_messages.php">' ."\n"
  712.         . $moveFields . "\n";
  713.  
  714.     if (!empty($paginator) && !empty($msg_cnt_str)) {
  715.  
  716.         echo html_tag( 'table' ,
  717.             html_tag( 'tr',
  718.                 html_tag( 'td' ,
  719.                     html_tag( 'table' ,
  720.                         html_tag( 'tr',
  721.                             html_tag( 'td', $paginator, 'left' ) .
  722.                             html_tag( 'td', $msg_cnt_str, 'right' )
  723.                         )
  724.                     , '', $color[4], 'border="0" width="100%" cellpadding="1"  cellspacing="0"' )
  725.                 , 'left', '', '' )
  726.             , '', $color[0] )
  727.          , '', '', 'border="0" width="100%" cellpadding="1"  cellspacing="0"' );
  728.     }
  729.     /* line between header and button area */
  730.         echo '</td></tr><tr><td height="5" bgcolor="'.$color[4].'"></td></tr>';
  731.  
  732.         echo '<tr><td>';
  733.         echo html_tag( 'tr' ) . "\n"
  734.         . html_tag( 'td' ,'' , 'left', '', '' )
  735.          . html_tag( 'table' ,'' , '', $color[9], 'border="0" width="100%" cellpadding="1"  cellspacing="0"' )
  736.           . '<tr><td>'
  737.            . html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="1"  cellspacing="0"' )
  738.             . html_tag( 'tr',
  739.              getSmallStringCell(_("Move Selected To"), 'left', 'nowrap') .
  740.              getSmallStringCell(_("Transform Selected Messages"), 'right')
  741.             )
  742.             . html_tag( 'tr' ) ."\n"
  743.             . html_tag( 'td', '', 'left', '', 'valign="middle" nowrap' );
  744.             getMbxList($imapConnection);
  745.             echo getButton('SUBMIT', 'moveButton',_("Move")) . "\n";
  746.             echo getButton('SUBMIT', 'attache',_("Forward")) . "\n";
  747.  
  748.   echo "      </small></td>\n"
  749.          . html_tag( 'td', '', 'right', '', 'nowrap' );
  750.  
  751.  
  752.  
  753.     if (!$auto_expunge) {
  754.         echo getButton('SUBMIT', 'expungeButton',_("Expunge"))
  755.              ."&nbsp;\n";
  756.     }
  757.  
  758.     echo getButton('SUBMIT', 'markRead',_("Read"));
  759.     echo getButton('SUBMIT', 'markUnread',_("Unread"));
  760.     echo getButton('SUBMIT', 'delete',_("Delete")) ."&nbsp;\n";
  761.     if (!strpos($php_self,'mailbox')) {
  762.         $location = $php_self.'?mailbox=INBOX&amp;startMessage=1';
  763.     } else {
  764.         $location = $php_self;
  765.     }
  766.  
  767. //    $location = urlencode($location);
  768.  
  769.     echo '<input type="hidden" name="location" value="'.$location.'">';
  770.     echo "</td>\n"
  771.          . "   </tr>\n";
  772.  
  773.     /* draws thread sorting links */
  774.     if ($allow_thread_sort == TRUE) {
  775.         if ($thread_sort_messages == 1 ) {
  776.             $set_thread = 2;
  777.             $thread_name = _("Unthread View");
  778.         } elseif ($thread_sort_messages == 0) {
  779.             $set_thread = 1;
  780.             $thread_name = _("Thread View");
  781.         }
  782.         echo html_tag( 'tr' ,
  783.                     html_tag( 'td' ,
  784.                               '&nbsp;<small><a href="' . $source_url . '?sort='
  785.                               . "$sort" . '&amp;start_messages=1&amp;set_thread=' . "$set_thread"
  786.                               . '&amp;mailbox=' . urlencode($mailbox) . '">' . $thread_name
  787.                               . '</a></small>&nbsp;'
  788.                      , '', '', '' )
  789.                  , '', '', '' );
  790.     }
  791.  
  792.     echo "</table></td></tr></table></td></tr>\n";
  793.  
  794.     do_hook('mailbox_form_before');
  795.  
  796.     /* if using server sort we highjack the
  797.      * the $sort var and use $server_sort_order
  798.      * instead. but here we reset sort for a bit
  799.      * since its easy
  800.      */
  801.     if ($allow_server_sort == TRUE) {
  802.         $sort = $server_sort_order;
  803.     }
  804. }
  805.  
  806. function mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color) {
  807.   if ($num_msgs) {
  808.     /* space between list and footer */
  809.     echo '<tr><td height="5" bgcolor="'.$color[4].'" colspan="1">';
  810.  
  811.     echo '</td></tr><tr><td>';
  812.     echo html_tag( 'table',
  813.             html_tag( 'tr',
  814.                 html_tag( 'td',
  815.                     html_tag( 'table',
  816.                         html_tag( 'tr',
  817.                             html_tag( 'td', $paginator_str ) .
  818.                             html_tag( 'td', $msg_cnt_str, 'right' )
  819.                         )
  820.                     , '', $color[4], 'width="100%" border="0" cellpadding="1" cellspacing="0"' )
  821.                 )
  822.             )
  823.         , '', $color[9], 'width="100%" border="0" cellpadding="1"  cellspacing="0"' );
  824.     echo '</td></tr>';
  825.   }
  826.     /* End of message-list table */
  827.  
  828.     do_hook('mailbox_index_after');
  829.     echo "</form>\n";
  830. }
  831.  
  832. function printHeader($mailbox, $sort, $color, $showsort=true) {
  833.     global $index_order;
  834.     echo html_tag( 'tr' ,'' , 'center', $color[5] );
  835.  
  836.     /* calculate the width of the subject column based on the
  837.      * widths of the other columns */
  838.     $widths = array(1=>1,2=>25,3=>5,4=>0,5=>1,6=>5);
  839.     $subjectwidth = 100;
  840.     foreach($index_order as $item) {
  841.         $subjectwidth -= $widths[$item];
  842.     }
  843.  
  844.     foreach ($index_order as $item) {
  845.         switch ($item) {
  846.         case 1: /* checkbox */
  847.         case 5: /* flags */
  848.             echo html_tag( 'td' ,'&nbsp;' , '', '', 'width="1%"' );
  849.             break;
  850.         case 2: /* from */
  851.             if (handleAsSent($mailbox)) {
  852.                 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
  853.                      . '<b>' . _("To") . '</b>';
  854.             } else {
  855.                 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
  856.                      . '<b>' . _("From") . '</b>';
  857.             }
  858.             if ($showsort) {
  859.                 ShowSortButton($sort, $mailbox, 2, 3);
  860.             }
  861.             echo "</td>\n";
  862.             break;
  863.         case 3: /* date */
  864.             echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
  865.                  . '<b>' . _("Date") . '</b>';
  866.             if ($showsort) {
  867.                 ShowSortButton($sort, $mailbox, 0, 1);
  868.             }
  869.             echo "</td>\n";
  870.             break;
  871.         case 4: /* subject */
  872.             echo html_tag( 'td' ,'' , 'left', '', 'width="'.$subjectwidth.'%"' )
  873.                  . '<b>' . _("Subject") . '</b>';
  874.             if ($showsort) {
  875.                 ShowSortButton($sort, $mailbox, 4, 5);
  876.             }
  877.             echo "</td>\n";
  878.             break;
  879.         case 6: /* size */
  880.             echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%" nowrap' );
  881.             break;
  882.         }
  883.     }
  884.     echo "</tr>\n";
  885. }
  886.  
  887.  
  888. /*
  889.  * This function shows the sort button. Isn't this a good comment?
  890.  */
  891. function ShowSortButton($sort, $mailbox, $Up, $Down ) {
  892.     global $PHP_SELF;
  893.     /* Figure out which image we want to use. */
  894.     if ($sort != $Up && $sort != $Down) {
  895.         $img = 'sort_none.png';
  896.         $which = $Up;
  897.     } elseif ($sort == $Up) {
  898.         $img = 'up_pointer.png';
  899.         $which = $Down;
  900.     } else {
  901.         $img = 'down_pointer.png';
  902.         $which = 6;
  903.     }
  904.  
  905.     if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
  906.         $source_url = $regs[1];
  907.     } else {
  908.         $source_url = $PHP_SELF;
  909.     }
  910.  
  911.     /* Now that we have everything figured out, show the actual button. */
  912.     echo ' <a href="' . $source_url .'?newsort=' . $which
  913.          . '&amp;startMessage=1&amp;mailbox=' . urlencode($mailbox)
  914.          . '"><img src="../images/' . $img
  915.          . '" border="0" width="12" height="10" alt="sort"></a>';
  916. }
  917.  
  918. function get_selectall_link($start_msg, $sort) {
  919.     global $checkall, $what, $where, $mailbox, $javascript_on;
  920.     global $PHP_SELF, $PG_SHOWNUM;
  921.  
  922.     $result = '';
  923.     if ($javascript_on) {
  924.         $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $mailbox);
  925.         $func_name = "CheckAll" . $safe_name;
  926.         $form_name = "FormMsgs" . $safe_name;
  927.         $result = '<script language="JavaScript" type="text/javascript">'
  928.                 . "\n<!-- \n"
  929.                 . "function " . $func_name . "() {\n"
  930.                 . "  for (var i = 0; i < document." . $form_name . ".elements.length; i++) {\n"
  931.                 . "    if(document." . $form_name . ".elements[i].type == 'checkbox'){\n"
  932.                 . "      document." . $form_name . ".elements[i].checked = "
  933.                 . "        !(document." . $form_name . ".elements[i].checked);\n"
  934.                 . "    }\n"
  935.                 . "  }\n"
  936.                 . "}\n"
  937.                 . "//-->\n"
  938.                 . '</script><a href="javascript:void(0)" onClick="' . $func_name . '();">' . _("Toggle All")
  939. /*                . '</script><a href="javascript:' . $func_name . '()">' . _("Toggle All")*/
  940.                 . "</a>\n";
  941.     } else {
  942.         if (strpos($PHP_SELF, "?")) {
  943.             $result .= "<a href=\"$PHP_SELF&amp;mailbox=" . urlencode($mailbox)
  944.                     .  "&amp;startMessage=$start_msg&amp;sort=$sort&amp;checkall=";
  945.         } else {
  946.             $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
  947.                     .  "&amp;startMessage=$start_msg&amp;sort=$sort&amp;checkall=";
  948.         }
  949.         if (isset($checkall) && $checkall == '1') {
  950.             $result .= '0';
  951.         } else {
  952.             $result .= '1';
  953.         }
  954.  
  955.         if (isset($where) && isset($what)) {
  956.             $result .= '&amp;where=' . urlencode($where)
  957.                     .  '&amp;what=' . urlencode($what);
  958.         }
  959.         $result .= "\">";
  960.  
  961.         if (isset($checkall) && ($checkall == '1')) {
  962.             $result .= _("Unselect All");
  963.         } else {
  964.             $result .= _("Select All");
  965.         }
  966.         $result .= "</A>\n";
  967.     }
  968.  
  969.     /* Return our final result. */
  970.     return ($result);
  971. }
  972.  
  973. /*
  974.  * This function computes the "Viewing Messages..." string.
  975.  */
  976. function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
  977.     /* Compute the $msg_cnt_str. */
  978.     $result = '';
  979.     if ($start_msg < $end_msg) {
  980.         $result = sprintf(_("Viewing Messages: %s to %s (%s total)"),
  981.                   '<b>'.$start_msg.'</b>', '<b>'.$end_msg.'</b>', $num_msgs);
  982.     } else if ($start_msg == $end_msg) {
  983.         $result = sprintf(_("Viewing Message: %s (%s total)"), '<b>'.$start_msg.'</b>', $num_msgs);
  984.     } else {
  985.         $result = '<br>';
  986.     }
  987.     /* Return our result string. */
  988.     return ($result);
  989. }
  990.  
  991. /*
  992.  * Generate a paginator link.
  993.  */
  994. function get_paginator_link($box, $start_msg, $use, $text) {
  995.     global $PHP_SELF;
  996.  
  997.     $result = "<a href=\"right_main.php?use_mailbox_cache=$use"
  998.             . "&amp;startMessage=$start_msg&amp;mailbox=$box\" "
  999.             . ">$text</a>";
  1000.     return ($result);
  1001. /*
  1002.     if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
  1003.         $source_url = $regs[1];
  1004.     } else {
  1005.         $source_url = $PHP_SELF;
  1006.     }
  1007.  
  1008.     $result = '<A HREF="'. $source_url . "?use_mailbox_cache=$use"
  1009.             . "&amp;startMessage=$start_msg&amp;mailbox=$box\" "
  1010.             . ">$text</A>";
  1011.     return ($result);
  1012. */
  1013. }
  1014.  
  1015. /*
  1016.  * This function computes the paginator string.
  1017.  */
  1018. function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
  1019.                            $show_num, $sort) {
  1020.     global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
  1021.  
  1022.     /* Initialize paginator string chunks. */
  1023.     $prv_str = '';
  1024.     $nxt_str = '';
  1025.     $pg_str  = '';
  1026.     $all_str = '';
  1027.     $tgl_str = '';
  1028.  
  1029.     $box = urlencode($box);
  1030.  
  1031.     /* Create simple strings that will be creating the paginator. */
  1032.     $spc = '&nbsp;';     /* This will be used as a space. */
  1033.     $sep = '|';          /* This will be used as a seperator. */
  1034.  
  1035.     /* Get some paginator preference values. */
  1036.     $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON);
  1037.     $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX);
  1038.  
  1039.     /* Make sure that our start message number is not too big. */
  1040.     $start_msg = min($start_msg, $num_msgs);
  1041.  
  1042.     /* Decide whether or not we will use the mailbox cache. */
  1043.     /* Not sure why $use_mailbox_cache is even passed in.   */
  1044.     if ($sort == 6) {
  1045.         $use = 0;
  1046.     } else {
  1047.         $use = 1;
  1048.     }
  1049.  
  1050.     /* Compute the starting message of the previous and next page group. */
  1051.     $next_grp = $start_msg + $show_num;
  1052.     $prev_grp = $start_msg - $show_num;
  1053.  
  1054.     /* Compute the basic previous and next strings. */
  1055.     if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
  1056.         $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
  1057.         $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
  1058.     } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
  1059.         $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
  1060.         $nxt_str = "<font color=\"$color[9]\">"._("Next")."</font>\n";
  1061.     } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
  1062.         $prv_str = "<font color=\"$color[9]\">"._("Previous") . '</font>';
  1063.         $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
  1064.     }
  1065.  
  1066.     /* Page selector block. Following code computes page links. */
  1067.     if ($pg_sel && ($num_msgs > $show_num)) {
  1068.         /* Most importantly, what is the current page!!! */
  1069.         $cur_pg = intval($start_msg / $show_num) + 1;
  1070.  
  1071.         /* Compute total # of pages and # of paginator page links. */
  1072.         $tot_pgs = ceil($num_msgs / $show_num);  /* Total number of Pages */
  1073.         $vis_pgs = min($pg_max, $tot_pgs - 1);   /* Visible Pages    */
  1074.  
  1075.         /* Compute the size of the four quarters of the page links. */
  1076.  
  1077.         /* If we can, just show all the pages. */
  1078.         if (($tot_pgs - 1) <= $pg_max) {
  1079.             $q1_pgs = $cur_pg - 1;
  1080.             $q2_pgs = $q3_pgs = 0;
  1081.             $q4_pgs = $tot_pgs - $cur_pg;
  1082.  
  1083.         /* Otherwise, compute some magic to choose the four quarters. */
  1084.         } else {
  1085.             /*
  1086.              * Compute the magic base values. Added together,
  1087.              * these values will always equal to the $pag_pgs.
  1088.              * NOTE: These are DEFAULT values and do not take
  1089.              * the current page into account. That is below.
  1090.              */
  1091.             $q1_pgs = floor($vis_pgs/4);
  1092.             $q2_pgs = round($vis_pgs/4, 0);
  1093.             $q3_pgs = ceil($vis_pgs/4);
  1094.             $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
  1095.  
  1096.             /* Adjust if the first quarter contains the current page. */
  1097.             if (($cur_pg - $q1_pgs) < 1) {
  1098.                 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) + $q2_pgs;
  1099.                 $q1_pgs = $cur_pg - 1;
  1100.                 $q2_pgs = 0;
  1101.                 $q3_pgs += ceil($extra_pgs / 2);
  1102.                 $q4_pgs += floor($extra_pgs / 2);
  1103.  
  1104.             /* Adjust if the first and second quarters intersect. */
  1105.             } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
  1106.                 $extra_pgs = $q2_pgs;
  1107.                 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 3/4);
  1108.                 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 3/4);
  1109.                 $q3_pgs += ceil($extra_pgs / 2);
  1110.                 $q4_pgs += floor($extra_pgs / 2);
  1111.  
  1112.             /* Adjust if the fourth quarter contains the current page. */
  1113.             } else if (($cur_pg + $q4_pgs) >= $tot_pgs) {
  1114.                 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) + $q3_pgs;
  1115.                 $q3_pgs = 0;
  1116.                 $q4_pgs = $tot_pgs - $cur_pg;
  1117.                 $q1_pgs += floor($extra_pgs / 2);
  1118.                 $q2_pgs += ceil($extra_pgs / 2);
  1119.  
  1120.             /* Adjust if the third and fourth quarter intersect. */
  1121.             } else if (($cur_pg + $q3_pgs) >= ($tot_pgs - $q4_pgs)) {
  1122.                 $extra_pgs = $q3_pgs;
  1123.                 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 3/4);
  1124.                 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 3/4);
  1125.                 $q1_pgs += floor($extra_pgs / 2);
  1126.                 $q2_pgs += ceil($extra_pgs / 2);
  1127.             }
  1128.         }
  1129.  
  1130.         /*
  1131.          * I am leaving this debug code here, commented out, because
  1132.          * it is a really nice way to see what the above code is doing.
  1133.          */
  1134.          // echo "qts =  $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
  1135.          //     . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
  1136.  
  1137.  
  1138.         /* Print out the page links from the compute page quarters. */
  1139.  
  1140.         /* Start with the first quarter. */
  1141.         if (($q1_pgs == 0) && ($cur_pg > 1)) {
  1142.             $pg_str .= "...$spc";
  1143.         } else {
  1144.             for ($pg = 1; $pg <= $q1_pgs; ++$pg) {
  1145.                 $start = (($pg-1) * $show_num) + 1;
  1146.                 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
  1147.             }
  1148.             if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
  1149.                 $pg_str .= "...$spc";
  1150.             }
  1151.         }
  1152.  
  1153.         /* Continue with the second quarter. */
  1154.         for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++$pg) {
  1155.             $start = (($pg-1) * $show_num) + 1;
  1156.             $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
  1157.         }
  1158.  
  1159.         /* Now print the current page. */
  1160.         $pg_str .= $cur_pg . $spc;
  1161.  
  1162.         /* Next comes the third quarter. */
  1163.         for ($pg = $cur_pg + 1; $pg <= $cur_pg + $q3_pgs; ++$pg) {
  1164.             $start = (($pg-1) * $show_num) + 1;
  1165.             $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
  1166.         }
  1167.  
  1168.         /* And last, print the forth quarter page links. */
  1169.         if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
  1170.             $pg_str .= "...$spc";
  1171.         } else {
  1172.             if (($tot_pgs - $q4_pgs) > ($cur_pg + $q3_pgs)) {
  1173.                 $pg_str .= "...$spc";
  1174.             }
  1175.             for ($pg = $tot_pgs - $q4_pgs + 1; $pg <= $tot_pgs; ++$pg) {
  1176.                 $start = (($pg-1) * $show_num) + 1;
  1177.                 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
  1178.             }
  1179.         }
  1180.     } else if ($PG_SHOWNUM == 999999) {
  1181.         $pg_str = "<a href=\"right_main.php?PG_SHOWALL=0"
  1182.                 . "&amp;use_mailbox_cache=$use&amp;startMessage=1&amp;mailbox=$box\" "
  1183.                 . ">" ._("Paginate") . '</a>' . $spc;
  1184.     }
  1185.  
  1186.     /* If necessary, compute the 'show all' string. */
  1187.     if (($prv_str != '') || ($nxt_str != '')) {
  1188.         $all_str = "<a href=\"right_main.php?PG_SHOWALL=1"
  1189.                  . "&amp;use_mailbox_cache=$use&amp;startMessage=1&amp;mailbox=$box\" "
  1190.                  . ">" . _("Show All") . '</a>';
  1191.     }
  1192.  
  1193.     /* Last but not least, get the value for the toggle all link. */
  1194.     $tgl_str = get_selectall_link($start_msg, $sort);
  1195.  
  1196.     /* Put all the pieces of the paginator string together. */
  1197.     /**
  1198.      * Hairy code... But let's leave it like it is since I am not certain
  1199.      * a different approach would be any easier to read. ;)
  1200.      */
  1201.     $result = '';
  1202.     $result .= ($prv_str != '' ? $prv_str . $spc . $sep . $spc : '');
  1203.     $result .= ($nxt_str != '' ? $nxt_str . $spc . $sep . $spc : '');
  1204.     $result .= ($pg_str  != '' ? $pg_str : '');
  1205.     $result .= ($all_str != '' ? $sep . $spc . $all_str . $spc : '');
  1206.     $result .= ($result  != '' ? $sep . $spc . $tgl_str: $tgl_str);
  1207.  
  1208.     /* If the resulting string is blank, return a non-breaking space. */
  1209.     if ($result == '') {
  1210.         $result = '&nbsp;';
  1211.     }
  1212.  
  1213.     /* Return our final magical paginator string. */
  1214.     return ($result);
  1215. }
  1216.  
  1217. function processSubject($subject, $threadlevel = 0) {
  1218.     global $languages, $squirrelmail_language;
  1219.     /* Shouldn't ever happen -- caught too many times in the IMAP functions */
  1220.     if ($subject == '') {
  1221.         return _("(no subject)");
  1222.     }
  1223.  
  1224.     $trim_at = SUBJ_TRIM_AT;
  1225.  
  1226.     /* if this is threaded, subtract two chars per indentlevel */
  1227.     if($threadlevel > 0 && $threadlevel <= 10) {
  1228.         $trim_at -= (2*$threadlevel);
  1229.     }
  1230.  
  1231.     if (strlen($subject) <= $trim_at) {
  1232.         return $subject;
  1233.     }
  1234.  
  1235.     $ent_strlen = $orig_len = strlen($subject);
  1236.     $trim_val = $trim_at - 5;
  1237.     $ent_offset = 0;
  1238.     /*
  1239.      * see if this is entities-encoded string
  1240.      * If so, Iterate through the whole string, find out
  1241.      * the real number of characters, and if more
  1242.      * than 55, substr with an updated trim value.
  1243.      */
  1244.     $step = $ent_loc = 0;
  1245.     while ( $ent_loc < $trim_val && (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
  1246.             (($ent_loc_end = strpos($subject, ';', $ent_loc+3)) !== false) ) {
  1247.         $trim_val += ($ent_loc_end-$ent_loc);
  1248.         $ent_offset  = $ent_loc_end+1;
  1249.         ++$step;
  1250.     }
  1251.  
  1252.     if (($trim_val > 50) && (strlen($subject) > ($trim_val))&& (strpos($subject,';',$trim_val) < ($trim_val +6))) {
  1253.         $i = strpos($subject,';',$trim_val);
  1254.         if ($i) {
  1255.             $trim_val = strpos($subject,';',$trim_val);
  1256.         }
  1257.     }
  1258.     if ($ent_strlen <= $trim_at){
  1259.         return $subject;
  1260.     }
  1261.  
  1262.     if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
  1263.         function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
  1264.         return $languages[$squirrelmail_language]['XTRA_CODE']('strimwidth', $subject, $trim_val);
  1265.     }
  1266.  
  1267.     // only print '...' when we're actually dropping part of the subject
  1268.     if(strlen($subject) <= $trim_val) {
  1269.         return $subject;
  1270.     } else {
  1271.         return substr($subject, 0, $trim_val) . '...';
  1272.     }
  1273. }
  1274.  
  1275. function getMbxList($imapConnection) {
  1276.     global $lastTargetMailbox;
  1277.     echo  '         <small>&nbsp;<tt><select name="targetMailbox">';
  1278.     echo sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)) );
  1279.     echo '         </select></tt>&nbsp;';
  1280. }
  1281.  
  1282. function getButton($type, $name, $value) {
  1283.     return '<input type="'.$type.'" name="'.$name.'" value="'.$value . '">';
  1284. }
  1285.  
  1286. function getSmallStringCell($string, $align) {
  1287.     return html_tag('td',
  1288.                     '<small>' . $string . ':&nbsp; </small>',
  1289.                     $align,
  1290.                     '',
  1291.                     'nowrap' );
  1292. }
  1293.  
  1294. function getEndMessage($start_msg, $show_num, $num_msgs) {
  1295.     if ($start_msg + ($show_num - 1) < $num_msgs){
  1296.         $end_msg = $start_msg + ($show_num - 1);
  1297.     } else {
  1298.         $end_msg = $num_msgs;
  1299.     }
  1300.  
  1301.     if ($end_msg < $start_msg) {
  1302.         $start_msg = $start_msg - $show_num;
  1303.         if ($start_msg < 1) {
  1304.             $start_msg = 1;
  1305.         }
  1306.     }
  1307.     return (array($start_msg,$end_msg));
  1308. }
  1309.  
  1310. function handleAsSent($mailbox) {
  1311.     global $handleAsSent_result;
  1312.  
  1313.     /* First check if this is the sent or draft folder. */
  1314.     $handleAsSent_result = isSentMailbox($mailbox) || isDraftMailbox($mailbox);
  1315.  
  1316.     /* Then check the result of the handleAsSent hook. */
  1317.     do_hook('check_handleAsSent_result', $mailbox);
  1318.  
  1319.     /* And return the result. */
  1320.     return $handleAsSent_result;
  1321. }
  1322.  
  1323. // vim: et ts=4
  1324. ?>

Documentation generated on Sat, 07 Oct 2006 16:32:17 +0300 by phpDocumentor 1.3.0RC6