Files
server/shared/lib/Mail/Object/MessagePropertiesBaseAbstract.php
Sebastian Krupinski f3c882454d
All checks were successful
Build Test / build (pull_request) Successful in 12s
JS Unit Tests / test (pull_request) Successful in 11s
PHP Unit Tests / test (pull_request) Successful in 39s
refactor: mail interfaces
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-05-14 22:54:51 -04:00

198 lines
4.4 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* 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 {
protected string $type = 'mail.message';
/**
* @inheritDoc
*/
public function jsonSerialize(): array {
return $this->data;
}
/**
* @inheritDoc
*/
public function getSize(): ?int {
return $this->data[static::PROPERTY_SIZE] ?? null;
}
/**
* @inheritDoc
*/
public function getHeaders(): array {
return $this->data[static::PROPERTY_HEADERS] ?? [];
}
/**
* @inheritDoc
*/
public function getHeader(string $name): string|array|null {
return $this->data[static::PROPERTY_HEADERS][$name] ?? null;
}
/**
* @inheritDoc
*/
public function getUrid(): ?string {
return $this->data[static::PROPERTY_URID] ?? null;
}
/**
* @inheritDoc
*/
public function getInReplyTo(): ?string {
return $this->data[static::PROPERTY_IN_REPLY_TO] ?? null;
}
/**
* @inheritDoc
*/
public function getReferences(): array {
return $this->data[static::PROPERTY_REFERENCES] ?? [];
}
/**
* @inheritDoc
*/
public function getReceived(): ?DateTimeImmutable {
return $this->data[static::PROPERTY_RECEIVED] ?? null;
}
/**
* @inheritDoc
*/
public function getSent(): ?DateTimeImmutable {
return $this->data[static::PROPERTY_SENT] ?? null;
}
/**
* @inheritDoc
*/
public function getSender(): ?AddressInterface {
return $this->data[static::PROPERTY_SENDER] ?? null;
}
/**
* @inheritDoc
*/
public function getFrom(): ?AddressInterface {
return $this->data[static::PROPERTY_FROM] ?? null;
}
/**
* @inheritDoc
*/
public function getReplyTo(): array {
return $this->data[static::PROPERTY_REPLY_TO] ?? [];
}
/**
* @inheritDoc
*/
public function getTo(): array {
return $this->data[static::PROPERTY_TO] ?? [];
}
/**
* @inheritDoc
*/
public function getCc(): array {
return $this->data[static::PROPERTY_CC] ?? [];
}
/**
* @inheritDoc
*/
public function getBcc(): array {
return $this->data[static::PROPERTY_BCC] ?? [];
}
/**
* @inheritDoc
*/
public function getSubject(): string {
return $this->data[static::PROPERTY_SUBJECT] ?? '';
}
/**
* @inheritDoc
*/
public function getBody(): ?MessagePartInterface {
return $this->data[static::PROPERTY_BODY] ?? null;
}
/**
* @inheritDoc
*/
public function hasBody(): bool {
return ($this->data[static::PROPERTY_BODY_TEXT_PLAIN] !== null && $this->data[static::PROPERTY_BODY_TEXT_PLAIN] !== '')
|| ($this->data[static::PROPERTY_BODY_TEXT_HTML] !== null && $this->data[static::PROPERTY_BODY_TEXT_HTML] !== '');
}
/**
* @inheritDoc
*/
public function getBodyTextPlain(): ?string {
return $this->data[static::PROPERTY_BODY_TEXT_PLAIN] ?? null;
}
/**
* @inheritDoc
*/
public function getBodyTextHtml(): ?string {
return $this->data[static::PROPERTY_BODY_TEXT_HTML] ?? null;
}
/**
* @inheritDoc
*/
public function getAttachments(): array {
return $this->data[static::PROPERTY_ATTACHMENTS] ?? [];
}
/**
* @inheritDoc
*/
public function getFlags(): array {
return $this->data[static::PROPERTY_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[static::PROPERTY_FLAGS][$name] ?? false;
}
}