> */ public array $flags = []; /** @var int[] */ public array $unfetchable = []; public array $fetchBatches = []; public int $selects = 0; public ?int $bodyTextLimit = null; /** @var Mailbox[] */ public array $mailboxList = []; /** @var string[] */ public array $failing = []; /** @var list */ public array $calls = []; public function collectionList(?string $location = null, ?IFilter $filter = null, ?ISort $sort = null): array { $this->calls[] = ['collectionList', [$location, $filter]]; $list = []; foreach ($this->mailboxList as $mailbox) { $list[$mailbox->name()] = (new CollectionResource('imap', 'svc'))->fromImap($mailbox); } return $list; } public function mailboxFetch(string $identifier): ?Mailbox { if (in_array($identifier, $this->failing, true)) { return null; } $this->selects++; return new Mailbox($identifier, '/', [], count($this->flags), 0, $this->uidValidity, 0, [], true, $this->uidNext); } public function entityFlags(string $collection): Generator { yield from $this->flags; } public function messageFetch(string $collection, ?FetchOptions $options = null, int ...$uids): Generator { $this->fetchBatches[] = $uids; if (preg_match('/BODY\.PEEK\[TEXT\]<0\.(\d+)>/', (string) $options?->toCommand(), $matches) === 1) { $this->bodyTextLimit = (int) $matches[1]; } foreach ($uids as $uid) { if (in_array($uid, $this->unfetchable, true)) { continue; } $flags = implode(' ', $this->flags[$uid] ?? []); yield $uid => FetchMessageParser::parse("* {$uid} FETCH (UID {$uid} FLAGS ({$flags}))"); } } /** * Every message of the mailbox in UID order; filter / sort / range are not evaluated. */ public function messageList(string $collection, ?IFilter $filter = null, ?ISort $sort = null, ?IRange $range = null): Generator { $this->calls[] = ['messageList', [$collection]]; $uids = array_keys($this->flags); sort($uids); yield from $this->messageFetch($collection, null, ...$uids); } /** @var int[] UIDs entityFind() returns */ public array $found = []; public function entityFind(string $collection, ?IFilter $filter = null, ?ISort $sort = null, ?IRange $range = null): array { $this->calls[] = ['entityFind', [$collection, $filter]]; return $this->found; } public function entityPatch(string $collection, array $flagsToAdd = [], array $flagsToRemove = [], int ...$uids): void { $this->calls[] = ['entityPatch', [$collection, $flagsToAdd, $flagsToRemove, $uids]]; } }