refactor: use new mail interface desing

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-05-14 22:44:28 -04:00
parent d9bc526126
commit c6935c47e3
9 changed files with 323 additions and 198 deletions

View File

@@ -108,7 +108,7 @@ class RemoteMailService
}
try {
$status = $this->client->perform(new StatusCommand($mailbox->name(), self::DEFAULT_MAILBOX_STATUS_ITEMS));
$mailbox->fromStatus($status);
$mailbox = $mailbox->fromStatus($status);
} catch (ImapException) {
// do nothing
}
@@ -134,7 +134,7 @@ class RemoteMailService
$mailbox = reset($mailbox);
// enrich with STATUS
$status = $this->client->perform(new StatusCommand($mailbox->name(), self::DEFAULT_MAILBOX_STATUS_ITEMS));
$mailbox->fromStatus($status);
$mailbox = $mailbox->fromStatus($status);
return $mailbox;
}
@@ -243,14 +243,31 @@ class RemoteMailService
*/
public function entityList(string $collection, ?IFilter $filter = null, ?ISort $sort = null, ?IRange $range = null): Generator
{
$options = FetchOptions::message()->withBodyText();
// fast path: fetch all messages without filtering, sorting or pagination
if ($filter === null && $sort === null && $range === null) {
$mailbox = $this->client->perform(new SelectCommand($collection, true));
if ($mailbox === null) {
return [];
}
yield from $this->client->perform(new FetchManyCommand(
FetchTarget::all(),
$options,
));
return;
}
// find all the UIDs matching the filter
$uids = $this->entityFind($collection, $filter, $sort, $range);
if (empty($uids)) {
return [];
}
$options = FetchOptions::default()->withBodyText();
yield from $this->entityFetch($collection, $options, ...$uids);
}
@@ -266,7 +283,7 @@ class RemoteMailService
return [];
}
$options ??= FetchOptions::default();
$options ??= FetchOptions::message()->withBodyText();
$this->client->perform(new SelectCommand($collection, true));
$request = new FetchManyCommand(
@@ -576,7 +593,7 @@ class RemoteMailService
*/
private function entitySortClientSide(array $uids, ISort $sort): array
{
$options = FetchOptions::summary();
$options = FetchOptions::default();
foreach ($sort->conditions() as $condition) {
if (in_array($condition['attribute'] ?? '', ['from', 'to', 'subject', 'sent'], true)) {
$options = $options->withEnvelope();
@@ -613,7 +630,7 @@ class RemoteMailService
'from' => $this->entityPrimaryAddressValue($left->from()) <=> $this->entityPrimaryAddressValue($right->from()),
'to' => $this->entityPrimaryAddressValue($left->to()) <=> $this->entityPrimaryAddressValue($right->to()),
'subject' => $this->entityScalarValue($left->subject()) <=> $this->entityScalarValue($right->subject()),
'received' => $this->entityTimestampValue($left->internalDate()) <=> $this->entityTimestampValue($right->internalDate()),
'received' => $this->entityTimestampValue($left->receivedAt() ?? $left->internalDate()) <=> $this->entityTimestampValue($right->receivedAt() ?? $right->internalDate()),
'sent' => $this->entityTimestampValue($left->sentAt()) <=> $this->entityTimestampValue($right->sentAt()),
'size' => $left->size() <=> $right->size(),
default => 0,