| | |
| | | return $res; |
| | | } |
| | | |
| | | return preg_replace('/{[0-9]+}\r\n/', '', $res); |
| | | return preg_replace('/^{[0-9]+}\r\n/', '', $res); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * Receives x bytes from the server. |
| | | * |
| | | * @param int $length Number of bytes to read |
| | | * |
| | | * @return string The server response. |
| | | */ |
| | | function _recvBytes($length) |
| | | { |
| | | $response = ''; |
| | | $response_length = 0; |
| | | |
| | | while ($response_length < $length) { |
| | | $response .= $this->_sock->read($length - $response_length); |
| | | $response_length = $this->_getLineLength($response); |
| | | } |
| | | |
| | | $this->_debug("S: " . rtrim($response)); |
| | | |
| | | return $response; |
| | | } |
| | | |
| | | /** |
| | | * Send a command and retrieves a response from the server. |
| | | * |
| | | * @param string $cmd The command to send. |
| | |
| | | |
| | | if ('NO' == substr($uc_line, 0, 2)) { |
| | | // Check for string literal error message. |
| | | if (preg_match('/^no {([0-9]+)\+?}/i', $line, $matches)) { |
| | | $line .= str_replace( |
| | | "\r\n", ' ', $this->_sock->read($matches[1] + 2) |
| | | ); |
| | | $this->_debug("S: $line"); |
| | | if (preg_match('/{([0-9]+)}$/i', $line, $matches)) { |
| | | $line = substr($line, 0, -(strlen($matches[1])+2)) |
| | | . str_replace( |
| | | "\r\n", ' ', $this->_recvBytes($matches[1] + 2) |
| | | ); |
| | | } |
| | | return PEAR::raiseError(trim($response . substr($line, 2)), 3); |
| | | } |
| | |
| | | return PEAR::raiseError(trim($response . $line), 6); |
| | | } |
| | | |
| | | if (preg_match('/^{([0-9]+)\+?}/i', $line, $matches)) { |
| | | // Matches String Responses. |
| | | $str_size = $matches[1] + 2; |
| | | $line = ''; |
| | | $line_length = 0; |
| | | while ($line_length < $str_size) { |
| | | $line .= $this->_sock->read($str_size - $line_length); |
| | | $line_length = $this->_getLineLength($line); |
| | | } |
| | | $this->_debug("S: $line"); |
| | | if (preg_match('/^{([0-9]+)}/i', $line, $matches)) { |
| | | // Matches literal string responses. |
| | | $line = $this->_recvBytes($matches[1] + 2); |
| | | |
| | | if (!$auth) { |
| | | // Receive the pending OK only if we aren't |
| | |
| | | |
| | | // The server should be sending a CAPABILITY response after |
| | | // negotiating TLS. Read it, and ignore if it doesn't. |
| | | $this->_doCmd(); |
| | | // Doesn't work with older timsieved versions |
| | | $regexp = '/^CYRUS TIMSIEVED V([0-9.]+)/'; |
| | | if (!preg_match($regexp, $this->_capability['implementation'], $matches) |
| | | || version_compare($matches[1], '2.3.10', '>=') |
| | | ) { |
| | | $this->_doCmd(); |
| | | } |
| | | |
| | | // RFC says we need to query the server capabilities again now that we |
| | | // are under encryption. |