Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/ManageSieve/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ private function initExpressions() {

private function getSingleLine() {
$pos = strpos($this->readBuffer, "\r\n");
if ($pos === false) {
throw new \RuntimeException("Incomplete line in buffer, waiting for more data.");
}
$return = substr($this->readBuffer, 0, $pos);
return [$return, $pos];
}
Expand Down Expand Up @@ -103,10 +106,16 @@ private function readLine() {

try {
$nval = \fread($this->sock, $this->readSize);
$meta = stream_get_meta_data($this->sock);
if ($meta['timed_out']) {
throw new SocketException("Connection timed out while reading from the server.");
}
if ($nval === false || $nval === "") {
break;
}
$this->readBuffer .= $nval;
} catch (SocketException $e) {
throw $e;
} catch (\Exception $e) {
throw new SocketException("Failed to read data from the server.");
}
Expand Down Expand Up @@ -656,6 +665,7 @@ public function connect($username, $password, $tls=false, $authz_id="", $auth_me
throw new SocketException("Socket creation failed: " . $errorstr);
}

stream_set_timeout($this->sock, $this->readTimeout);
$this->connected = true;
self::$connectionPool[$connectionKey] = $this->sock;
if (!$this->getCapabilitiesFromServer()) {
Expand Down