Skip to content

Commit 263450f

Browse files
authored
Merge pull request #145 from DirectoryTree/larger-smaller-support
Add message larger/smaller query support
2 parents daf0c7e + 69ad634 commit 263450f

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

src/Connection/ImapQueryBuilder.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,22 @@ public function uid(int|string|array $from, int|float|null $to = null): static
235235
return $this->where(ImapSearchKey::Uid, new RawQueryValue(Str::set($from, $to)));
236236
}
237237

238+
/**
239+
* Add a where "LARGER" clause to the query.
240+
*/
241+
public function larger(int $bytes): static
242+
{
243+
return $this->where(ImapSearchKey::Larger, new RawQueryValue($bytes));
244+
}
245+
246+
/**
247+
* Add a where "SMALLER" clause to the query.
248+
*/
249+
public function smaller(int $bytes): static
250+
{
251+
return $this->where(ImapSearchKey::Smaller, new RawQueryValue($bytes));
252+
}
253+
238254
/**
239255
* Add a "where" condition.
240256
*/

src/Enums/ImapSearchKey.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ enum ImapSearchKey: string
2222
case Unseen = 'UNSEEN';
2323
case Before = 'BEFORE';
2424
case Header = 'HEADER';
25+
case Larger = 'LARGER';
2526
case Deleted = 'DELETED';
2627
case Flagged = 'FLAGGED';
2728
case Keyword = 'KEYWORD';
2829
case Subject = 'SUBJECT';
30+
case Smaller = 'SMALLER';
2931
case Answered = 'ANSWERED';
3032
case Undeleted = 'UNDELETED';
3133
case Unflagged = 'UNFLAGGED';

tests/Unit/Connection/ImapQueryBuilderTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,19 @@ function (ImapQueryBuilder $q) {
284284

285285
expect($builder->toImap())->toBe('UID 2');
286286
});
287+
288+
test('compiles LARGER condition without quotes', function () {
289+
expect((new ImapQueryBuilder)->larger(5242880)->toImap())->toBe('LARGER 5242880');
290+
});
291+
292+
test('compiles SMALLER condition without quotes', function () {
293+
expect((new ImapQueryBuilder)->smaller(10240)->toImap())->toBe('SMALLER 10240');
294+
});
295+
296+
test('compiles LARGER and SMALLER conditions together', function () {
297+
$builder = new ImapQueryBuilder;
298+
299+
$builder->larger(1024)->smaller(1048576);
300+
301+
expect($builder->toImap())->toBe('LARGER 1024 SMALLER 1048576');
302+
});

0 commit comments

Comments
 (0)