Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Connection/ImapQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

class ImapQueryBuilder
{
/**
* The largest UID value allowed by IMAP.
*/
protected const MAX_UID = '4294967295';

/**
* The where conditions for the query.
*/
Expand Down Expand Up @@ -270,6 +275,10 @@ public function header(string $header, string $value): static
*/
public function uid(int|string|array $from, int|float|null $to = null): static
{
if ($to === INF) {
$to = self::MAX_UID;
}

return $this->where(ImapSearchKey::Uid, new RawQueryValue(Str::set($from, $to)));
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Connection/ImapQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,12 @@ function (ImapQueryBuilder $q) {
expect($builder->toImap())->toBe('UID 2,3,5');
});

test('compiles UID range to infinity with from and to', function () {
test('compiles UID range to infinity with from and to as a numeric upper bound', function () {
$builder = new ImapQueryBuilder;

$builder->uid(2, INF);

expect($builder->toImap())->toBe('UID 2:*');
expect($builder->toImap())->toBe('UID 2:4294967295');
});

test('compiles UID range with upper bound with array', function () {
Expand Down
20 changes: 20 additions & 0 deletions tests/Unit/MessageQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,26 @@ function query(?Mailbox $mailbox = null): MessageQuery
$stream->assertWritten('TAG3 UID STORE 5,6,7,8 +FLAGS.SILENT (\Flagged)');
});

test('uid range to infinity searches with numeric upper bound', function () {
$stream = new FakeStream;
$stream->open();

$stream->feed([
'* OK Welcome to IMAP',
'TAG1 OK Logged in',
'* SEARCH',
'TAG2 OK SEARCH completed',
]);

$mailbox = Mailbox::make();
$mailbox->connect(new ImapConnection($stream));

$messages = query($mailbox)->uid(42, INF)->get();

expect($messages)->toBeEmpty();
$stream->assertWritten('TAG2 UID SEARCH UID 42:4294967295');
});

test('unmarkFlagged unflags all matching messages', function () {
$stream = new FakeStream;
$stream->open();
Expand Down
Loading