Skip to content
Open
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
30 changes: 30 additions & 0 deletions src/Connection/ImapQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
3 changes: 3 additions & 0 deletions src/Enums/ImapSearchKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
12 changes: 12 additions & 0 deletions tests/Unit/Connection/ImapQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});