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

Documentation generated on Wed, 19 Jun 2013 04:22:34 +0200 by phpDocumentor 1.4.3