Changeset 2451 in subversion


Ignore:
Timestamp:
May 4, 2009 3:53:01 AM (4 years ago)
Author:
alec
Message:
  • use preg_* instead of ereg* + removed caching functions
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/program/lib/imap.inc

    r2448 r2451  
    8080                - added iil_C_FetchMIMEHeaders() function 
    8181                - added \* flag support  
     82                - use PREG instead of EREG 
     83                - removed caching functions 
    8284 
    8385********************************************************/ 
     
    135137        var $message; 
    136138        var $host; 
    137         var $cache; 
    138         var $uid_cache; 
    139         var $do_cache; 
    140139        var $exists; 
    141140        var $recent; 
     
    259258function iil_MultLine($fp, $line) { 
    260259        $line = chop($line); 
    261         if (ereg('\{[0-9]+\}$', $line)) { 
     260        if (preg_match('/\{[0-9]+\}$/', $line)) { 
    262261                $out = ''; 
    263262         
     
    321320                return true; 
    322321        } 
    323         if ($error && preg_match('/^\* (BYE|BAD) /', $string)) { 
     322        if ($error && preg_match('/^\* (BYE|BAD) /i', $string)) { 
    324323                return true; 
    325324        } 
     
    547546        global $iil_error, $iil_errornum; 
    548547        global $ICL_SSL, $ICL_PORT; 
    549         global $IMAP_NO_CACHE; 
    550548        global $my_prefs, $IMAP_USE_INTERNAL_DATE; 
    551549         
     
    580578        $conn->user        = $user; 
    581579        $conn->host        = $host; 
    582         $conn->cache       = array(); 
    583         $conn->do_cache    = (function_exists("cache_write")&&!$IMAP_NO_CACHE); 
    584         $conn->cache_dirty = array(); 
    585580         
    586581        if ($my_prefs['sort_field'] == 'INTERNALDATE') { 
     
    714709 
    715710function iil_Close(&$conn) { 
    716         iil_C_WriteCache($conn); 
    717711        if (iil_PutLine($conn->fp, "I LOGOUT")) { 
    718712                fgets($conn->fp, 1024); 
     
    720714                $conn->fp = false; 
    721715        } 
    722 } 
    723  
    724 function iil_ClearCache($user, $host) { 
    725 } 
    726  
    727 function iil_C_WriteCache(&$conn) { 
    728         //echo "<!-- doing iil_C_WriteCache //-->\n"; 
    729         if (!$conn->do_cache) return false; 
    730          
    731         if (is_array($conn->cache)) { 
    732                 while (list($folder,$data)=each($conn->cache)) { 
    733                         if ($folder && is_array($data) && $conn->cache_dirty[$folder]) { 
    734                                 $key = $folder.".imap"; 
    735                                 $result = cache_write($conn->user, $conn->host, $key, $data, true); 
    736                                 //echo "<!-- writing $key $data: $result //-->\n"; 
    737                         } 
    738                 } 
    739         } 
    740 } 
    741  
    742 function iil_C_EnableCache(&$conn) { 
    743         $conn->do_cache = true; 
    744 } 
    745  
    746 function iil_C_DisableCache(&$conn) { 
    747         $conn->do_cache = false; 
    748 } 
    749  
    750 function iil_C_LoadCache(&$conn, $folder) { 
    751         if (!$conn->do_cache) { 
    752             return false; 
    753         } 
    754      
    755         $key = $folder.'.imap'; 
    756         if (!is_array($conn->cache[$folder])) { 
    757                 $conn->cache[$folder]       = cache_read($conn->user, $conn->host, $key); 
    758                 $conn->cache_dirty[$folder] = false; 
    759         } 
    760 } 
    761  
    762 function iil_C_ExpireCachedItems(&$conn, $folder, $message_set) { 
    763          
    764         if (!$conn->do_cache) { 
    765                 return; //caching disabled 
    766         } 
    767         if (!is_array($conn->cache[$folder])) { 
    768                 return; //cache not initialized|empty 
    769         } 
    770         if (count($conn->cache[$folder]) == 0) { 
    771                 return; //cache not initialized|empty 
    772         } 
    773      
    774         $uids = iil_C_FetchHeaderIndex($conn, $folder, $message_set, 'UID'); 
    775         $num_removed = 0; 
    776         if (is_array($uids)) { 
    777                 //echo "<!-- unsetting: ".implode(",",$uids)." //-->\n"; 
    778                 while (list($n,$uid)=each($uids)) { 
    779                         unset($conn->cache[$folder][$uid]); 
    780                         //$conn->cache[$folder][$uid] = false; 
    781                         //$num_removed++; 
    782                 } 
    783                 $conn->cache_dirty[$folder] = true; 
    784  
    785                 //echo '<!--'."\n"; 
    786                 //print_r($conn->cache); 
    787                 //echo "\n".'//-->'."\n"; 
    788         } else { 
    789                 echo "<!-- failed to get uids: $message_set //-->\n"; 
    790         } 
    791          
    792         /* 
    793         if ($num_removed>0) { 
    794                 $new_cache; 
    795                 reset($conn->cache[$folder]); 
    796                 while (list($uid,$item)=each($conn->cache[$folder])) { 
    797                         if ($item) $new_cache[$uid] = $conn->cache[$folder][$uid]; 
    798                 } 
    799                 $conn->cache[$folder] = $new_cache; 
    800         } 
    801         */ 
    802716} 
    803717 
     
    854768        } 
    855769     
    856         iil_C_LoadCache($conn, $mailbox); 
    857          
    858770        if (iil_PutLine($conn->fp, "sel1 SELECT \"".iil_Escape($mailbox).'"')) { 
    859771                do { 
     
    12861198        $message_set = '1' . ($num>1?':' . $num:''); 
    12871199         
    1288         //if cache not enabled, just call iil_C_FetchHeaderIndex on 'UID' field 
    1289         if (!$conn->do_cache) 
    1290                 return iil_C_FetchHeaderIndex($conn, $mailbox, $message_set, 'UID'); 
    1291  
    1292         //otherwise, let's check cache first 
    1293         $key        = $mailbox.'.uids'; 
    1294         $cache_good = true; 
    1295         if ($conn->uid_cache) { 
    1296             $data = $conn->uid_cache; 
    1297         } else { 
    1298             $data = cache_read($conn->user, $conn->host, $key); 
    1299         } 
    1300      
    1301         //was anything cached at all? 
    1302         if ($data === false) { 
    1303             $cache_good = -1; 
    1304         } 
    1305      
    1306         //make sure number of messages were the same 
    1307         if ($cache_good > 0 && $data['n'] != $num) { 
    1308             $cache_good = -2; 
    1309         } 
    1310      
    1311         //if everything's okay so far... 
    1312         if ($cache_good > 0) { 
    1313                 //check UIDs of highest mid with current and cached 
    1314                 $temp = iil_C_Search($conn, $mailbox, 'UID ' . $data['d'][$num]); 
    1315                 if (!$temp || !is_array($temp) || $temp[0] != $num) { 
    1316                     $cache_good = -3; 
    1317                 } 
    1318         } 
    1319  
    1320         //if cached data's good, return it 
    1321         if ($cache_good > 0) { 
    1322                 return $data['d']; 
    1323         } 
    1324  
    1325         //otherwise, we need to fetch it 
    1326         $data      = array('n' => $num, 'd' => array()); 
    1327         $data['d'] = iil_C_FetchHeaderIndex($conn, $mailbox, $message_set, 'UID'); 
    1328      
    1329         cache_write($conn->user, $conn->host, $key, $data); 
    1330         $conn->uid_cache = $data; 
    1331         return $data['d']; 
     1200        return iil_C_FetchHeaderIndex($conn, $mailbox, $message_set, 'UID'); 
    13321201} 
    13331202 
     
    13561225        $debug  = false; 
    13571226         
    1358         /* Get cached records where possible */ 
    1359         if ($conn->do_cache) { 
    1360                 $cached = cache_read($conn->user, $conn->host, $mailbox.'.thhd'); 
    1361                 if ($cached && is_array($uids) && count($uids)>0) { 
    1362                         $needed_set = ''; 
    1363                         foreach ($uids as $id=>$uid) { 
    1364                                 if ($cached[$uid]) { 
    1365                                         $result[$uid]     = $cached[$uid]; 
    1366                                         $result[$uid]->id = $id; 
    1367                                 } else { 
    1368                                     $needed_set .= ($needed_set ? ',' : '') . $id; 
    1369                                 } 
    1370                         } 
    1371                         if ($needed_set) { 
    1372                             $message_set = $needed_set; 
    1373                         } else { 
    1374                             $message_set = ''; 
    1375                         } 
    1376                 } 
    1377         } 
    13781227        $message_set = iil_CompressMessageSet($message_set); 
    1379         if ($debug) { 
    1380             echo "Still need: ".$message_set; 
    1381         } 
    13821228     
    13831229        /* if we're missing any, get them */ 
     
    13971243                            echo $line . "\n"; 
    13981244                        } 
    1399                         if (ereg('\{[0-9]+\}$', $line)) { 
     1245                        if (preg_match('/\{[0-9]+\}$/', $line)) { 
    14001246                                $a       = explode(' ', $line); 
    14011247                                $new = array(); 
     
    14151261                                                $new[strtoupper($field_name)] = trim($field_val); 
    14161262 
    1417                                         } else if (ereg('^[[:space:]]', $line)) { 
     1263                                        } else if (preg_match('/^\s+/', $line)) { 
    14181264                                                $new[strtoupper($field_name)] .= trim($line); 
    14191265                                        } 
     
    14341280        } 
    14351281         
    1436         /* write new set to cache */ 
    1437         if ($conn->do_cache) { 
    1438                 if (count($result)!=count($cached)) { 
    1439                         cache_write($conn->user, $conn->host, $mailbox . '.thhd', $result); 
    1440                 } 
    1441         } 
    1442          
    14431282        //echo 'iil_FetchThreadHeaders:'."\n"; 
    14441283        //print_r($result); 
     
    14651304        $debug     = false; 
    14661305         
    1467         $sbj_filter_pat = '[a-zA-Z]{2,3}(\[[0-9]*\])?:([[:space:]]*)'; 
     1306        $sbj_filter_pat = '/[a-z]{2,3}(\[[0-9]*\])?:(\s*)/i'; 
    14681307         
    14691308        /*  Do "SELECT" command */ 
     
    15021341         
    15031342                /* if subject contains 'RE:' or has in-reply-to header, it's a reply */ 
    1504                 $sbj_pre =''; 
     1343                $sbj_pre = ''; 
    15051344                $has_re = false; 
    1506                 if (eregi($sbj_filter_pat, $new['SUBJECT'])) { 
     1345                if (preg_match($sbj_filter_pat, $new['SUBJECT'])) { 
    15071346                    $has_re = true; 
    15081347                } 
    1509                 if ($has_re||$new['IN-REPLY-TO']) { 
     1348                if ($has_re || $new['IN-REPLY-TO']) { 
    15101349                    $sbj_pre = 'RE:'; 
    15111350                } 
     
    15131352                /* strip out 're:', 'fw:' etc */ 
    15141353                if ($has_re) { 
    1515                     $sbj = ereg_replace($sbj_filter_pat, '', $new['SUBJECT']); 
     1354                    $sbj = preg_replace($sbj_filter_pat, '', $new['SUBJECT']); 
    15161355                } else { 
    15171356                    $sbj = $new['SUBJECT']; 
     
    16821521        } 
    16831522                 
    1684         /* Get cached records where possible */ 
    1685         if ($conn->do_cache) { 
    1686                 $uids = iil_C_FetchHeaderIndex($conn, $mailbox, $message_set, "UID"); 
    1687                 if (is_array($uids) && count($conn->cache[$mailbox]>0)) { 
    1688                         $needed_set = ''; 
    1689                         while (list($id,$uid)=each($uids)) { 
    1690                                 if ($conn->cache[$mailbox][$uid]) { 
    1691                                         $result[$id]     = $conn->cache[$mailbox][$uid]; 
    1692                                         $result[$id]->id = $id; 
    1693                                 } else { 
    1694                                     $needed_set.=($needed_set ? ',': '') . $id; 
    1695                                 } 
    1696                         } 
    1697                         //echo "<!-- iil_C_FetchHeader\nMessage Set: $message_set\nNeeded Set:$needed_set\n//-->\n"; 
    1698                         if ($needed_set) { 
    1699                                 $message_set = iil_CompressMessageSet($needed_set); 
    1700                         } else { 
    1701                                 return $result; 
    1702                         } 
    1703                 } 
    1704         } 
    1705          
    17061523        if ($add) 
    1707           $add = ' '.strtoupper(trim($add)); 
     1524                $add = ' '.strtoupper(trim($add)); 
    17081525 
    17091526        /* FETCH uid, size, flags and headers */ 
     
    17471564 
    17481565                                // swap parents with quotes, then explode 
    1749                                 $str = eregi_replace("[()]", "\"", $str); 
     1566                                $str = preg_replace('/[()]/', '"', $str); 
    17501567                                $a = iil_ExplodeQuotedString(' ', $str); 
    17511568 
     
    18641681                                         
    18651682                                        $field  = strtolower($field); 
    1866                                         $string = ereg_replace("\n[[:space:]]*"," ",$string); 
     1683                                        $string = preg_replace('/\n\s*/', ' ', $string); 
    18671684                                         
    18681685                                        switch ($field) { 
     
    19051722                                                break; 
    19061723                                        case 'in-reply-to': 
    1907                                                 $result[$id]->in_reply_to = ereg_replace("[\n<>]", '', $string); 
     1724                                                $result[$id]->in_reply_to = preg_replace('/[\n<>]/', '', $string); 
    19081725                                                break; 
    19091726                                        case 'references': 
     
    19281745                                        } // end switch () 
    19291746                                } // end while () 
    1930                  
    1931                                 if ($conn->do_cache) { 
    1932                                         $uid = $result[$id]->uid; 
    1933                                         $conn->cache[$mailbox][$uid] = $result[$id]; 
    1934                                         $conn->cache_dirty[$mailbox] = true; 
    1935                                 } 
    19361747                        } else { 
    19371748                                $a = explode(' ', $line); 
     
    19401751                        // process flags 
    19411752                        if (!empty($flags_str)) { 
    1942                                 $flags_str = eregi_replace('[\\\"]', '', $flags_str); 
     1753                                $flags_str = preg_replace('/[\\\"]/', '', $flags_str); 
    19431754                                $flags_a   = explode(' ', $flags_str); 
    19441755                                         
     
    20901901 
    20911902                if (iil_ParseResult($line) == 0) { 
    2092                         iil_C_ExpireCachedItems($conn, $mailbox, $messages); 
    20931903                        return $c; 
    20941904                } 
     
    21751985                        do { 
    21761986                                $line=chop(iil_ReadLine($fp, 1024)); 
    2177                                 if (eregi("^\* $id FETCH \(UID (.*)\)", $line, $r)) { 
     1987                                if (preg_match("/^\* $id FETCH \(UID (.*)\)/i", $line, $r)) { 
    21781988                                        $result = $r[1]; 
    21791989                                } 
     
    21952005                do { 
    21962006                        $line=trim(iil_ReadLine($fp, 10000)); 
    2197                         if (eregi("^\* SEARCH", $line)) { 
     2007                        if (preg_match('/^\* SEARCH/i', $line)) { 
    21982008                                $str = trim(substr($line, 8)); 
    21992009                                $messages = explode(' ', $str); 
     
    23382148             
    23392149                        if (empty($ignore) || (!empty($ignore) 
    2340                                 && !eregi($ignore, $folder))) { 
     2150                                && !preg_match('/'.preg_quote(ignore, '/').'/i', $folder))) { 
    23412151                                $folders[$i] = $folder; 
    23422152                        } 
     
    24062216             
    24072217                        if ((!in_array($folder, $folders)) && (empty($ignore) 
    2408                                 || (!empty($ignore) && !eregi($ignore, $folder)))) { 
     2218                                || (!empty($ignore) && !preg_match('/'.preg_quote(ignore, '/').'/i', $folder)))) { 
    24092219                            $folders[$i] = $folder; 
    24102220                        } 
     
    28192629        $min_free = PHP_INT_MAX; 
    28202630        foreach ($quota_lines as $key => $quota_line) { 
    2821                 $quota_line   = eregi_replace('[()]', '', $quota_line); 
     2631                $quota_line   = preg_replace('/[()]/', '', $quota_line); 
    28222632                $parts        = explode(' ', $quota_line); 
    28232633                $storage_part = array_search('STORAGE', $parts); 
Note: See TracChangeset for help on using the changeset viewer.