Rewrite of sqimap_read_data_list. This will raise performance and it's more
[squirrelmail.git] / functions / mailbox_display.php
index 97f1418bbac8958512b97d7e590d1ded1fd80ff0..426609ed4aef42d66cdb22ea75721201eade1f94 100644 (file)
@@ -73,7 +73,7 @@ function printMessageInfo($imapConnection, $t, $not_last=true, $key, $mailbox,
     if (handleAsSent($mailbox)) {
        $msg['FROM'] = $msg['TO'];
     }
-    $msg['FROM'] = parseAddress($msg['FROM']);
+    $msg['FROM'] = parseAddress($msg['FROM'],1);
     
        /*
         * This is done in case you're looking into Sent folders,
@@ -134,60 +134,41 @@ function printMessageInfo($imapConnection, $t, $not_last=true, $key, $mailbox,
     } else {
         $searchstr = '';
     }
-    /**
-    * AAAAH! Make my eyes stop bleeding!
-    * Who wrote this?!
-    */
+    
     if (is_array($message_highlight_list) && count($message_highlight_list)) {
-       $msg['TO'] = parseAddress($msg['TO']);
-       $msg['CC'] = parseAddress($msg['CC']);
+        $msg['TO'] = parseAddress($msg['TO']);
+        $msg['CC'] = parseAddress($msg['CC']);
         foreach ($message_highlight_list as $message_highlight_list_part) {
             if (trim($message_highlight_list_part['value']) != '') {
                 $high_val   = strtolower($message_highlight_list_part['value']);
                 $match_type = strtoupper($message_highlight_list_part['match_type']);
-                switch($match_type) {
-                    case('TO'):
-                    case('TO_CC'):
-                        foreach ($msg['TO'] as $address) {
-                            $address[0] = decodeHeader($address[0]);
-                            $address[1] = decodeHeader($address[1]);
-                            if (strstr('^^' . strtolower($address[0]), $high_val) ||
-                                strstr('^^' . strtolower($address[1]), $high_val)) {
-                                $hlt_color = $message_highlight_list_part['color'];
-                                continue;
+                if($match_type == 'TO_CC') {
+                    $match = array('TO', 'CC');
+                } else {
+                    $match = array($match_type);
+                }
+                foreach($match as $match_type) {
+                    switch($match_type) {
+                        case('TO'):
+                        case('CC'):
+                        case('FROM'):
+                            foreach ($msg[$match_type] as $address) {
+                                $address[0] = decodeHeader($address[0]);
+                                $address[1] = decodeHeader($address[1]);
+                                if (strstr('^^' . strtolower($address[0]), $high_val) ||
+                                    strstr('^^' . strtolower($address[1]), $high_val)) {
+                                    $hlt_color = $message_highlight_list_part['color'];
+                                    break 4;
+                                }
                             }
-                        }
-                        if($match_type != 'TO_CC') {
                             break;
-                        }
-                    case('CC'):
-                        foreach ($msg['CC'] as $address) {
-                            $address[0] = decodeHeader($address[0]);
-                            $address[1] = decodeHeader($address[1]);
-                            if( strstr('^^' . strtolower($address[0]), $high_val) ||
-                                strstr('^^' . strtolower($address[1]), $high_val)) {
+                        default:
+                            if (strstr('^^' . strtolower($msg[$match_type]), $high_val)) {
                                 $hlt_color = $message_highlight_list_part['color'];
-                                continue;
+                                break 3; 
                             }
-                        }
-                        break;
-                    case('FROM'):
-                        foreach ($msg['FROM'] as $address) {
-                            $address[0] = decodeHeader($address[0]);
-                            $address[1] = decodeHeader($address[1]);
-                            if( strstr('^^' . strtolower($address[0]), $high_val) ||
-                                strstr('^^' . strtolower($address[1]), $high_val)) {
-                                $hlt_color = $message_highlight_list_part['color'];
-                                continue;
-                            }
-                        }
-                        break;
-                    default:
-                        if (strstr('^^' . strtolower($msg[$match_type]), $high_val)) {
-                            $hlt_color = $message_highlight_list_part['color'];
-                            continue;
-                        }
-                        break;
+                            break;
+                    }
                 }
             }
         }
@@ -314,7 +295,7 @@ function getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $i
         } else {
             $end_loop = $show_num;
         }
-        return fillMessageArray($imapConnection,$id,$end_loop);
+        return fillMessageArray($imapConnection,$id,$end_loop,$show_num);
     } else {
         return false;
     }
@@ -362,7 +343,7 @@ function getSelfSortMessages($imapConnection, $start_msg, $show_num,
                 $end_loop = $show_num;
             }
         }
-        $msgs = fillMessageArray($imapConnection,$id,$end_loop);
+        $msgs = fillMessageArray($imapConnection,$id,$end_loop, $show_num);
     }
     return $msgs;
 }
@@ -393,7 +374,7 @@ function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
         $msgs = array();
     }
 
-    $start = microtime();
+    //$start = microtime();
     /* If autoexpunge is turned on, then do it now. */
     $mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox);
     $srt = $sort;
@@ -507,7 +488,7 @@ function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
 
     mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color); 
     echo '</td></tr></table>';
-    $t = elapsed($start);
+    //$t = elapsed($start);
     //echo("elapsed time = $t seconds\n");
 }
 
@@ -547,8 +528,8 @@ function calc_msort($msgs, $sort) {
     return $msort;
 }
 
-function fillMessageArray($imapConnection, $id, $count) {
-    return sqimap_get_small_header_list($imapConnection, $id);
+function fillMessageArray($imapConnection, $id, $count, $show_num=false) {
+    return sqimap_get_small_header_list($imapConnection, $id, $show_num);
 }