Skip to content

Commit

Permalink
Merge pull request #15 from DirectoryTree/BUG-13
Browse files Browse the repository at this point in the history
Fix parser exception being thrown when there are no more tokens in response
  • Loading branch information
stevebauman authored Feb 13, 2025
2 parents c2a2c54 + f2504e6 commit 12b474f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/Connection/ImapParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Connection/ImapConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -681,7 +681,7 @@

expect(function () use ($connection) {
iterator_to_array($connection->idle(30));
})->toThrow(ImapParserException::class);
})->toThrow(ImapConnectionException::class);

$stream->assertWritten('TAG1 IDLE');
});
Expand Down

0 comments on commit 12b474f

Please sign in to comment.