public function onRead()
{
while (($rawLine = $this->readLine(\EventBuffer::EOL_CRLF_STRICT)) !== null) {
if ($this->blobOctetsLeft > 0) {
$this->blob .= $rawLine . "\r\n";
$this->blobOctetsLeft -= strlen($rawLine) + 2;
continue;
}
if (preg_match('~\\{([0-9]+)\\}$~', $rawLine, $matches)) {
$this->blob = '';
$this->blobOctetsLeft = $matches[1];
}
@(list($tag, $line) = @explode(' ', $rawLine, 2));
@(list($type, $restLine) = @explode(' ', $line, 2));
if ($this->state == self::STATE_CONNECTING) {
if ($this->startsWith($rawLine, '* OK')) {
$this->state = self::STATE_CONNECTED;
$this->connected = true;
} else {
$this->log("IMAP hello failed");
$this->finish();
return;
}
if ($this->onConnected) {
$this->onConnected->executeAll($this->connected ? $this : false);
$this->onConnected = null;
}
return;
} elseif ($this->state != self::STATE_CONNECTING) {
if ($tag === '*') {
$this->lines[] = $line;
continue;
}
if (!in_array($type, ['OK', 'BAD', 'NO'])) {
$this->lines[] = $rawLine;
continue;
}
$this->lines[] = $line;
$this->onCommand($tag, $type, $line, $this->lines, $this->blob);
$this->lines = [];
}
}
}