refactor: unify response-code parsing

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-09-25 11:54:28 -04:00
parent 09d0bbd817
commit 68ca777150
3 changed files with 51 additions and 26 deletions
+13 -4
View File
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Protocol\Command;
use KTXM\ProviderImap\Client\Protocol\Parser\ResponseCodeParser;
use KTXM\ProviderImap\Client\Protocol\StringEncoder;
use KTXM\ProviderImap\Client\ImapException;
use KTXM\ProviderImap\Client\Protocol\RequestFrame;
@@ -26,6 +27,7 @@ use KTXM\ProviderImap\Client\Protocol\SessionState;
*/
final class AppendCommand implements CommandInterface
{
private readonly ResponseCodeParser $responseCodeParser;
private readonly string $literal;
/**
@@ -36,6 +38,8 @@ final class AppendCommand implements CommandInterface
string $message,
private readonly array $flags = [],
) {
$this->responseCodeParser = new ResponseCodeParser();
// IMAP literals are octet-counted; normalise to CRLF line endings.
$this->literal = (string) preg_replace('/\r\n|\r|\n/', "\r\n", $message);
}
@@ -87,13 +91,18 @@ final class AppendCommand implements CommandInterface
throw new ImapException('APPEND did not receive a tagged completion response.');
}
private function parseAppendUid(string $text): ?int
{
if (preg_match('/\[APPENDUID\s+\d+\s+(\d+)\]/i', $text, $matches) === 1) {
return (int) $matches[1];
$responseCode = $this->responseCodeParser->parse($text);
if ($responseCode === null || $responseCode['name'] !== 'APPENDUID') {
return null;
}
return null;
$arguments = $responseCode['arguments'];
if (count($arguments) !== 2 || !ctype_digit($arguments[0]) || !ctype_digit($arguments[1])) {
return null;
}
return (int) $arguments[1];
}
}