* SPDX-License-Identifier: AGPL-3.0-or-later */ namespace KTXF\Mail\Object; use DateTimeImmutable; use KTXF\Resource\Provider\Node\NodePropertiesBaseAbstract; /** * Abstract Message Properties Base Class * * Provides common implementation for message properties (read-only) * * @since 2025.05.01 */ abstract class MessagePropertiesBaseAbstract extends NodePropertiesBaseAbstract implements MessagePropertiesBaseInterface { public const JSON_TYPE = MessagePropertiesBaseInterface::JSON_TYPE; /** * @inheritDoc */ public function version(): int { return $this->data['version'] ?? 1; } /** * @inheritDoc */ public function getHeaders(): array { return $this->data['headers'] ?? []; } /** * @inheritDoc */ public function getHeader(string $name): string|array|null { return $this->data['headers'][$name] ?? null; } /** * @inheritDoc */ public function getUrid(): ?string { return $this->data['urid'] ?? null; } /** * @inheritDoc */ public function getCreated(): ?DateTimeImmutable { return $this->data['created'] ?? null; } /** * @inheritDoc */ public function getModified(): ?DateTimeImmutable { return $this->data['modified'] ?? null; } /** * @inheritDoc */ public function getDate(): ?DateTimeImmutable { return $this->data['date'] ?? null; } /** * @inheritDoc */ public function getReceived(): ?DateTimeImmutable { return $this->data['received'] ?? null; } /** * @inheritDoc */ public function getSize(): ?int { return $this->data['size'] ?? null; } /** * @inheritDoc */ public function getSender(): ?AddressInterface { return $this->data['sender'] ?? null; } /** * @inheritDoc */ public function getFrom(): ?AddressInterface { return $this->data['from'] ?? null; } /** * @inheritDoc */ public function getReplyTo(): array { return $this->data['replyTo'] ?? []; } /** * @inheritDoc */ public function getTo(): array { return $this->data['to'] ?? []; } /** * @inheritDoc */ public function getCc(): array { return $this->data['cc'] ?? []; } /** * @inheritDoc */ public function getBcc(): array { return $this->data['bcc'] ?? []; } /** * @inheritDoc */ public function getInReplyTo(): ?string { return $this->data['inReplyTo'] ?? null; } /** * @inheritDoc */ public function getReferences(): array { return $this->data['references'] ?? []; } /** * @inheritDoc */ public function getSubject(): string { return $this->data['subject'] ?? ''; } /** * @inheritDoc */ public function getSnippet(): ?string { return $this->data['snippet'] ?? null; } /** * @inheritDoc */ public function getBodyText(): ?string { return $this->data['bodyText'] ?? null; } /** * @inheritDoc */ public function getBodyTextCharset(): ?string { return $this->data['bodyTextCharset'] ?? null; } /** * @inheritDoc */ public function getBodyTextSize(): ?int { return $this->data['bodyTextSize'] ?? null; } /** * @inheritDoc */ public function getBodyHtml(): ?string { return $this->data['bodyHtml'] ?? null; } /** * @inheritDoc */ public function getBodyHtmlCharset(): ?string { return $this->data['bodyHtmlCharset'] ?? null; } /** * @inheritDoc */ public function getBodyHtmlSize(): ?int { return $this->data['bodyHtmlSize'] ?? null; } /** * @inheritDoc */ public function getAttachments(): array { return $this->data['attachments'] ?? []; } /** * @inheritDoc */ public function getFlags(): array { return $this->data['flags'] ?? [ 'read' => false, 'starred' => false, 'important' => false, 'answered' => false, 'forwarded' => false, 'draft' => false, 'deleted' => false, 'flagged' => false, ]; } /** * @inheritDoc */ public function getFlag(string $name): bool { return $this->data['flags'][$name] ?? false; } /** * Gets message labels * * @since 2025.05.01 * * @return array */ public function getLabels(): array { return $this->data['labels'] ?? []; } /** * Gets message tags * * @since 2025.05.01 * * @return array */ public function getTags(): array { return $this->data['tags'] ?? []; } /** * Gets message priority * * @since 2025.05.01 * * @return string */ public function getPriority(): string { return $this->data['priority'] ?? 'normal'; } /** * Gets message sensitivity * * @since 2025.05.01 * * @return string */ public function getSensitivity(): string { return $this->data['sensitivity'] ?? 'normal'; } /** * Gets encryption information * * @since 2025.05.01 * * @return array{method: string|null, signed: bool, encrypted: bool} */ public function getEncryption(): array { return $this->data['encryption'] ?? [ 'method' => null, 'signed' => false, 'encrypted' => false, ]; } /** * Checks if delivery receipt is requested * * @since 2025.05.01 * * @return bool */ public function isDeliveryReceipt(): bool { return $this->data['deliveryReceipt'] ?? false; } /** * Checks if read receipt is requested * * @since 2025.05.01 * * @return bool */ public function isReadReceipt(): bool { return $this->data['readReceipt'] ?? false; } /** * @inheritDoc */ public function hasRecipients(): bool { return !empty($this->data['to']) || !empty($this->data['cc']) || !empty($this->data['bcc']); } /** * @inheritDoc */ public function hasBody(): bool { return ($this->data['bodyText'] !== null && $this->data['bodyText'] !== '') || ($this->data['bodyHtml'] !== null && $this->data['bodyHtml'] !== ''); } /** * @inheritDoc */ public function getBody(): ?MessagePartInterface { return $this->data['body'] ?? null; } /** * @inheritDoc */ public function jsonSerialize(): array { $data = [ self::JSON_PROPERTY_TYPE => self::JSON_TYPE, self::JSON_PROPERTY_VERSION => $this->data['version'] ?? 1, ]; if (!empty($this->data['headers'])) { $data[self::JSON_PROPERTY_HEADERS] = $this->data['headers']; } if (isset($this->data['urid']) && $this->data['urid'] !== null) { $data[self::JSON_PROPERTY_URID] = $this->data['urid']; } if (isset($this->data['date']) && $this->data['date'] !== null) { $data[self::JSON_PROPERTY_DATE] = $this->data['date'] instanceof DateTimeImmutable ? $this->data['date']->format('c') : $this->data['date']; } if (isset($this->data['received']) && $this->data['received'] !== null) { $data[self::JSON_PROPERTY_RECEIVED] = $this->data['received'] instanceof DateTimeImmutable ? $this->data['received']->format('c') : $this->data['received']; } if (isset($this->data['size']) && $this->data['size'] !== null) { $data[self::JSON_PROPERTY_SIZE] = $this->data['size']; } if (isset($this->data['sender']) && $this->data['sender'] !== null) { $data[self::JSON_PROPERTY_SENDER] = $this->data['sender']; } if (isset($this->data['from']) && $this->data['from'] !== null) { $data[self::JSON_PROPERTY_FROM] = $this->data['from']; } if (!empty($this->data['replyTo'])) { $data[self::JSON_PROPERTY_REPLY_TO] = $this->data['replyTo']; } if (!empty($this->data['to'])) { $data[self::JSON_PROPERTY_TO] = $this->data['to']; } if (!empty($this->data['cc'])) { $data[self::JSON_PROPERTY_CC] = $this->data['cc']; } if (!empty($this->data['bcc'])) { $data[self::JSON_PROPERTY_BCC] = $this->data['bcc']; } if (isset($this->data['inReplyTo']) && $this->data['inReplyTo'] !== null) { $data[self::JSON_PROPERTY_IN_REPLY_TO] = $this->data['inReplyTo']; } if (!empty($this->data['references'])) { $data[self::JSON_PROPERTY_REFERENCES] = $this->data['references']; } if (isset($this->data['snippet']) && $this->data['snippet'] !== null) { $data[self::JSON_PROPERTY_SNIPPET] = $this->data['snippet']; } if (!empty($this->data['attachments'])) { $data[self::JSON_PROPERTY_ATTACHMENTS] = $this->data['attachments']; } $data[self::JSON_PROPERTY_SUBJECT] = $this->data['subject'] ?? null; $data[self::JSON_PROPERTY_BODY] = $this->data['body'] ?? null; return $data; } }