Changeset 992 in subversion
- Timestamp:
- Feb 2, 2008 9:03:38 AM (5 years ago)
- File:
-
- 1 edited
-
trunk/roundcubemail/program/lib/imap.inc (modified) (26 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/roundcubemail/program/lib/imap.inc
r991 r992 58 58 * @todo Split this file into smaller files. 59 59 * @todo Refactor code. 60 * @todo Replace echo-debugging (make it adhere to config setting and log) 60 61 */ 61 62 … … 563 564 564 565 function iil_C_LoadCache(&$conn, $folder) { 565 if (!$conn->do_cache) return false; 566 567 $key = $folder.".imap"; 566 if (!$conn->do_cache) { 567 return false; 568 } 569 570 $key = $folder.'.imap'; 568 571 if (!is_array($conn->cache[$folder])) { 569 $conn->cache[$folder] = cache_read($conn->user, $conn->host, $key);572 $conn->cache[$folder] = cache_read($conn->user, $conn->host, $key); 570 573 $conn->cache_dirty[$folder] = false; 571 574 } … … 574 577 function iil_C_ExpireCachedItems(&$conn, $folder, $message_set) { 575 578 576 if (!$conn->do_cache) return; //caching disabled 577 if (!is_array($conn->cache[$folder])) return; //cache not initialized|empty 578 if (count($conn->cache[$folder]) == 0) return; //cache not initialized|empty 579 580 $uids = iil_C_FetchHeaderIndex($conn, $folder, $message_set, "UID"); 579 if (!$conn->do_cache) { 580 return; //caching disabled 581 } 582 if (!is_array($conn->cache[$folder])) { 583 return; //cache not initialized|empty 584 } 585 if (count($conn->cache[$folder]) == 0) { 586 return; //cache not initialized|empty 587 } 588 589 $uids = iil_C_FetchHeaderIndex($conn, $folder, $message_set, 'UID'); 581 590 $num_removed = 0; 582 591 if (is_array($uids)) { … … 609 618 610 619 function iil_ExplodeQuotedString($delimiter, $string) { 611 $quotes=explode( "\"", $string);612 while ( list($key, $val) = each($quotes)) 613 if (($key % 2) == 1) 620 $quotes=explode('"', $string); 621 while ( list($key, $val) = each($quotes)) { 622 if (($key % 2) == 1) { 614 623 $quotes[$key] = str_replace($delimiter, "_!@!_", $quotes[$key]); 615 $string=implode("\"", $quotes); 624 } 625 } 626 $string=implode('"', $quotes); 616 627 617 628 $result=explode($delimiter, $string); 618 while ( list($key, $val) = each($result) ) 619 $result[$key] = str_replace("_!@!_", $delimiter, $result[$key]); 620 629 while ( list($key, $val) = each($result) ) { 630 $result[$key] = str_replace('_!@!_', $delimiter, $result[$key]); 631 } 632 621 633 return $result; 622 634 } … … 634 646 $line=chop(iil_ReadLine($fp, 300)); 635 647 $a=explode(' ', $line); 636 if (($a[0] == '*') && (strcasecmp($a[2], "RECENT") == 0)) {648 if (($a[0] == '*') && (strcasecmp($a[2], 'RECENT') == 0)) { 637 649 $result = (int) $a[1]; 638 650 } 639 } while (!iil_StartsWith($a[0], "a002"));651 } while (!iil_StartsWith($a[0], 'a002')); 640 652 641 653 fputs($fp, "a003 LOGOUT\r\n"); … … 665 677 $a=explode(' ', $line); 666 678 if (count($a) == 3) { 667 if (strcasecmp($a[2], "EXISTS") == 0) $conn->exists=(int)$a[1]; 668 if (strcasecmp($a[2], "RECENT") == 0) $conn->recent=(int)$a[1]; 679 if (strcasecmp($a[2], 'EXISTS') == 0) { 680 $conn->exists = (int) $a[1]; 681 } 682 if (strcasecmp($a[2], 'RECENT') == 0) { 683 $conn->recent = (int) $a[1]; 684 } 669 685 } 670 } while (!iil_StartsWith($line, "sel1"));686 } while (!iil_StartsWith($line, 'sel1')); 671 687 672 688 $a=explode(' ', $line); 673 689 674 if (strcasecmp($a[1], "OK") == 0) {690 if (strcasecmp($a[1], 'OK') == 0) { 675 691 $conn->selected = $mailbox; 676 692 return true; … … 727 743 //replace double spaces with single space 728 744 $str = trim($str); 729 $str = str_replace( " ", " ", $str);745 $str = str_replace(' ', ' ', $str); 730 746 731 747 //strip off day of week 732 $pos=strpos($str, " ");748 $pos=strpos($str, ' '); 733 749 if (!is_numeric(substr($str, 0, $pos))) { 734 750 $str = substr($str, $pos+1); … … 744 760 $tz_str = $a[4]; 745 761 $tz = substr($tz_str, 0, 3); 746 $ta = explode( ":",$time);762 $ta = explode(':', $time); 747 763 $hour = (int)$ta[0]-(int)$tz; 748 764 $minute = (int)$ta[1]; … … 756 772 757 773 function iil_C_Sort(&$conn, $mailbox, $field, $add='', $is_uid=FALSE, 758 $encoding ='US-ASCII') {774 $encoding = 'US-ASCII') { 759 775 /* Do "SELECT" command */ 760 776 if (!iil_C_Select($conn, $mailbox)) { … … 787 803 do { 788 804 $line = chop(iil_ReadLine($fp, 1024)); 789 if (iil_StartsWith($line, '* SORT')) $data.=($data?' ':'').substr($line,7); 805 if (iil_StartsWith($line, '* SORT')) { 806 $data .= ($data?' ':'') . substr($line, 7); 807 } 790 808 } while ($line[0]!='s'); 791 809 … … 915 933 do { 916 934 $line=chop(iil_ReadLine($fp, 200)); 917 if ($line[0]=="*") { 918 //original: "* 10 FETCH (INTERNALDATE "31-Jul-2002 09:18:02 -0500")" 919 $paren_pos = strpos($line, "("); 920 $foo = substr($line, 0, $paren_pos); 921 $a = explode(' ', $foo); 922 $id = $a[1]; 935 if ($line[0] == '*') { 936 /* 937 * original: 938 * "* 10 FETCH (INTERNALDATE "31-Jul-2002 09:18:02 -0500")" 939 */ 940 $paren_pos = strpos($line, '('); 941 $foo = substr($line, 0, $paren_pos); 942 $a = explode(' ', $foo); 943 $id = $a[1]; 923 944 924 $open_pos = strpos($line, "\"") + 1;925 $close_pos = strrpos($line, "\"");945 $open_pos = strpos($line, '"') + 1; 946 $close_pos = strrpos($line, '"'); 926 947 if ($open_pos && $close_pos) { 927 $len = $close_pos - $open_pos;928 $time_str = substr($line, $open_pos, $len);948 $len = $close_pos - $open_pos; 949 $time_str = substr($line, $open_pos, $len); 929 950 $result[$id] = strtotime($time_str); 930 951 } … … 1020 1041 $incr = $id - $prev; 1021 1042 if ($incr>1) { //found a gap 1022 if ($start==$prev) $result[] = $prev; //push single id 1023 else $result[] = $start.':'.$prev; //push sequence as start_id:end_id 1024 $start = $id; //start of new sequence 1043 if ($start==$prev) { 1044 $result[] = $prev; //push single id 1045 } else { 1046 $result[] = $start.':'.$prev; //push sequence as start_id:end_id 1047 } 1048 $start = $id; //start of new sequence 1025 1049 } 1026 1050 $prev = $id; … … 1059 1083 return array(); 1060 1084 } 1061 $message_set = '1' .($num>1?':'.$num:'');1085 $message_set = '1' . ($num>1?':' . $num:''); 1062 1086 1063 1087 //if cache not enabled, just call iil_C_FetchHeaderIndex on 'UID' field … … 1075 1099 1076 1100 //was anything cached at all? 1077 if ($data ===false) {1101 if ($data === false) { 1078 1102 $cache_good = -1; 1079 1103 } … … 1099 1123 1100 1124 //otherwise, we need to fetch it 1101 $data = array('n' =>$num,'d'=>array());1125 $data = array('n' => $num, 'd' => array()); 1102 1126 $data['d'] = iil_C_FetchHeaderIndex($conn, $mailbox, $message_set, 'UID'); 1103 1127 … … 2100 2124 $i++; 2101 2125 } 2102 } while (!iil_StartsWith($line, "lmb"));2126 } while (!iil_StartsWith($line, 'lmb')); 2103 2127 2104 2128 if (is_array($folders)) { … … 2168 2192 $i++; 2169 2193 } 2170 } while (!iil_StartsWith($line, "lsb"));2194 } while (!iil_StartsWith($line, 'lsb')); 2171 2195 2172 2196 if (is_array($folders)) { … … 2267 2291 $line = chop(iil_ReadLine($fp, 1000)); 2268 2292 $a = explode(' ', $line); 2269 } while ($a[2] !="FETCH");2293 } while ($a[2] != 'FETCH'); 2270 2294 $len = strlen($line); 2271 2295 if ($line[$len-1] == ')') { … … 2318 2342 return false; 2319 2343 } else { 2320 echo "Select failed.";2344 echo 'Select failed.'; 2321 2345 } 2322 2346 … … 2341 2365 function iil_C_CreateFolder(&$conn, $folder) { 2342 2366 $fp = $conn->fp; 2343 if (fputs($fp, "c CREATE \"".$folder."\"\r\n")) {2367 if (fputs($fp, 'c CREATE "' . $folder . '"' . "\r\n")) { 2344 2368 do { 2345 2369 $line=iil_ReadLine($fp, 300); 2346 } while ($line[0] !="c");2370 } while ($line[0] != 'c'); 2347 2371 $conn->error = $line; 2348 2372 return (iil_ParseResult($line) == 0); … … 2353 2377 function iil_C_RenameFolder(&$conn, $from, $to) { 2354 2378 $fp = $conn->fp; 2355 if (fputs($fp, "r RENAME \"".$from."\" \"".$to."\"\r\n")) {2379 if (fputs($fp, 'r RENAME "' . $from . '" "' . $to . '"' . "\r\n")) { 2356 2380 do { 2357 2381 $line=iil_ReadLine($fp, 300); … … 2364 2388 function iil_C_DeleteFolder(&$conn, $folder) { 2365 2389 $fp = $conn->fp; 2366 if (fputs($fp, "d DELETE \"".$folder."\"\r\n")) {2390 if (fputs($fp, 'd DELETE "' . $folder. '"' . "\r\n")) { 2367 2391 do { 2368 2392 $line=iil_ReadLine($fp, 300); … … 2396 2420 $result = (iil_ParseResult($line) == 0); 2397 2421 if (!$result) { 2398 $conn->error .= $line ."\n";2422 $conn->error .= $line . "\n"; 2399 2423 } 2400 2424 return $result; … … 2414 2438 $in_fp = false; 2415 2439 if (file_exists(realpath($path))) { 2416 $in_fp = fopen($path, "r");2440 $in_fp = fopen($path, 'r'); 2417 2441 } 2418 2442 if (!$in_fp) { … … 2450 2474 $result = (iil_ParseResult($line) == 0); 2451 2475 if (!$result) { 2452 $conn->error .= $line ."\n";2476 $conn->error .= $line . "\n"; 2453 2477 } 2454 2478 return $result; … … 2514 2538 2515 2539 //get line containing quota info 2516 if (fputs($fp, "QUOT1 GETQUOTAROOT \"INBOX\"\r\n")) {2540 if (fputs($fp, 'QUOT1 GETQUOTAROOT "INBOX"' . "\r\n")) { 2517 2541 do { 2518 2542 $line=chop(iil_ReadLine($fp, 5000)); 2519 if (iil_StartsWith($line, "* QUOTA ")) {2543 if (iil_StartsWith($line, '* QUOTA ')) { 2520 2544 $quota_line = $line; 2521 2545 } 2522 } while (!iil_StartsWith($line, "QUOT1"));2546 } while (!iil_StartsWith($line, 'QUOT1')); 2523 2547 } 2524 2548 2525 2549 //return false if not found, parse if found 2526 2550 if (!empty($quota_line)) { 2527 $quota_line = eregi_replace( "[()]", '', $quota_line);2551 $quota_line = eregi_replace('[()]', '', $quota_line); 2528 2552 $parts = explode(' ', $quota_line); 2529 $storage_part = array_search( "STORAGE", $parts);2553 $storage_part = array_search('STORAGE', $parts); 2530 2554 if ($storage_part>0) { 2531 2555 $result = array();
Note: See TracChangeset
for help on using the changeset viewer.
