Changeset 3d695da in github
- Timestamp:
- Feb 12, 2008 7:48:39 PM (5 years ago)
- Branches:
- master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
- Children:
- 2f93b03
- Parents:
- 8b661f6
- File:
-
- 1 edited
-
program/lib/imap.inc (modified) (46 diffs)
Legend:
- Unmodified
- Added
- Removed
-
program/lib/imap.inc
ra9a8ef2 r3d695da 57 57 /** 58 58 * @todo Possibly clean up more CS. 59 * @todo Try to replace most double-quotes with single-quotes. 59 60 * @todo Split this file into smaller files. 60 61 * @todo Refactor code. … … 63 64 64 65 // changed path to work within roundcube webmail 65 include_once ("lib/icl_commons.inc");66 include_once 'lib/icl_commons.inc'; 66 67 67 68 … … 254 255 // initialize ipad, opad 255 256 for ($i=0;$i<64;$i++) { 256 $ipad .= chr(0x36);257 $opad .= chr(0x5C);257 $ipad .= chr(0x36); 258 $opad .= chr(0x5C); 258 259 } 259 260 // pad $pass so it's 64 bytes … … 265 266 // generate hash 266 267 $hash = iil_xor($pass,$opad); 267 $hash .= pack("H*", md5(iil_xor($pass, $ipad) . base64_decode($encChallenge)));268 $hash .= pack("H*", md5(iil_xor($pass, $ipad) . base64_decode($encChallenge))); 268 269 $hash = md5($hash); 269 270 … … 457 458 //check for SSL 458 459 if ($ICL_SSL) { 459 $host = $ICL_SSL ."://".$host;460 $host = $ICL_SSL . '://' . $host; 460 461 } 461 462 … … 475 476 476 477 //default to plain text auth 477 $auth_method = "plain";478 $auth_method = 'plain'; 478 479 479 480 //check for CRAM-MD5 … … 481 482 do { 482 483 $line = trim(chop(iil_ReadLine($conn->fp, 100))); 483 $conn->message.="$line\n"; 484 485 $conn->message .= "$line\n"; 486 484 487 $a = explode(' ', $line); 485 if ($line[0] =="*") {486 while ( list($k, $w) = each($a)) {487 if ($w !='*' && $w!='CAPABILITY') {488 if ($line[0] == '*') { 489 while (list($k, $w) = each($a)) { 490 if ($w != '*' && $w != 'CAPABILITY') { 488 491 $conn->capability[] = $w; 489 492 } … … 494 497 } 495 498 } 496 } while ($a[0] !="cp01");497 } 498 499 if (strcasecmp($auth_method, "auth") == 0) {499 } while ($a[0] != 'cp01'); 500 } 501 502 if (strcasecmp($auth_method, 'auth') == 0) { 500 503 $conn->message .= "Trying CRAM-MD5\n"; 504 501 505 //do CRAM-MD5 authentication 502 506 fputs($conn->fp, "a000 AUTHENTICATE CRAM-MD5\r\n"); 503 507 $line = trim(chop(iil_ReadLine($conn->fp, 1024))); 504 508 505 $conn->message .="$line\n";509 $conn->message .= "$line\n"; 506 510 507 if ($line[0] == "+") {508 $conn->message .= 'Got challenge: ' . htmlspecialchars($line) ."\n";511 if ($line[0] == '+') { 512 $conn->message .= 'Got challenge: ' . htmlspecialchars($line) . "\n"; 509 513 510 514 //got a challenge string, try CRAM-5 … … 761 765 } 762 766 //explode, take good parts 763 $a =explode(' ',$str);767 $a = explode(' ', $str); 764 768 765 769 $month_str = $a[1]; … … 791 795 $field = 'ARRIVAL'; 792 796 } 793 $fields = array('ARRIVAL' =>1,'CC'=>1,'DATE'=>1,'FROM'=>1,'SIZE'=>1,794 'SUBJECT'=>1,'TO'=>1);797 $fields = array('ARRIVAL' => 1,'CC' => 1,'DATE' => 1, 798 'FROM' => 1, 'SIZE' => 1, 'SUBJECT' => 1, 'TO' => 1); 795 799 796 800 if (!$fields[$field]) { … … 804 808 } 805 809 806 $fp = $conn->fp; 807 $command = 's '. $is_uid .'SORT ('.$field.') '.$encoding.' ALL'."$add\r\n"; 808 $line = $data = ''; 810 $fp = $conn->fp; 811 $command = 's ' . $is_uid . 'SORT (' . $field . ') '; 812 $command .= $encoding . ' ALL' . "$add\r\n"; 813 $line = $data = ''; 809 814 810 815 if (!fputs($fp, $command)) { … … 943 948 944 949 $key = 'fhi' . ($c++); 945 $request = $key ." FETCH $message_set (INTERNALDATE)\r\n";950 $request = $key . " FETCH $message_set (INTERNALDATE)\r\n"; 946 951 if (!fputs($fp, $request)) { 947 952 return false; … … 1015 1020 1016 1021 //check number of elements... 1017 list($start_mid, $end_mid) = explode(':', $message_set);1022 list($start_mid, $end_mid) = explode(':', $message_set); 1018 1023 if (is_numeric($start_mid) && is_numeric($end_mid)) { 1019 1024 //count how many we should have … … 1021 1026 1022 1027 //if we have less, try and fill in the "gaps" 1023 if (count($result) <$should_have) {1024 for ($i=$start_mid; $i<=$end_mid;$i++) {1028 if (count($result) < $should_have) { 1029 for ($i=$start_mid; $i<=$end_mid; $i++) { 1025 1030 if (!isset($result[$i])) { 1026 1031 $result[$i] = ''; … … 1029 1034 } 1030 1035 } 1031 1032 1036 return $result; 1033 1034 1037 } 1035 1038 … … 1049 1052 1050 1053 //separate, then sort 1051 $ids = explode(',', $message_set);1054 $ids = explode(',', $message_set); 1052 1055 sort($ids); 1053 1056 1054 1057 $result = array(); 1055 $start = $prev = $ids[0]; 1058 $start = $prev = $ids[0]; 1059 1056 1060 foreach ($ids as $id) { 1057 1061 $incr = $id - $prev; 1058 if ($incr >1) { //found a gap1059 if ($start ==$prev) {1062 if ($incr > 1) { //found a gap 1063 if ($start == $prev) { 1060 1064 $result[] = $prev; //push single id 1061 1065 } else { 1062 $result[] = $start .':'.$prev;//push sequence as start_id:end_id1066 $result[] = $start . ':' . $prev; //push sequence as start_id:end_id 1063 1067 } 1064 1068 $start = $id; //start of new sequence … … 1081 1085 return array(); 1082 1086 } 1083 return iil_C_Search($conn, $mailbox, "UID ".implode(",", $uids));1087 return iil_C_Search($conn, $mailbox, 'UID ' . implode(',', $uids)); 1084 1088 } 1085 1089 1086 1090 function iil_C_UIDToMID(&$conn, $mailbox, $uid) { 1087 1091 $result = iil_C_UIDsToMIDs($conn, $mailbox, array($uid)); 1088 if (count($result) ==1) {1092 if (count($result) == 1) { 1089 1093 return $result[0]; 1090 1094 } … … 1120 1124 1121 1125 //make sure number of messages were the same 1122 if ($cache_good >0 && $data['n']!=$num) {1126 if ($cache_good > 0 && $data['n'] != $num) { 1123 1127 $cache_good = -2; 1124 1128 } 1125 1129 1126 1130 //if everything's okay so far... 1127 if ($cache_good >0) {1131 if ($cache_good > 0) { 1128 1132 //check UIDs of highest mid with current and cached 1129 1133 $temp = iil_C_Search($conn, $mailbox, 'UID ' . $data['d'][$num]); … … 1134 1138 1135 1139 //if cached data's good, return it 1136 if ($cache_good >0) {1140 if ($cache_good > 0) { 1137 1141 return $data['d']; 1138 1142 } … … 1219 1223 $new_thhd->id = $a[1]; 1220 1224 do { 1221 $line =chop(iil_ReadLine($fp, 1024),"\r\n");1225 $line = chop(iil_ReadLine($fp, 1024), "\r\n"); 1222 1226 if (iil_StartsWithI($line, 'Message-ID:') 1223 1227 || (iil_StartsWithI($line,'In-Reply-To:')) 1224 1228 || (iil_StartsWithI($line,'SUBJECT:'))) { 1225 $pos = strpos($line, ":"); 1229 1230 $pos = strpos($line, ':'); 1226 1231 $field_name = substr($line, 0, $pos); 1227 $field_val = substr($line, $pos+1); 1232 $field_val = substr($line, $pos+1); 1233 1228 1234 $new[strtoupper($field_name)] = trim($field_val); 1235 1229 1236 } else if (ereg('^[[:space:]]', $line)) { 1230 $new[strtoupper($field_name)] .= trim($line);1237 $new[strtoupper($field_name)] .= trim($line); 1231 1238 } 1232 1239 } while ($line[0] != ')'); … … 1302 1309 // 'IN-REPLY-TO'=>$header['r'], 'SUBJECT'=>$header['s']); 1303 1310 $id = $header->id; 1304 $new = array('id' =>$id, 'MESSAGE-ID'=>$header->mid,1305 'IN-REPLY-TO' =>$header->irt, 'SUBJECT'=>$header->sbj);1311 $new = array('id' => $id, 'MESSAGE-ID' => $header->mid, 1312 'IN-REPLY-TO' => $header->irt, 'SUBJECT' => $header->sbj); 1306 1313 1307 1314 /* add to message-id -> mid lookup table */ … … 1344 1351 $sub_mids[$new['MESSAGE-ID']] = $root_id; 1345 1352 $result[$root_id][] = $id; 1346 }else if (!isset($roots[$sbj]) ||(!$has_re&&$root_in_root[$root_id])) {1353 }else if (!isset($roots[$sbj]) || (!$has_re && $root_in_root[$root_id])) { 1347 1354 /* try to use In-Reply-To header to find root 1348 1355 unless subject contains 'Re:' */ … … 1387 1394 //now that we've gone through all the messages, 1388 1395 //go back and try and link up the stray threads 1389 if (count($strays) >0) {1396 if (count($strays) > 0) { 1390 1397 foreach ($strays as $id=>$irt) { 1391 1398 $root_id = $sub_mids[$irt]; … … 1453 1460 //sort by key, this basically sorts all threads 1454 1461 ksort($itree); 1455 $i =0;1456 $out =array();1462 $i = 0; 1463 $out = array(); 1457 1464 foreach ($itree as $k=>$node) { 1458 1465 $out[$i] = $itree[$k]; … … 1659 1666 */ 1660 1667 $command_key = 'fh' . ($c++); 1661 $request = $command_key . $prefix;1662 $request .= " FETCH $message_set (UID RFC822.SIZE FLAGS INTERNALDATE)\r\n";1668 $request = $command_key . $prefix; 1669 $request .= " FETCH $message_set (UID RFC822.SIZE FLAGS INTERNALDATE)\r\n"; 1663 1670 1664 1671 if (!fputs($fp, $request)) { … … 1700 1707 // process flags 1701 1708 $flags_str = eregi_replace('[\\\"]', '', $flags_str); 1702 $flags_a = explode(' ', $flags_str); 1703 //echo "<!-- ID: $id FLAGS: ".implode(",", $flags_a)." //-->\n"; 1709 $flags_a = explode(' ', $flags_str); 1710 1711 /* 1712 trigger_error("<!-- ID: $id FLAGS: ".implode(",", $flags_a)." //-->\n", 1713 E_USER_WARNING); 1714 */ 1704 1715 1705 1716 if (is_array($flags_a)) { … … 1789 1800 1790 1801 $c=count($a); 1791 if ($c >0) {1802 if ($c > 0) { 1792 1803 /* 1793 1804 Strategy: … … 1839 1850 $fp = $conn->fp; 1840 1851 if (iil_C_Select($conn, $mailbox)) { 1841 $c =0;1852 $c = 0; 1842 1853 fputs($fp, "exp1 EXPUNGE\r\n"); 1843 1854 do { … … 1878 1889 1879 1890 if (iil_C_Select($conn, $mailbox)) { 1880 $c =0;1891 $c = 0; 1881 1892 fputs($fp, "flg STORE $messages " . $mod . "FLAGS (" . $flag . ")\r\n"); 1882 1893 do { … … 1993 2004 $fp = $conn->fp; 1994 2005 if (iil_C_Select($conn, $folder)) { 1995 $c =0;2006 $c = 0; 1996 2007 1997 2008 $query = 'srch1 SEARCH ' . chop($criteria) . "\r\n"; … … 2003 2014 $messages = explode(' ', $str); 2004 2015 } 2005 } while (!iil_StartsWith($line, "srch1"));2016 } while (!iil_StartsWith($line, 'srch1')); 2006 2017 2007 $result_code =iil_ParseResult($line);2008 if ($result_code ==0) {2018 $result_code = iil_ParseResult($line); 2019 if ($result_code == 0) { 2009 2020 return $messages; 2010 2021 } … … 2024 2035 } 2025 2036 2026 $r =iil_C_Copy($conn, $messages, $from,$to);2037 $r = iil_C_Copy($conn, $messages, $from,$to); 2027 2038 if ($r==0) { 2028 2039 return iil_C_Delete($conn, $from, $messages); … … 2238 2249 $query = 'sub1 SUBSCRIBE "' . $folder. '"' . "\r\n"; 2239 2250 fputs($fp, $query); 2251 2240 2252 $line = trim(chop(iil_ReadLine($fp, 10000))); 2241 2253 return iil_ParseResult($line); … … 2268 2280 if (!fputs($fp, $request)) return false; 2269 2281 do { 2270 $line =chop(iil_ReadLine($fp, 200));2271 $a =explode(' ', $line);2282 $line = chop(iil_ReadLine($fp, 200)); 2283 $a = explode(' ', $line); 2272 2284 if (($line[0] == '*') && ($a[2] == 'FETCH') 2273 2285 && ($line[strlen($line)-1] != ')')) { 2274 2286 $line=iil_ReadLine($fp, 300); 2275 while (chop($line) !=")") {2276 $result .=$line;2287 while (chop($line) != ')') { 2288 $result .= $line; 2277 2289 $line=iil_ReadLine($fp, 300); 2278 2290 } 2279 2291 } 2280 } while (strcmp($a[0], $key) !=0);2292 } while (strcmp($a[0], $key) != 0); 2281 2293 } 2282 2294 … … 2293 2305 $fp = $conn->fp; 2294 2306 $result = false; 2295 if (($part ==0) || (empty($part))) {2307 if (($part == 0) || empty($part)) { 2296 2308 $part = 'TEXT'; 2297 2309 } 2298 2310 2299 2311 if (iil_C_Select($conn, $mailbox)) { 2300 $reply_key ='* ' . $id;2312 $reply_key = '* ' . $id; 2301 2313 2302 2314 // format request … … 2343 2355 } 2344 2356 $received += strlen($line); 2345 if ($mode ==1) {2346 $result .= chop($line) ."\n";2347 } else if ($mode ==2) {2348 echo chop($line) ."\n"; flush();2349 } else if ($mode ==3) {2357 if ($mode == 1) { 2358 $result .= chop($line) . "\n"; 2359 } else if ($mode == 2) { 2360 echo chop($line) . "\n"; flush(); 2361 } else if ($mode == 3) { 2350 2362 echo base64_decode($line); flush(); 2351 2363 } … … 2400 2412 if (fputs($fp, 'r RENAME "' . $from . '" "' . $to . '"' . "\r\n")) { 2401 2413 do { 2402 $line =iil_ReadLine($fp, 300);2403 } while ($line[0] !="r");2414 $line = iil_ReadLine($fp, 300); 2415 } while ($line[0] != 'r'); 2404 2416 return (iil_ParseResult($line) == 0); 2405 2417 } 2406 return false; 2418 return false; 2407 2419 } 2408 2420 … … 2412 2424 do { 2413 2425 $line=iil_ReadLine($fp, 300); 2414 } while ($line[0] !="d");2426 } while ($line[0] != 'd'); 2415 2427 return (iil_ParseResult($line) == 0); 2416 2428 } … … 2420 2432 2421 2433 function iil_C_Append(&$conn, $folder, &$message) { 2422 if (!$folder) return false; 2434 if (!$folder) { 2435 return false; 2436 } 2423 2437 $fp = $conn->fp; 2424 2438 … … 2427 2441 2428 2442 $len = strlen($message); 2429 if (!$len) return false; 2430 2443 if (!$len) { 2444 return false; 2445 } 2431 2446 $request = 'A APPEND "' . $folder .'" (\\Seen) {' . $len . "}\r\n"; 2432 2447 … … 2476 2491 $bytes_sent = 0; 2477 2492 if (fputs($fp, $request)) { 2478 $line =iil_ReadLine($fp, 100);2493 $line = iil_ReadLine($fp, 100); 2479 2494 2480 2495 //send file 2481 2496 while (!feof($in_fp)) { 2482 $buffer = fgets($in_fp, 4096);2497 $buffer = fgets($in_fp, 4096); 2483 2498 $bytes_sent += strlen($buffer); 2484 2499 fputs($fp, $buffer); … … 2490 2505 //read response 2491 2506 do { 2492 $line =iil_ReadLine($fp, 1000);2507 $line = iil_ReadLine($fp, 1000); 2493 2508 } while ($line[0] != 'A'); 2494 2509 … … 2534 2549 $result = substr($post, 0, strlen($post)-1); 2535 2550 } 2536 } while (!preg_match("/^$key/", $line));2551 } while (!preg_match("/^$key/", $line)); 2537 2552 } 2538 2553 } … … 2570 2585 //return false if not found, parse if found 2571 2586 if (!empty($quota_line)) { 2572 $quota_line = eregi_replace('[()]', '', $quota_line);2573 $parts = explode(' ', $quota_line);2587 $quota_line = eregi_replace('[()]', '', $quota_line); 2588 $parts = explode(' ', $quota_line); 2574 2589 $storage_part = array_search('STORAGE', $parts); 2575 if ($storage_part >0) {2590 if ($storage_part > 0) { 2576 2591 $result = array(); 2577 2592 $used = $parts[$storage_part+1]; … … 2584 2599 } 2585 2600 } 2586 2587 2601 return $result; 2588 2602 } … … 2596 2610 return (iil_C_Expunge($conn, $folder) >= 0); 2597 2611 } 2598 2599 2612 ?>
Note: See TracChangeset
for help on using the changeset viewer.
