Skip to content

Commit 601cb7d

Browse files
authored
Merge pull request #11 from josaphatim/handle-edge-error-cases
[FIX] Handled edge cases exception for email providers that does not support script inclusion
2 parents 7cf3123 + df4119e commit 601cb7d

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/ManageSieve/Client.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ private function initExpressions() {
6262
$this->activeExpression = "#ACTIVE#";
6363
}
6464

65+
private function getSingleLine() {
66+
$pos = strpos($this->readBuffer, "\r\n");
67+
$return = substr($this->readBuffer, 0, $pos);
68+
return [$return, $pos];
69+
}
70+
6571
/**
6672
* Read line from the server
6773
*
@@ -75,8 +81,7 @@ private function readLine() {
7581
while (true) {
7682
try {
7783
if ($this->readBuffer != null) {
78-
$pos = strpos($this->readBuffer, "\r\n");
79-
$return = substr($this->readBuffer, 0, $pos);
84+
list($return, $pos) = $this->getSingleLine();
8085
$this->readBuffer = substr($this->readBuffer, $pos + strlen("\r\n"));
8186
break;
8287
}
@@ -172,7 +177,13 @@ private function parseError($text) {
172177
preg_match($this->sizeExpression, $text, $matches);
173178
if ($matches) {
174179
$this->errorCode = "";
175-
$this->errorMessage = $this->readBlock($matches[1] + 2);
180+
$errorMessage = $matches[1] + 2;
181+
list($nextLine, $_) = $this->getSingleLine();
182+
if (preg_match('/^\d+$/', trim($errorMessage)) && preg_match('/error:/i', $nextLine)) {
183+
$this->errorMessage = $nextLine;
184+
} else {
185+
$this->errorMessage = $this->readBlock($errorMessage);
186+
}
176187
return;
177188
}
178189

0 commit comments

Comments
 (0)