partialParseResponseBranch broken due to previous commit

This commit is contained in:
the-djmaze 2022-12-19 10:44:25 +01:00
parent 8b65b6ee7c
commit a78fcb6308

View file

@ -66,6 +66,8 @@ trait ResponseParser
return !$oImapResponse->IsStatusResponse || 2 < \count($oImapResponse->ResponseList); return !$oImapResponse->IsStatusResponse || 2 < \count($oImapResponse->ResponseList);
} }
private $sResponseBuffer = '';
/** /**
* @return array|string * @return array|string
* @throws \MailSo\RuntimeException * @throws \MailSo\RuntimeException
@ -91,12 +93,10 @@ trait ResponseParser
$aList =& $oImapResponse->ResponseList; $aList =& $oImapResponse->ResponseList;
} }
$sResponseBuffer = '';
while (true) { while (true) {
if ($this->bNeedNext) { if ($this->bNeedNext) {
$iPos = 0; $iPos = 0;
$sResponseBuffer = $this->getNextBuffer(); $this->sResponseBuffer = $this->getNextBuffer();
$this->iResponseBufParsedPos = $iPos; $this->iResponseBufParsedPos = $iPos;
$this->bNeedNext = false; $this->bNeedNext = false;
} }
@ -105,13 +105,13 @@ trait ResponseParser
if ($bIsGotoDefault) { if ($bIsGotoDefault) {
$bIsGotoDefault = false; $bIsGotoDefault = false;
} else { } else {
$iBufferEndIndex = \strlen($sResponseBuffer) - 3; $iBufferEndIndex = \strlen($this->sResponseBuffer) - 3;
if ($iPos > $iBufferEndIndex) { if ($iPos > $iBufferEndIndex) {
break; break;
} }
$sChar = $sResponseBuffer[$iPos]; $sChar = $this->sResponseBuffer[$iPos];
} }
switch ($sChar) switch ($sChar)
@ -159,13 +159,13 @@ trait ResponseParser
continue 2; continue 2;
case '~': // literal8 case '~': // literal8
if ('{' !== $sResponseBuffer[++$iPos]) { if ('{' !== $this->sResponseBuffer[++$iPos]) {
break; break;
} }
case '{': case '{':
$iLength = \strspn($sResponseBuffer, '0123456789', $iPos + 1); $iLength = \strspn($this->sResponseBuffer, '0123456789', $iPos + 1);
if ($iLength && "}\r\n" === \substr($sResponseBuffer, $iPos + 1 + $iLength, 3)) { if ($iLength && "}\r\n" === \substr($this->sResponseBuffer, $iPos + 1 + $iLength, 3)) {
$iLiteralLen = (int) \substr($sResponseBuffer, $iPos + 1, $iLength); $iLiteralLen = (int) \substr($this->sResponseBuffer, $iPos + 1, $iLength);
$iPos += 4 + $iLength; $iPos += 4 + $iLength;
if ($this->partialResponseLiteralCallbacks($sParentToken, $sPreviousAtomUpperCase, $iLiteralLen)) { if ($this->partialResponseLiteralCallbacks($sParentToken, $sPreviousAtomUpperCase, $iLiteralLen)) {
@ -209,13 +209,13 @@ trait ResponseParser
$iPos = $iBufferEndIndex; $iPos = $iBufferEndIndex;
break; break;
} }
$iLength = \strcspn($sResponseBuffer, "\r\n\\\"", $iOffset); $iLength = \strcspn($this->sResponseBuffer, "\r\n\\\"", $iOffset);
$sSpecial = $sResponseBuffer[$iOffset + $iLength]; $sSpecial = $this->sResponseBuffer[$iOffset + $iLength];
switch ($sSpecial) switch ($sSpecial)
{ {
case '\\': case '\\':
// Is escaped character \ or "? // Is escaped character \ or "?
if (!\in_array($sResponseBuffer[$iOffset + $iLength + 1], ['\\','"'])) { if (!\in_array($this->sResponseBuffer[$iOffset + $iLength + 1], ['\\','"'])) {
// No, not allowed in quoted string // No, not allowed in quoted string
break 2; break 2;
} }
@ -224,9 +224,9 @@ trait ResponseParser
case '"': case '"':
if ($bTreatAsAtom) { if ($bTreatAsAtom) {
$sAtomBuilder .= \stripslashes(\substr($sResponseBuffer, $iPos, $iOffset + $iLength - $iPos + 1)); $sAtomBuilder .= \stripslashes(\substr($this->sResponseBuffer, $iPos, $iOffset + $iLength - $iPos + 1));
} else { } else {
$aList[] = \stripslashes(\substr($sResponseBuffer, $iPos + 1, $iOffset + $iLength - $iPos - 1)); $aList[] = \stripslashes(\substr($this->sResponseBuffer, $iPos + 1, $iOffset + $iLength - $iPos - 1));
} }
$iPos = $iOffset + $iLength + 1; $iPos = $iOffset + $iLength + 1;
break 2; break 2;
@ -234,7 +234,7 @@ trait ResponseParser
default: default:
case "\r": case "\r":
case "\n": case "\n":
\SnappyMail\Log::notice('IMAP', 'Invalid char in quoted string: "' . \substr($sResponseBuffer, $iPos, $iOffset + $iLength - $iPos) . '"'); \SnappyMail\Log::notice('IMAP', 'Invalid char in quoted string: "' . \substr($this->sResponseBuffer, $iPos, $iOffset + $iLength - $iPos) . '"');
// Not allowed in quoted string // Not allowed in quoted string
break 2; break 2;
} }
@ -248,12 +248,12 @@ trait ResponseParser
if ($bRoot && $oImapResponse->IsStatusResponse) { if ($bRoot && $oImapResponse->IsStatusResponse) {
$iPos = $iBufferEndIndex; $iPos = $iBufferEndIndex;
if ($iPos > $iCharBlockStartPos) { if ($iPos > $iCharBlockStartPos) {
$iCharBlockStartPos += \strspn($sResponseBuffer, ' ', $iCharBlockStartPos, $iPos - $iCharBlockStartPos); $iCharBlockStartPos += \strspn($this->sResponseBuffer, ' ', $iCharBlockStartPos, $iPos - $iCharBlockStartPos);
} }
} }
while ($iPos <= $iBufferEndIndex) { while ($iPos <= $iBufferEndIndex) {
$sCharDef = $sResponseBuffer[$iPos]; $sCharDef = $this->sResponseBuffer[$iPos];
switch (true) switch (true)
{ {
case $bRoot && ('[' === $sCharDef || ']' === $sCharDef) && static::skipSquareBracketParse($oImapResponse): case $bRoot && ('[' === $sCharDef || ']' === $sCharDef) && static::skipSquareBracketParse($oImapResponse):
@ -264,7 +264,7 @@ trait ResponseParser
$sAtomBuilder = ''; $sAtomBuilder = '';
} }
$sAtomBuilder .= \substr($sResponseBuffer, $iCharBlockStartPos, $iPos - $iCharBlockStartPos + 1); $sAtomBuilder .= \substr($this->sResponseBuffer, $iCharBlockStartPos, $iPos - $iCharBlockStartPos + 1);
$this->iResponseBufParsedPos = ++$iPos; $this->iResponseBufParsedPos = ++$iPos;
@ -291,7 +291,7 @@ trait ResponseParser
} }
if ($iPos > $iCharBlockStartPos || null !== $sAtomBuilder) { if ($iPos > $iCharBlockStartPos || null !== $sAtomBuilder) {
$sLastCharBlock = \substr($sResponseBuffer, $iCharBlockStartPos, $iPos - $iCharBlockStartPos); $sLastCharBlock = \substr($this->sResponseBuffer, $iCharBlockStartPos, $iPos - $iCharBlockStartPos);
if (null === $sAtomBuilder) { if (null === $sAtomBuilder) {
$aList[] = 'NIL' === $sLastCharBlock ? null : $sLastCharBlock; $aList[] = 'NIL' === $sLastCharBlock ? null : $sLastCharBlock;
$sPreviousAtomUpperCase = \strtoupper($sLastCharBlock); $sPreviousAtomUpperCase = \strtoupper($sLastCharBlock);