diff --git a/src/Connection/ImapQueryBuilder.php b/src/Connection/ImapQueryBuilder.php index 80db38f..71fcdaf 100644 --- a/src/Connection/ImapQueryBuilder.php +++ b/src/Connection/ImapQueryBuilder.php @@ -211,6 +211,36 @@ public function before(mixed $value): static )); } + /** + * Add a where "SENTON" clause to the query. + */ + public function sentOn(mixed $date): static + { + return $this->where(ImapSearchKey::SentOn, new RawQueryValue( + $this->parseDate($date)->format($this->dateFormat) + )); + } + + /** + * Add a where "SENTSINCE" clause to the query. + */ + public function sentSince(mixed $date): static + { + return $this->where(ImapSearchKey::SentSince, new RawQueryValue( + $this->parseDate($date)->format($this->dateFormat) + )); + } + + /** + * Add a where "SENTBEFORE" clause to the query. + */ + public function sentBefore(mixed $date): static + { + return $this->where(ImapSearchKey::SentBefore, new RawQueryValue( + $this->parseDate($date)->format($this->dateFormat) + )); + } + /** * Add a where "SUBJECT" clause to the query. */ diff --git a/src/Enums/ImapSearchKey.php b/src/Enums/ImapSearchKey.php index 1f8415d..214e4b0 100644 --- a/src/Enums/ImapSearchKey.php +++ b/src/Enums/ImapSearchKey.php @@ -18,6 +18,9 @@ enum ImapSearchKey: string case Text = 'TEXT'; case Draft = 'DRAFT'; case Since = 'SINCE'; + case SentOn = 'SENTON'; + case SentSince = 'SENTSINCE'; + case SentBefore = 'SENTBEFORE'; case Recent = 'RECENT'; case Unseen = 'UNSEEN'; case Before = 'BEFORE'; diff --git a/tests/Unit/Connection/ImapQueryBuilderTest.php b/tests/Unit/Connection/ImapQueryBuilderTest.php index 50a1e32..ad4b1b5 100644 --- a/tests/Unit/Connection/ImapQueryBuilderTest.php +++ b/tests/Unit/Connection/ImapQueryBuilderTest.php @@ -308,3 +308,15 @@ function (ImapQueryBuilder $q) { test('compiles UNKEYWORD condition', function () { expect((new ImapQueryBuilder)->unkeyword('important')->toImap())->toBe('UNKEYWORD "important"'); }); + +test('compiles a SENTON condition with unquoted date', function () { + expect((new ImapQueryBuilder)->sentOn(Carbon::create(2024, 4, 4))->toImap())->toBe('SENTON 04-Apr-2024'); +}); + +test('compiles a SENTSINCE condition with unquoted date', function () { + expect((new ImapQueryBuilder)->sentSince(Carbon::create(2024, 4, 4))->toImap())->toBe('SENTSINCE 04-Apr-2024'); +}); + +test('compiles a SENTBEFORE condition with unquoted date', function () { + expect((new ImapQueryBuilder)->sentBefore(Carbon::create(2024, 4, 4))->toImap())->toBe('SENTBEFORE 04-Apr-2024'); +});