Skip to content

Commit b3f0ac3

Browse files
authored
Merge pull request #149 from DirectoryTree/sent-queries
Add sent on/since/before support
2 parents 1c5c94c + 6c05369 commit b3f0ac3

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

src/Connection/ImapQueryBuilder.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,36 @@ public function before(mixed $value): static
211211
));
212212
}
213213

214+
/**
215+
* Add a where "SENTON" clause to the query.
216+
*/
217+
public function sentOn(mixed $date): static
218+
{
219+
return $this->where(ImapSearchKey::SentOn, new RawQueryValue(
220+
$this->parseDate($date)->format($this->dateFormat)
221+
));
222+
}
223+
224+
/**
225+
* Add a where "SENTSINCE" clause to the query.
226+
*/
227+
public function sentSince(mixed $date): static
228+
{
229+
return $this->where(ImapSearchKey::SentSince, new RawQueryValue(
230+
$this->parseDate($date)->format($this->dateFormat)
231+
));
232+
}
233+
234+
/**
235+
* Add a where "SENTBEFORE" clause to the query.
236+
*/
237+
public function sentBefore(mixed $date): static
238+
{
239+
return $this->where(ImapSearchKey::SentBefore, new RawQueryValue(
240+
$this->parseDate($date)->format($this->dateFormat)
241+
));
242+
}
243+
214244
/**
215245
* Add a where "SUBJECT" clause to the query.
216246
*/

src/Enums/ImapSearchKey.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ enum ImapSearchKey: string
1818
case Text = 'TEXT';
1919
case Draft = 'DRAFT';
2020
case Since = 'SINCE';
21+
case SentOn = 'SENTON';
22+
case SentSince = 'SENTSINCE';
23+
case SentBefore = 'SENTBEFORE';
2124
case Recent = 'RECENT';
2225
case Unseen = 'UNSEEN';
2326
case Before = 'BEFORE';

tests/Unit/Connection/ImapQueryBuilderTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,15 @@ function (ImapQueryBuilder $q) {
308308
test('compiles UNKEYWORD condition', function () {
309309
expect((new ImapQueryBuilder)->unkeyword('important')->toImap())->toBe('UNKEYWORD "important"');
310310
});
311+
312+
test('compiles a SENTON condition with unquoted date', function () {
313+
expect((new ImapQueryBuilder)->sentOn(Carbon::create(2024, 4, 4))->toImap())->toBe('SENTON 04-Apr-2024');
314+
});
315+
316+
test('compiles a SENTSINCE condition with unquoted date', function () {
317+
expect((new ImapQueryBuilder)->sentSince(Carbon::create(2024, 4, 4))->toImap())->toBe('SENTSINCE 04-Apr-2024');
318+
});
319+
320+
test('compiles a SENTBEFORE condition with unquoted date', function () {
321+
expect((new ImapQueryBuilder)->sentBefore(Carbon::create(2024, 4, 4))->toImap())->toBe('SENTBEFORE 04-Apr-2024');
322+
});

0 commit comments

Comments
 (0)