Skip to content

Commit

Permalink
Merge pull request #11 from josaphatim/handle-edge-error-cases
Browse files Browse the repository at this point in the history
[FIX] Handled edge cases exception for email providers that does not support script inclusion
  • Loading branch information
kroky authored May 2, 2024
2 parents 7cf3123 + df4119e commit 601cb7d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/ManageSieve/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 601cb7d

Please sign in to comment.