clientFactory = $clientFactory; $this->messageMapper = $messageMapper; $this->cache = $cacheFactory->createLocal(self::CACHE_PREFIX); $this->dkimValidator = $dkimValidator; } #[\Override] public function validate(Account $account, Mailbox $mailbox, int $id): bool { $cached = $this->getCached($account, $mailbox, $id); if (is_bool($cached)) { return $cached; } $client = $this->clientFactory->getClient($account); try { $fullText = $this->messageMapper->getFullText( $client, $mailbox->getName(), $id, $account->getUserId(), false, ); if ($fullText === null) { throw new ServiceException('Could not fetch message source for uid ' . $id); } } finally { $client->logout(); } $result = $this->dkimValidator->validate($fullText); $cache_key = $this->buildCacheKey($account, $mailbox, $id); $this->cache->set($cache_key, $result, self::CACHE_TTL); return $result; } #[\Override] public function getCached(Account $account, Mailbox $mailbox, int $id): ?bool { return $this->cache->get($this->buildCacheKey($account, $mailbox, $id)); } private function buildCacheKey(Account $account, Mailbox $mailbox, int $id): string { return $account->getId() . '_' . $mailbox->getName() . '_' . $id; } }