From df4119eb4206f8c47c5a85d9344ae2276c1dd45a Mon Sep 17 00:00:00 2001 From: Josaphat Imani Date: Wed, 1 May 2024 18:28:01 +0200 Subject: [PATCH] [FIX] Handled edge cases exception for email providers that does not support including scripts --- src/ManageSieve/Client.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/ManageSieve/Client.php b/src/ManageSieve/Client.php index 6d4ebd2..26f3f65 100644 --- a/src/ManageSieve/Client.php +++ b/src/ManageSieve/Client.php @@ -62,6 +62,12 @@ private function initExpressions() { $this->activeExpression = "#ACTIVE#"; } + private function getSingleLine() { + $pos = strpos($this->readBuffer, "\r\n"); + $return = substr($this->readBuffer, 0, $pos); + return [$return, $pos]; + } + /** * Read line from the server * @@ -75,8 +81,7 @@ private function readLine() { while (true) { try { if ($this->readBuffer != null) { - $pos = strpos($this->readBuffer, "\r\n"); - $return = substr($this->readBuffer, 0, $pos); + list($return, $pos) = $this->getSingleLine(); $this->readBuffer = substr($this->readBuffer, $pos + strlen("\r\n")); break; } @@ -172,7 +177,13 @@ private function parseError($text) { preg_match($this->sizeExpression, $text, $matches); if ($matches) { $this->errorCode = ""; - $this->errorMessage = $this->readBlock($matches[1] + 2); + $errorMessage = $matches[1] + 2; + list($nextLine, $_) = $this->getSingleLine(); + if (preg_match('/^\d+$/', trim($errorMessage)) && preg_match('/error:/i', $nextLine)) { + $this->errorMessage = $nextLine; + } else { + $this->errorMessage = $this->readBlock($errorMessage); + } return; }