| | |
| | | - iil_C_HandlePartBody(): added 6th argument and fixed endless loop |
| | | - added iil_PutLineC() |
| | | - fixed iil_C_Sort() to support very long and/or divided responses |
| | | - added BYE response simple support for endless loop prevention |
| | | - added 3rd argument in iil_StartsWith* functions |
| | | |
| | | ********************************************************/ |
| | | |
| | |
| | | return -1; |
| | | } else if (strcasecmp($a[1], 'BAD') == 0) { |
| | | return -2; |
| | | } else if (strcasecmp($a[1], 'BYE') == 0) { |
| | | return -3; |
| | | } |
| | | } |
| | | return -3; |
| | | return -4; |
| | | } |
| | | |
| | | // check if $string starts with $match |
| | | function iil_StartsWith($string, $match) { |
| | | function iil_StartsWith($string, $match, $bye=false) { |
| | | $len = strlen($match); |
| | | if ($len == 0) { |
| | | return false; |
| | |
| | | if (strncmp($string, $match, $len) == 0) { |
| | | return true; |
| | | } |
| | | if ($bye && strncmp($string, '* BYE ', 6) == 0) { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | function iil_StartsWithI($string, $match) { |
| | | function iil_StartsWithI($string, $match, $bye=false) { |
| | | $len = strlen($match); |
| | | if ($len == 0) { |
| | | return false; |
| | | } |
| | | if (strncasecmp($string, $match, $len) == 0) { |
| | | return true; |
| | | } |
| | | if ($bye && strncmp($string, '* BYE ', 6) == 0) { |
| | | return true; |
| | | } |
| | | return false; |
| | |
| | | $line = iil_ReadLine($conn->fp, 1024); |
| | | |
| | | // process result |
| | | if (iil_ParseResult($line) == 0) { |
| | | $result = iil_ParseResult($line); |
| | | if ($result == 0) { |
| | | $conn->error .= ''; |
| | | $conn->errorNum = 0; |
| | | return $conn->fp; |
| | | } |
| | | |
| | | if ($result == -3) fclose($conn->fp); // BYE response |
| | | |
| | | $conn->error .= 'Authentication for ' . $user . ' failed (AUTH): "'; |
| | | $conn->error .= htmlspecialchars($line) . '"'; |
| | | $conn->errorNum = -2; |
| | | return false; |
| | | $conn->errorNum = $result; |
| | | |
| | | return $result; |
| | | } |
| | | |
| | | function iil_C_Login(&$conn, $user, $password) { |
| | |
| | | if ($line === false) { |
| | | break; |
| | | } |
| | | } while (!iil_StartsWith($line, "a001 ")); |
| | | $a = explode(' ', $line); |
| | | if (strcmp($a[1], 'OK') == 0) { |
| | | $result = $conn->fp; |
| | | } while (!iil_StartsWith($line, 'a001 ', true)); |
| | | |
| | | // process result |
| | | $result = iil_ParseResult($line); |
| | | |
| | | if ($result == 0) { |
| | | $conn->error .= ''; |
| | | $conn->errorNum = 0; |
| | | return $result; |
| | | return $conn->fp; |
| | | } |
| | | $result = false; |
| | | |
| | | fclose($conn->fp); |
| | | |
| | | $conn->error .= 'Authentication for ' . $user . ' failed (LOGIN): "'; |
| | | $conn->error .= htmlspecialchars($line)."\""; |
| | | $conn->errorNum = -2; |
| | | $conn->errorNum = $result; |
| | | |
| | | return $result; |
| | | } |
| | |
| | | $i = 0; |
| | | $data = iil_ParseNamespace2(substr($line,11), $i, 0, 0); |
| | | } |
| | | } while (!iil_StartsWith($line, "ns1")); |
| | | } while (!iil_StartsWith($line, 'ns1', true)); |
| | | |
| | | if (!is_array($data)) { |
| | | return false; |
| | |
| | | |
| | | $iil_error = ''; |
| | | $iil_errornum = 0; |
| | | |
| | | //strip slashes |
| | | // $user = stripslashes($user); |
| | | // $password = stripslashes($password); |
| | | |
| | | //set auth method |
| | | $auth_method = 'plain'; |
| | |
| | | |
| | | //check input |
| | | if (empty($host)) { |
| | | $iil_error .= "Invalid host\n"; |
| | | $iil_error = "Empty host"; |
| | | $iil_errornum = -1; |
| | | return false; |
| | | } |
| | | if (empty($user)) { |
| | | $iil_error .= "Invalid user\n"; |
| | | $iil_error = "Empty user"; |
| | | $iil_errornum = -1; |
| | | return false; |
| | | } |
| | | if (empty($password)) { |
| | | $iil_error .= "Invalid password\n"; |
| | | } |
| | | if (!empty($iil_error)) { |
| | | $iil_error = "Empty password"; |
| | | $iil_errornum = -1; |
| | | return false; |
| | | } |
| | | if (!$ICL_PORT) { |
| | |
| | | |
| | | //got a challenge string, try CRAM-5 |
| | | $result = iil_C_Authenticate($conn, $user, $password, substr($line,2)); |
| | | |
| | | |
| | | // stop if server sent BYE response |
| | | if($result == -3) { |
| | | $iil_error = $conn->error; |
| | | $iil_errornum = $conn->errorNum; |
| | | return false; |
| | | } |
| | | $conn->message .= "Tried CRAM-MD5: $result \n"; |
| | | } else { |
| | | $conn->message .='No challenge ('.htmlspecialchars($line)."), try plain\n"; |
| | |
| | | if ((!$result)||(strcasecmp($auth, "plain") == 0)) { |
| | | //do plain text auth |
| | | $result = iil_C_Login($conn, $user, $password); |
| | | $conn->message.="Tried PLAIN: $result \n"; |
| | | $conn->message .= "Tried PLAIN: $result \n"; |
| | | } |
| | | |
| | | $conn->message .= $auth; |
| | | |
| | | if ($result) { |
| | | if (!is_int($result)) { |
| | | iil_C_Namespace($conn); |
| | | return $conn; |
| | | } else { |
| | |
| | | $a=explode(' ', $line); |
| | | if (($a[0] == '*') && (strcasecmp($a[2], 'RECENT') == 0)) { |
| | | $result = (int) $a[1]; |
| | | } |
| | | } while (!iil_StartsWith($a[0], 'a002')); |
| | | } |
| | | } while (!iil_StartsWith($a[0], 'a002', true)); |
| | | |
| | | iil_PutLine($fp, "a003 LOGOUT"); |
| | | fclose($fp); |
| | |
| | | else if (preg_match('/\[?PERMANENTFLAGS\s+\(([^\)]+)\)\]/U', $line, $match)) { |
| | | $conn->permanentflags = explode(' ', $match[1]); |
| | | } |
| | | } while (!iil_StartsWith($line, 'sel1')); |
| | | } while (!iil_StartsWith($line, 'sel1', true)); |
| | | |
| | | $a = explode(' ', $line); |
| | | |
| | |
| | | |
| | | function iil_StrToTime($str) { |
| | | $IMAP_MONTHS = $GLOBALS['IMAP_MONTHS']; |
| | | $IMAP_SERVER_TZ = $GLOBALS['IMAP_SERVER_TR']; |
| | | $IMAP_SERVER_TZ = $GLOBALS['IMAP_SERVER_TZ']; |
| | | |
| | | if ($str) { |
| | | $time1 = strtotime($str); |
| | |
| | | } else if (preg_match('/^[0-9 ]+$/', $line)) { |
| | | $data .= $line; |
| | | } |
| | | } while ($line[0]!='s'); |
| | | } while (!iil_StartsWith($line, 's ', true)); |
| | | |
| | | if (empty($data)) { |
| | | $conn->error = $line; |
| | |
| | | //one line response, not expected so ignore |
| | | } |
| | | */ |
| | | } while (!iil_StartsWith($line, $key)); |
| | | } while (!iil_StartsWith($line, $key, true)); |
| | | |
| | | }else if ($mode == 6) { |
| | | |
| | |
| | | } else { |
| | | $a = explode(' ', $line); |
| | | } |
| | | } while (!iil_StartsWith($a[0], $key)); |
| | | } while (!iil_StartsWith($a[0], $key, true)); |
| | | } else { |
| | | if ($mode >= 3) { |
| | | $field_name = 'FLAGS'; |
| | |
| | | $result[$id] = (strpos($haystack, $index_field) > 0 ? "F" : "N"); |
| | | } |
| | | } |
| | | } while (!iil_StartsWith($line, $key)); |
| | | } while (!iil_StartsWith($line, $key, true)); |
| | | } |
| | | |
| | | //check number of elements... |
| | |
| | | if ($line[0] == '*') { |
| | | $c++; |
| | | } |
| | | } while (!iil_StartsWith($line, 'exp1')); |
| | | } while (!iil_StartsWith($line, 'exp1', true)); |
| | | |
| | | if (iil_ParseResult($line) == 0) { |
| | | $conn->selected = ''; //state has changed, need to reselect |
| | |
| | | if ($line[0] == '*') { |
| | | $c++; |
| | | } |
| | | } while (!iil_StartsWith($line, 'flg')); |
| | | } while (!iil_StartsWith($line, 'flg', true)); |
| | | |
| | | if (iil_ParseResult($line) == 0) { |
| | | iil_C_ExpireCachedItems($conn, $mailbox, $messages); |
| | |
| | | $str = trim(substr($line, 8)); |
| | | $messages = explode(' ', $str); |
| | | } |
| | | } while (!iil_StartsWith($line, 'srch1')); |
| | | } while (!iil_StartsWith($line, 'srch1', true)); |
| | | |
| | | $result_code = iil_ParseResult($line); |
| | | if ($result_code == 0) { |
| | |
| | | $delimiter = str_replace('"', '', $a[count($a)-2]); |
| | | } |
| | | } |
| | | } while (!iil_StartsWith($line, 'ghd')); |
| | | } while (!iil_StartsWith($line, 'ghd', true)); |
| | | |
| | | if (strlen($delimiter)>0) { |
| | | return $delimiter; |
| | |
| | | $i = 0; |
| | | $data = iil_ParseNamespace2(substr($line,11), $i, 0, 0); |
| | | } |
| | | } while (!iil_StartsWith($line, 'ns1')); |
| | | } while (!iil_StartsWith($line, 'ns1', true)); |
| | | |
| | | if (!is_array($data)) { |
| | | return false; |
| | |
| | | // is it a container? |
| | | $i++; |
| | | } |
| | | } while (!iil_StartsWith($line, 'lmb')); |
| | | } while (!iil_StartsWith($line, 'lmb', true)); |
| | | |
| | | if (is_array($folders)) { |
| | | if (!empty($ref)) { |
| | |
| | | // is it a container? |
| | | $i++; |
| | | } |
| | | } while (!iil_StartsWith($line, 'lsb')); |
| | | } while (!iil_StartsWith($line, 'lsb', true)); |
| | | |
| | | if (is_array($folders)) { |
| | | if (!empty($ref)) { |
| | |
| | | $line = chop(iil_ReadLine($fp, 200)); |
| | | $a = explode(' ', $line); |
| | | if (($line[0] == '*') && ($a[2] == 'FETCH') |
| | | && ($line[strlen($line)-1] != ')')) { |
| | | && ($line[strlen($line)-1] != ')')) { |
| | | $line=iil_ReadLine($fp, 300); |
| | | while (trim($line) != ')') { |
| | | $result .= $line; |
| | | $line=iil_ReadLine($fp, 300); |
| | | } |
| | | } |
| | | } while (strcmp($a[0], $key) != 0); |
| | | } while (strcmp($a[0], $key) != 0 && ($a[0] != '*' || $a[1] != 'BYE')); |
| | | } |
| | | |
| | | return $result; |
| | |
| | | $a = explode(' ', $line); |
| | | } while ($a[2] != 'FETCH'); |
| | | $len = strlen($line); |
| | | |
| | | if ($line[$len-1] == ')') { |
| | | |
| | | // handle empty "* X FETCH ()" response |
| | | if ($line[$len-1] == ')' && $line[$len-2] != '(') { |
| | | // one line response, get everything between first and last quotes |
| | | if (substr($line, -4, 3) == 'NIL') { |
| | | // NIL response |
| | |
| | | // read in anything up until last line |
| | | do { |
| | | $line = iil_ReadLine($fp, 1024); |
| | | } while (!iil_StartsWith($line, $key)); |
| | | } while (!iil_StartsWith($line, $key, true)); |
| | | |
| | | if ($mode == 3 && $file) { |
| | | return true; |
| | |
| | | if (iil_StartsWith($line, '* QUOTA ')) { |
| | | $quota_line = $line; |
| | | } |
| | | } while (!iil_StartsWith($line, 'QUOT1')); |
| | | } while (!iil_StartsWith($line, 'QUOT1', true)); |
| | | } |
| | | |
| | | //return false if not found, parse if found |