From 0c597bc653b747b4117b4469b1fe0d1eac0a0d16 Mon Sep 17 00:00:00 2001 From: matthieu Date: Tue, 19 May 2026 23:16:52 +0200 Subject: [PATCH] feat(mail) : MailMessage entity + repository --- src/Entity/MailMessage.php | 238 +++++++++++++++++++++++ src/Repository/MailMessageRepository.php | 57 ++++++ 2 files changed, 295 insertions(+) create mode 100644 src/Entity/MailMessage.php create mode 100644 src/Repository/MailMessageRepository.php diff --git a/src/Entity/MailMessage.php b/src/Entity/MailMessage.php new file mode 100644 index 0000000..55524f5 --- /dev/null +++ b/src/Entity/MailMessage.php @@ -0,0 +1,238 @@ +id; + } + + public function getMessageId(): string + { + return $this->messageId; + } + + public function setMessageId(string $messageId): static + { + $this->messageId = $messageId; + + return $this; + } + + public function getFolder(): MailFolder + { + return $this->folder; + } + + public function setFolder(MailFolder $folder): static + { + $this->folder = $folder; + + return $this; + } + + public function getUid(): int + { + return $this->uid; + } + + public function setUid(int $uid): static + { + $this->uid = $uid; + + return $this; + } + + public function getSubject(): ?string + { + return $this->subject; + } + + public function setSubject(?string $subject): static + { + $this->subject = $subject; + + return $this; + } + + public function getFromAddress(): string + { + return $this->fromAddress; + } + + public function setFromAddress(string $fromAddress): static + { + $this->fromAddress = $fromAddress; + + return $this; + } + + public function getFromName(): ?string + { + return $this->fromName; + } + + public function setFromName(?string $fromName): static + { + $this->fromName = $fromName; + + return $this; + } + + public function getToAddresses(): array + { + return $this->toAddresses; + } + + public function setToAddresses(array $toAddresses): static + { + $this->toAddresses = $toAddresses; + + return $this; + } + + public function getCcAddresses(): ?array + { + return $this->ccAddresses; + } + + public function setCcAddresses(?array $ccAddresses): static + { + $this->ccAddresses = $ccAddresses; + + return $this; + } + + public function getSentAt(): DateTimeImmutable + { + return $this->sentAt; + } + + public function setSentAt(DateTimeImmutable $sentAt): static + { + $this->sentAt = $sentAt; + + return $this; + } + + public function isRead(): bool + { + return $this->isRead; + } + + public function setIsRead(bool $isRead): static + { + $this->isRead = $isRead; + + return $this; + } + + public function isFlagged(): bool + { + return $this->isFlagged; + } + + public function setIsFlagged(bool $isFlagged): static + { + $this->isFlagged = $isFlagged; + + return $this; + } + + public function hasAttachments(): bool + { + return $this->hasAttachments; + } + + public function setHasAttachments(bool $hasAttachments): static + { + $this->hasAttachments = $hasAttachments; + + return $this; + } + + public function getSnippet(): ?string + { + return $this->snippet; + } + + public function setSnippet(?string $snippet): static + { + $this->snippet = $snippet; + + return $this; + } + + public function getSyncedAt(): DateTimeImmutable + { + return $this->syncedAt; + } + + public function setSyncedAt(DateTimeImmutable $syncedAt): static + { + $this->syncedAt = $syncedAt; + + return $this; + } +} diff --git a/src/Repository/MailMessageRepository.php b/src/Repository/MailMessageRepository.php new file mode 100644 index 0000000..bc4bef9 --- /dev/null +++ b/src/Repository/MailMessageRepository.php @@ -0,0 +1,57 @@ +findOneBy(['messageId' => $messageId]); + } + + public function findByFolderAndUid(MailFolder $folder, int $uid): ?MailMessage + { + return $this->findOneBy(['folder' => $folder, 'uid' => $uid]); + } + + /** + * @return list + */ + public function findByFolderPaginated(MailFolder $folder, int $limit, int $offset): array + { + return $this->createQueryBuilder('m') + ->andWhere('m.folder = :folder') + ->setParameter('folder', $folder) + ->orderBy('m.sentAt', 'DESC') + ->addOrderBy('m.id', 'DESC') + ->setMaxResults($limit) + ->setFirstResult($offset) + ->getQuery() + ->getResult() + ; + } + + public function countUnreadByFolder(MailFolder $folder): int + { + return (int) $this->createQueryBuilder('m') + ->select('COUNT(m.id)') + ->andWhere('m.folder = :folder') + ->andWhere('m.isRead = false') + ->setParameter('folder', $folder) + ->getQuery() + ->getSingleScalarResult() + ; + } +}