diff --git a/src/Connection/ImapParser.php b/src/Connection/ImapParser.php index 74dff1d..1bd0c86 100644 --- a/src/Connection/ImapParser.php +++ b/src/Connection/ImapParser.php @@ -45,13 +45,14 @@ public function __construct(ImapTokenizer $tokenizer) */ public function next(): Data|Token|Response|null { - // Load the first token. + // Attempt to load the first token. if (! $this->currentToken) { $this->advance(); } + // No token was found, return null. if (! $this->currentToken) { - throw new ImapParserException('Empty response'); + return null; } // If the token indicates the beginning of a list, parse it. diff --git a/tests/Unit/Connection/ImapConnectionTest.php b/tests/Unit/Connection/ImapConnectionTest.php index 78637a5..749b245 100644 --- a/tests/Unit/Connection/ImapConnectionTest.php +++ b/tests/Unit/Connection/ImapConnectionTest.php @@ -3,8 +3,8 @@ use DirectoryTree\ImapEngine\Connection\ImapConnection; use DirectoryTree\ImapEngine\Connection\Streams\FakeStream; use DirectoryTree\ImapEngine\Exceptions\ImapCommandException; +use DirectoryTree\ImapEngine\Exceptions\ImapConnectionException; use DirectoryTree\ImapEngine\Exceptions\ImapConnectionFailedException; -use DirectoryTree\ImapEngine\Exceptions\ImapParserException; use DirectoryTree\ImapEngine\Support\Str; test('connect success', function () { @@ -681,7 +681,7 @@ expect(function () use ($connection) { iterator_to_array($connection->idle(30)); - })->toThrow(ImapParserException::class); + })->toThrow(ImapConnectionException::class); $stream->assertWritten('TAG1 IDLE'); });