generated from Nodarx/template
refactor: use new mail interface desing
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -106,7 +106,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
|
||||
}
|
||||
@@ -132,7 +132,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;
|
||||
}
|
||||
@@ -241,14 +241,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);
|
||||
}
|
||||
|
||||
@@ -264,7 +281,7 @@ class RemoteMailService
|
||||
return [];
|
||||
}
|
||||
|
||||
$options ??= FetchOptions::default();
|
||||
$options ??= FetchOptions::message()->withBodyText();
|
||||
$this->client->perform(new SelectCommand($collection, true));
|
||||
|
||||
$request = new FetchManyCommand(
|
||||
@@ -599,7 +616,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();
|
||||
@@ -636,7 +653,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,
|
||||
|
||||
Reference in New Issue
Block a user