Changeset 2451 in subversion
- Timestamp:
- May 4, 2009 3:53:01 AM (4 years ago)
- File:
-
- 1 edited
-
trunk/roundcubemail/program/lib/imap.inc (modified) (29 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/roundcubemail/program/lib/imap.inc
r2448 r2451 80 80 - added iil_C_FetchMIMEHeaders() function 81 81 - added \* flag support 82 - use PREG instead of EREG 83 - removed caching functions 82 84 83 85 ********************************************************/ … … 135 137 var $message; 136 138 var $host; 137 var $cache;138 var $uid_cache;139 var $do_cache;140 139 var $exists; 141 140 var $recent; … … 259 258 function iil_MultLine($fp, $line) { 260 259 $line = chop($line); 261 if ( ereg('\{[0-9]+\}$', $line)) {260 if (preg_match('/\{[0-9]+\}$/', $line)) { 262 261 $out = ''; 263 262 … … 321 320 return true; 322 321 } 323 if ($error && preg_match('/^\* (BYE|BAD) / ', $string)) {322 if ($error && preg_match('/^\* (BYE|BAD) /i', $string)) { 324 323 return true; 325 324 } … … 547 546 global $iil_error, $iil_errornum; 548 547 global $ICL_SSL, $ICL_PORT; 549 global $IMAP_NO_CACHE;550 548 global $my_prefs, $IMAP_USE_INTERNAL_DATE; 551 549 … … 580 578 $conn->user = $user; 581 579 $conn->host = $host; 582 $conn->cache = array();583 $conn->do_cache = (function_exists("cache_write")&&!$IMAP_NO_CACHE);584 $conn->cache_dirty = array();585 580 586 581 if ($my_prefs['sort_field'] == 'INTERNALDATE') { … … 714 709 715 710 function iil_Close(&$conn) { 716 iil_C_WriteCache($conn);717 711 if (iil_PutLine($conn->fp, "I LOGOUT")) { 718 712 fgets($conn->fp, 1024); … … 720 714 $conn->fp = false; 721 715 } 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 disabled766 }767 if (!is_array($conn->cache[$folder])) {768 return; //cache not initialized|empty769 }770 if (count($conn->cache[$folder]) == 0) {771 return; //cache not initialized|empty772 }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 */802 716 } 803 717 … … 854 768 } 855 769 856 iil_C_LoadCache($conn, $mailbox);857 858 770 if (iil_PutLine($conn->fp, "sel1 SELECT \"".iil_Escape($mailbox).'"')) { 859 771 do { … … 1286 1198 $message_set = '1' . ($num>1?':' . $num:''); 1287 1199 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'); 1332 1201 } 1333 1202 … … 1356 1225 $debug = false; 1357 1226 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 }1378 1227 $message_set = iil_CompressMessageSet($message_set); 1379 if ($debug) {1380 echo "Still need: ".$message_set;1381 }1382 1228 1383 1229 /* if we're missing any, get them */ … … 1397 1243 echo $line . "\n"; 1398 1244 } 1399 if ( ereg('\{[0-9]+\}$', $line)) {1245 if (preg_match('/\{[0-9]+\}$/', $line)) { 1400 1246 $a = explode(' ', $line); 1401 1247 $new = array(); … … 1415 1261 $new[strtoupper($field_name)] = trim($field_val); 1416 1262 1417 } else if ( ereg('^[[:space:]]', $line)) {1263 } else if (preg_match('/^\s+/', $line)) { 1418 1264 $new[strtoupper($field_name)] .= trim($line); 1419 1265 } … … 1434 1280 } 1435 1281 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 1443 1282 //echo 'iil_FetchThreadHeaders:'."\n"; 1444 1283 //print_r($result); … … 1465 1304 $debug = false; 1466 1305 1467 $sbj_filter_pat = ' [a-zA-Z]{2,3}(\[[0-9]*\])?:([[:space:]]*)';1306 $sbj_filter_pat = '/[a-z]{2,3}(\[[0-9]*\])?:(\s*)/i'; 1468 1307 1469 1308 /* Do "SELECT" command */ … … 1502 1341 1503 1342 /* if subject contains 'RE:' or has in-reply-to header, it's a reply */ 1504 $sbj_pre = '';1343 $sbj_pre = ''; 1505 1344 $has_re = false; 1506 if ( eregi($sbj_filter_pat, $new['SUBJECT'])) {1345 if (preg_match($sbj_filter_pat, $new['SUBJECT'])) { 1507 1346 $has_re = true; 1508 1347 } 1509 if ($has_re ||$new['IN-REPLY-TO']) {1348 if ($has_re || $new['IN-REPLY-TO']) { 1510 1349 $sbj_pre = 'RE:'; 1511 1350 } … … 1513 1352 /* strip out 're:', 'fw:' etc */ 1514 1353 if ($has_re) { 1515 $sbj = ereg_replace($sbj_filter_pat, '', $new['SUBJECT']);1354 $sbj = preg_replace($sbj_filter_pat, '', $new['SUBJECT']); 1516 1355 } else { 1517 1356 $sbj = $new['SUBJECT']; … … 1682 1521 } 1683 1522 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 1706 1523 if ($add) 1707 $add = ' '.strtoupper(trim($add));1524 $add = ' '.strtoupper(trim($add)); 1708 1525 1709 1526 /* FETCH uid, size, flags and headers */ … … 1747 1564 1748 1565 // swap parents with quotes, then explode 1749 $str = eregi_replace("[()]", "\"", $str);1566 $str = preg_replace('/[()]/', '"', $str); 1750 1567 $a = iil_ExplodeQuotedString(' ', $str); 1751 1568 … … 1864 1681 1865 1682 $field = strtolower($field); 1866 $string = ereg_replace("\n[[:space:]]*"," ",$string);1683 $string = preg_replace('/\n\s*/', ' ', $string); 1867 1684 1868 1685 switch ($field) { … … 1905 1722 break; 1906 1723 case 'in-reply-to': 1907 $result[$id]->in_reply_to = ereg_replace("[\n<>]", '', $string);1724 $result[$id]->in_reply_to = preg_replace('/[\n<>]/', '', $string); 1908 1725 break; 1909 1726 case 'references': … … 1928 1745 } // end switch () 1929 1746 } // 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 }1936 1747 } else { 1937 1748 $a = explode(' ', $line); … … 1940 1751 // process flags 1941 1752 if (!empty($flags_str)) { 1942 $flags_str = eregi_replace('[\\\"]', '', $flags_str);1753 $flags_str = preg_replace('/[\\\"]/', '', $flags_str); 1943 1754 $flags_a = explode(' ', $flags_str); 1944 1755 … … 2090 1901 2091 1902 if (iil_ParseResult($line) == 0) { 2092 iil_C_ExpireCachedItems($conn, $mailbox, $messages);2093 1903 return $c; 2094 1904 } … … 2175 1985 do { 2176 1986 $line=chop(iil_ReadLine($fp, 1024)); 2177 if ( eregi("^\* $id FETCH \(UID (.*)\)", $line, $r)) {1987 if (preg_match("/^\* $id FETCH \(UID (.*)\)/i", $line, $r)) { 2178 1988 $result = $r[1]; 2179 1989 } … … 2195 2005 do { 2196 2006 $line=trim(iil_ReadLine($fp, 10000)); 2197 if ( eregi("^\* SEARCH", $line)) {2007 if (preg_match('/^\* SEARCH/i', $line)) { 2198 2008 $str = trim(substr($line, 8)); 2199 2009 $messages = explode(' ', $str); … … 2338 2148 2339 2149 if (empty($ignore) || (!empty($ignore) 2340 && ! eregi($ignore, $folder))) {2150 && !preg_match('/'.preg_quote(ignore, '/').'/i', $folder))) { 2341 2151 $folders[$i] = $folder; 2342 2152 } … … 2406 2216 2407 2217 if ((!in_array($folder, $folders)) && (empty($ignore) 2408 || (!empty($ignore) && ! eregi($ignore, $folder)))) {2218 || (!empty($ignore) && !preg_match('/'.preg_quote(ignore, '/').'/i', $folder)))) { 2409 2219 $folders[$i] = $folder; 2410 2220 } … … 2819 2629 $min_free = PHP_INT_MAX; 2820 2630 foreach ($quota_lines as $key => $quota_line) { 2821 $quota_line = eregi_replace('[()]', '', $quota_line);2631 $quota_line = preg_replace('/[()]/', '', $quota_line); 2822 2632 $parts = explode(' ', $quota_line); 2823 2633 $storage_part = array_search('STORAGE', $parts);
Note: See TracChangeset
for help on using the changeset viewer.
