Skip to content

Commit 12b474f

Browse files
authored
Merge pull request #15 from DirectoryTree/BUG-13
Fix parser exception being thrown when there are no more tokens in response
2 parents c2a2c54 + f2504e6 commit 12b474f

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/Connection/ImapParser.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ public function __construct(ImapTokenizer $tokenizer)
4545
*/
4646
public function next(): Data|Token|Response|null
4747
{
48-
// Load the first token.
48+
// Attempt to load the first token.
4949
if (! $this->currentToken) {
5050
$this->advance();
5151
}
5252

53+
// No token was found, return null.
5354
if (! $this->currentToken) {
54-
throw new ImapParserException('Empty response');
55+
return null;
5556
}
5657

5758
// If the token indicates the beginning of a list, parse it.

tests/Unit/Connection/ImapConnectionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
use DirectoryTree\ImapEngine\Connection\ImapConnection;
44
use DirectoryTree\ImapEngine\Connection\Streams\FakeStream;
55
use DirectoryTree\ImapEngine\Exceptions\ImapCommandException;
6+
use DirectoryTree\ImapEngine\Exceptions\ImapConnectionException;
67
use DirectoryTree\ImapEngine\Exceptions\ImapConnectionFailedException;
7-
use DirectoryTree\ImapEngine\Exceptions\ImapParserException;
88
use DirectoryTree\ImapEngine\Support\Str;
99

1010
test('connect success', function () {
@@ -681,7 +681,7 @@
681681

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

686686
$stream->assertWritten('TAG1 IDLE');
687687
});

0 commit comments

Comments
 (0)