lots of improvements

This commit is contained in:
root
2026-02-10 17:47:48 -05:00
parent 6d0c5584bd
commit b87b5d9052
65 changed files with 3445 additions and 1577 deletions

View File

@@ -1,141 +0,0 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Mail\Entity;
/**
* Mail Address Implementation
*
* Concrete implementation of IAddress for email addresses.
*
* @since 2025.05.01
*/
class Address implements IAddress {
/**
* @param string $address Email address
* @param string|null $name Display name
*/
public function __construct(
private string $address = '',
private ?string $name = null,
) {}
/**
* Creates an Address from a formatted string
*
* @since 2025.05.01
*
* @param string $value Formatted as "Name <address>" or just "address"
*
* @return self
*/
public static function fromString(string $value): self {
$value = trim($value);
// Match "Name <address>" format
if (preg_match('/^(.+?)\s*<([^>]+)>$/', $value, $matches)) {
return new self(trim($matches[2]), trim($matches[1], ' "\''));
}
// Match "<address>" format
if (preg_match('/^<([^>]+)>$/', $value, $matches)) {
return new self(trim($matches[1]));
}
// Assume plain address
return new self($value);
}
/**
* Creates an Address from an array
*
* @since 2025.05.01
*
* @param array $data Array with 'address' and optional 'name' keys
*
* @return self
*/
public static function fromArray(array $data): self {
return new self(
$data[self::JSON_PROPERTY_ADDRESS] ?? $data['address'] ?? '',
$data[self::JSON_PROPERTY_NAME] ?? $data['name'] ?? null,
);
}
/**
* @inheritDoc
*/
public function getAddress(): string {
return $this->address;
}
/**
* Sets the email address
*
* @since 2025.05.01
*
* @param string $address
*
* @return self
*/
public function setAddress(string $address): self {
$this->address = $address;
return $this;
}
/**
* @inheritDoc
*/
public function getName(): ?string {
return $this->name;
}
/**
* Sets the display name
*
* @since 2025.05.01
*
* @param string|null $name
*
* @return self
*/
public function setName(?string $name): self {
$this->name = $name;
return $this;
}
/**
* @inheritDoc
*/
public function toString(): string {
if ($this->name !== null && $this->name !== '') {
return sprintf('"%s" <%s>', $this->name, $this->address);
}
return $this->address;
}
/**
* @inheritDoc
*/
public function jsonSerialize(): array {
return array_filter([
self::JSON_PROPERTY_ADDRESS => $this->address,
self::JSON_PROPERTY_NAME => $this->name,
], fn($v) => $v !== null && $v !== '');
}
/**
* String representation
*/
public function __toString(): string {
return $this->toString();
}
}

View File

@@ -1,195 +0,0 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Mail\Entity;
/**
* Mail Attachment Implementation
*
* Concrete implementation of IAttachment for mail attachments.
*
* @since 2025.05.01
*/
class Attachment implements IAttachment {
/**
* @param string $name File name
* @param string $mimeType MIME type
* @param string $content Binary content
* @param string|null $id Attachment ID
* @param int|null $size Size in bytes
* @param string|null $contentId Content-ID for inline attachments
* @param bool $inline Whether inline attachment
*/
public function __construct(
private string $name,
private string $mimeType,
private string $content,
private ?string $id = null,
private ?int $size = null,
private ?string $contentId = null,
private bool $inline = false,
) {
if ($this->size === null) {
$this->size = strlen($this->content);
}
}
/**
* Creates an attachment from a file path
*
* @since 2025.05.01
*
* @param string $path File path
* @param string|null $name Override file name
* @param string|null $mimeType Override MIME type
*
* @return self
*/
public static function fromFile(string $path, ?string $name = null, ?string $mimeType = null): self {
$content = file_get_contents($path);
$name = $name ?? basename($path);
$mimeType = $mimeType ?? mime_content_type($path) ?: 'application/octet-stream';
return new self($name, $mimeType, $content);
}
/**
* Creates an attachment from base64 encoded content
*
* @since 2025.05.01
*
* @param string $name File name
* @param string $mimeType MIME type
* @param string $base64Content Base64 encoded content
*
* @return self
*/
public static function fromBase64(string $name, string $mimeType, string $base64Content): self {
return new self($name, $mimeType, base64_decode($base64Content));
}
/**
* Creates an inline attachment for embedding in HTML
*
* @since 2025.05.01
*
* @param string $name File name
* @param string $mimeType MIME type
* @param string $content Binary content
* @param string $contentId Content-ID (without cid: prefix)
*
* @return self
*/
public static function inline(string $name, string $mimeType, string $content, string $contentId): self {
return new self($name, $mimeType, $content, null, null, $contentId, true);
}
/**
* Creates from array data
*
* @since 2025.05.01
*
* @param array $data
*
* @return self
*/
public static function fromArray(array $data): self {
$content = $data['content'] ?? '';
if (isset($data['contentBase64'])) {
$content = base64_decode($data['contentBase64']);
}
return new self(
$data[self::JSON_PROPERTY_NAME] ?? $data['name'] ?? '',
$data[self::JSON_PROPERTY_MIME_TYPE] ?? $data['mimeType'] ?? 'application/octet-stream',
$content,
$data[self::JSON_PROPERTY_ID] ?? $data['id'] ?? null,
$data[self::JSON_PROPERTY_SIZE] ?? $data['size'] ?? null,
$data[self::JSON_PROPERTY_CONTENT_ID] ?? $data['contentId'] ?? null,
$data[self::JSON_PROPERTY_INLINE] ?? $data['inline'] ?? false,
);
}
/**
* @inheritDoc
*/
public function getId(): ?string {
return $this->id;
}
/**
* @inheritDoc
*/
public function getName(): string {
return $this->name;
}
/**
* @inheritDoc
*/
public function getMimeType(): string {
return $this->mimeType;
}
/**
* @inheritDoc
*/
public function getSize(): ?int {
return $this->size;
}
/**
* @inheritDoc
*/
public function getContentId(): ?string {
return $this->contentId;
}
/**
* @inheritDoc
*/
public function isInline(): bool {
return $this->inline;
}
/**
* @inheritDoc
*/
public function getContent(): string {
return $this->content;
}
/**
* Gets the content as base64 encoded string
*
* @since 2025.05.01
*
* @return string
*/
public function getContentBase64(): string {
return base64_encode($this->content);
}
/**
* @inheritDoc
*/
public function jsonSerialize(): array {
return array_filter([
self::JSON_PROPERTY_ID => $this->id,
self::JSON_PROPERTY_NAME => $this->name,
self::JSON_PROPERTY_MIME_TYPE => $this->mimeType,
self::JSON_PROPERTY_SIZE => $this->size,
self::JSON_PROPERTY_CONTENT_ID => $this->contentId,
self::JSON_PROPERTY_INLINE => $this->inline ?: null,
'contentBase64' => $this->getContentBase64(),
], fn($v) => $v !== null);
}
}

View File

@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Mail\Entity;
use KTXF\Mail\Object\MessagePropertiesBaseInterface;
use KTXF\Resource\Provider\Node\NodeBaseAbstract;
/**
* Abstract Mail Entity Base Class
*
* Provides common implementation for mail entities
*
* @since 2025.05.01
*/
abstract class EntityBaseAbstract extends NodeBaseAbstract implements EntityBaseInterface {
protected MessagePropertiesBaseInterface $properties;
/**
* @inheritDoc
*/
public function getProperties(): MessagePropertiesBaseInterface {
return $this->properties;
}
}

View File

@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Mail\Entity;
use KTXF\Mail\Object\MessagePropertiesBaseInterface;
use KTXF\Mail\Object\MessagePropertiesMutableInterface;
use KTXF\Resource\Provider\Node\NodeBaseInterface;
interface EntityBaseInterface extends NodeBaseInterface {
public const JSON_TYPE = 'mail.entity';
/**
* Gets the entity properties
*
* @since 2025.05.01
*/
public function getProperties(): MessagePropertiesBaseInterface|MessagePropertiesMutableInterface;
}

View File

@@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Mail\Entity;
use KTXF\Mail\Object\MessagePropertiesMutableInterface;
use KTXF\Resource\Provider\Node\NodeMutableAbstract;
use KTXF\Resource\Provider\Node\NodePropertiesMutableInterface;
/**
* Abstract Mail Entity Mutable Class
*
* Provides common implementation for mutable mail entities
*
* @since 2025.05.01
*/
abstract class EntityMutableAbstract extends NodeMutableAbstract implements EntityMutableInterface {
public const JSON_TYPE = EntityMutableInterface::JSON_TYPE;
protected MessagePropertiesMutableInterface $properties;
/**
* @inheritDoc
*/
public function getProperties(): MessagePropertiesMutableInterface {
return $this->properties;
}
/**
* @inheritDoc
*/
public function setProperties(NodePropertiesMutableInterface $value): static {
if (!$value instanceof MessagePropertiesMutableInterface) {
throw new \InvalidArgumentException('Properties must implement MessagePropertiesMutableInterface');
}
$this->properties = $value;
return $this;
}
}

View File

@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Mail\Entity;
use KTXF\Mail\Object\MessagePropertiesMutableInterface;
use KTXF\Resource\Provider\Node\NodeMutableInterface;
/**
* @method static setProperties(MessagePropertiesMutableInterface $value)
*/
interface EntityMutableInterface extends EntityBaseInterface, NodeMutableInterface {
public const JSON_TYPE = EntityBaseInterface::JSON_TYPE;
/**
* Gets the entity properties (mutable)
*
* @since 2025.05.01
*/
public function getProperties(): MessagePropertiesMutableInterface;
}

View File

@@ -1,53 +0,0 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Mail\Entity;
use JsonSerializable;
/**
* Mail Address Interface
*
* Represents an email address with optional display name.
*
* @since 2025.05.01
*/
interface IAddress extends JsonSerializable {
public const JSON_PROPERTY_ADDRESS = 'address';
public const JSON_PROPERTY_NAME = 'name';
/**
* Gets the email address
*
* @since 2025.05.01
*
* @return string Email address (e.g., "user@example.com")
*/
public function getAddress(): string;
/**
* Gets the display name
*
* @since 2025.05.01
*
* @return string|null Display name (e.g., "John Doe") or null
*/
public function getName(): ?string;
/**
* Gets the formatted address string
*
* @since 2025.05.01
*
* @return string Formatted as "Name <address>" or just "address" if no name
*/
public function toString(): string;
}

View File

@@ -1,93 +0,0 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Mail\Entity;
use JsonSerializable;
/**
* Mail Attachment Interface
*
* Represents a file attachment on a mail message.
*
* @since 2025.05.01
*/
interface IAttachment extends JsonSerializable {
public const JSON_PROPERTY_ID = 'id';
public const JSON_PROPERTY_NAME = 'name';
public const JSON_PROPERTY_MIME_TYPE = 'mimeType';
public const JSON_PROPERTY_SIZE = 'size';
public const JSON_PROPERTY_CONTENT_ID = 'contentId';
public const JSON_PROPERTY_INLINE = 'inline';
/**
* Gets the attachment identifier
*
* @since 2025.05.01
*
* @return string|null Attachment ID or null for new attachments
*/
public function getId(): ?string;
/**
* Gets the file name
*
* @since 2025.05.01
*
* @return string File name (e.g., "document.pdf")
*/
public function getName(): string;
/**
* Gets the MIME type
*
* @since 2025.05.01
*
* @return string MIME type (e.g., "application/pdf")
*/
public function getMimeType(): string;
/**
* Gets the file size in bytes
*
* @since 2025.05.01
*
* @return int|null Size in bytes or null if unknown
*/
public function getSize(): ?int;
/**
* Gets the Content-ID for inline attachments
*
* @since 2025.05.01
*
* @return string|null Content-ID for referencing in HTML body (e.g., "cid:image1")
*/
public function getContentId(): ?string;
/**
* Checks if this is an inline attachment (embedded in body)
*
* @since 2025.05.01
*
* @return bool True if inline, false if regular attachment
*/
public function isInline(): bool;
/**
* Gets the attachment content
*
* @since 2025.05.01
*
* @return string Binary content of the attachment
*/
public function getContent(): string;
}

View File

@@ -1,176 +0,0 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Mail\Entity;
use DateTimeImmutable;
use JsonSerializable;
/**
* Mail Message Base Interface
*
* Read-only interface for mail message entities.
*
* @since 2025.05.01
*/
interface IMessageBase extends JsonSerializable {
public const JSON_TYPE = 'mail.message';
public const JSON_PROPERTY_TYPE = '@type';
public const JSON_PROPERTY_ID = 'id';
public const JSON_PROPERTY_SUBJECT = 'subject';
public const JSON_PROPERTY_FROM = 'from';
public const JSON_PROPERTY_REPLY_TO = 'replyTo';
public const JSON_PROPERTY_TO = 'to';
public const JSON_PROPERTY_CC = 'cc';
public const JSON_PROPERTY_BCC = 'bcc';
public const JSON_PROPERTY_DATE = 'date';
public const JSON_PROPERTY_BODY_TEXT = 'bodyText';
public const JSON_PROPERTY_BODY_HTML = 'bodyHtml';
public const JSON_PROPERTY_ATTACHMENTS = 'attachments';
public const JSON_PROPERTY_HEADERS = 'headers';
/**
* Gets the message identifier
*
* @since 2025.05.01
*
* @return string|null Message ID or null for unsent messages
*/
public function getId(): ?string;
/**
* Gets the message subject
*
* @since 2025.05.01
*
* @return string
*/
public function getSubject(): string;
/**
* Gets the sender address
*
* @since 2025.05.01
*
* @return IAddress|null
*/
public function getFrom(): ?IAddress;
/**
* Gets the reply-to address
*
* @since 2025.05.01
*
* @return IAddress|null
*/
public function getReplyTo(): ?IAddress;
/**
* Gets the primary recipients (To)
*
* @since 2025.05.01
*
* @return array<int, IAddress>
*/
public function getTo(): array;
/**
* Gets the carbon copy recipients (CC)
*
* @since 2025.05.01
*
* @return array<int, IAddress>
*/
public function getCc(): array;
/**
* Gets the blind carbon copy recipients (BCC)
*
* @since 2025.05.01
*
* @return array<int, IAddress>
*/
public function getBcc(): array;
/**
* Gets the message date
*
* @since 2025.05.01
*
* @return DateTimeImmutable|null
*/
public function getDate(): ?DateTimeImmutable;
/**
* Gets the plain text body
*
* @since 2025.05.01
*
* @return string|null
*/
public function getBodyText(): ?string;
/**
* Gets the HTML body
*
* @since 2025.05.01
*
* @return string|null
*/
public function getBodyHtml(): ?string;
/**
* Gets the attachments
*
* @since 2025.05.01
*
* @return array<int, IAttachment>
*/
public function getAttachments(): array;
/**
* Gets custom headers
*
* @since 2025.05.01
*
* @return array<string, string> Header name => value
*/
public function getHeaders(): array;
/**
* Gets a specific header value
*
* @since 2025.05.01
*
* @param string $name Header name
*
* @return string|null Header value or null if not set
*/
public function getHeader(string $name): ?string;
/**
* Checks if the message has any recipients
*
* @since 2025.05.01
*
* @return bool True if To, CC, or BCC has at least one recipient
*/
public function hasRecipients(): bool;
/**
* Checks if the message has any body content
*
* @since 2025.05.01
*
* @return bool True if text or HTML body is set
*/
public function hasBody(): bool;
}

View File

@@ -1,211 +0,0 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Mail\Entity;
use DateTimeImmutable;
/**
* Mail Message Mutable Interface
*
* Interface for composing and modifying mail messages with fluent setters.
*
* @since 2025.05.01
*/
interface IMessageMutable extends IMessageBase {
/**
* Sets the message identifier
*
* @since 2025.05.01
*
* @param string|null $id
*
* @return self
*/
public function setId(?string $id): self;
/**
* Sets the message subject
*
* @since 2025.05.01
*
* @param string $subject
*
* @return self
*/
public function setSubject(string $subject): self;
/**
* Sets the sender address
*
* @since 2025.05.01
*
* @param IAddress|null $from
*
* @return self
*/
public function setFrom(?IAddress $from): self;
/**
* Sets the reply-to address
*
* @since 2025.05.01
*
* @param IAddress|null $replyTo
*
* @return self
*/
public function setReplyTo(?IAddress $replyTo): self;
/**
* Sets the primary recipients (To)
*
* @since 2025.05.01
*
* @param array<int, IAddress> $to
*
* @return self
*/
public function setTo(array $to): self;
/**
* Adds a primary recipient (To)
*
* @since 2025.05.01
*
* @param IAddress $address
*
* @return self
*/
public function addTo(IAddress $address): self;
/**
* Sets the carbon copy recipients (CC)
*
* @since 2025.05.01
*
* @param array<int, IAddress> $cc
*
* @return self
*/
public function setCc(array $cc): self;
/**
* Adds a carbon copy recipient (CC)
*
* @since 2025.05.01
*
* @param IAddress $address
*
* @return self
*/
public function addCc(IAddress $address): self;
/**
* Sets the blind carbon copy recipients (BCC)
*
* @since 2025.05.01
*
* @param array<int, IAddress> $bcc
*
* @return self
*/
public function setBcc(array $bcc): self;
/**
* Adds a blind carbon copy recipient (BCC)
*
* @since 2025.05.01
*
* @param IAddress $address
*
* @return self
*/
public function addBcc(IAddress $address): self;
/**
* Sets the message date
*
* @since 2025.05.01
*
* @param DateTimeImmutable|null $date
*
* @return self
*/
public function setDate(?DateTimeImmutable $date): self;
/**
* Sets the plain text body
*
* @since 2025.05.01
*
* @param string|null $text
*
* @return self
*/
public function setBodyText(?string $text): self;
/**
* Sets the HTML body
*
* @since 2025.05.01
*
* @param string|null $html
*
* @return self
*/
public function setBodyHtml(?string $html): self;
/**
* Sets the attachments
*
* @since 2025.05.01
*
* @param array<int, IAttachment> $attachments
*
* @return self
*/
public function setAttachments(array $attachments): self;
/**
* Adds an attachment
*
* @since 2025.05.01
*
* @param IAttachment $attachment
*
* @return self
*/
public function addAttachment(IAttachment $attachment): self;
/**
* Sets custom headers
*
* @since 2025.05.01
*
* @param array<string, string> $headers Header name => value
*
* @return self
*/
public function setHeaders(array $headers): self;
/**
* Sets a specific header value
*
* @since 2025.05.01
*
* @param string $name Header name
* @param string $value Header value
*
* @return self
*/
public function setHeader(string $name, string $value): self;
}

View File

@@ -1,383 +0,0 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Mail\Entity;
use DateTimeImmutable;
/**
* Mail Message Implementation
*
* Concrete implementation of IMessageMutable for composing mail messages.
*
* @since 2025.05.01
*/
class Message implements IMessageMutable {
private ?string $id = null;
private string $subject = '';
private ?IAddress $from = null;
private ?IAddress $replyTo = null;
/** @var array<int, IAddress> */
private array $to = [];
/** @var array<int, IAddress> */
private array $cc = [];
/** @var array<int, IAddress> */
private array $bcc = [];
private ?DateTimeImmutable $date = null;
private ?string $bodyText = null;
private ?string $bodyHtml = null;
/** @var array<int, IAttachment> */
private array $attachments = [];
/** @var array<string, string> */
private array $headers = [];
/**
* Creates a message from array data
*
* @since 2025.05.01
*
* @param array $data
*
* @return self
*/
public static function fromArray(array $data): self {
$message = new self();
if (isset($data[self::JSON_PROPERTY_ID])) {
$message->setId($data[self::JSON_PROPERTY_ID]);
}
if (isset($data[self::JSON_PROPERTY_SUBJECT])) {
$message->setSubject($data[self::JSON_PROPERTY_SUBJECT]);
}
if (isset($data[self::JSON_PROPERTY_FROM])) {
$message->setFrom(Address::fromArray($data[self::JSON_PROPERTY_FROM]));
}
if (isset($data[self::JSON_PROPERTY_REPLY_TO])) {
$message->setReplyTo(Address::fromArray($data[self::JSON_PROPERTY_REPLY_TO]));
}
if (isset($data[self::JSON_PROPERTY_TO])) {
$message->setTo(array_map(fn($a) => Address::fromArray($a), $data[self::JSON_PROPERTY_TO]));
}
if (isset($data[self::JSON_PROPERTY_CC])) {
$message->setCc(array_map(fn($a) => Address::fromArray($a), $data[self::JSON_PROPERTY_CC]));
}
if (isset($data[self::JSON_PROPERTY_BCC])) {
$message->setBcc(array_map(fn($a) => Address::fromArray($a), $data[self::JSON_PROPERTY_BCC]));
}
if (isset($data[self::JSON_PROPERTY_DATE])) {
$message->setDate(new DateTimeImmutable($data[self::JSON_PROPERTY_DATE]));
}
if (isset($data[self::JSON_PROPERTY_BODY_TEXT])) {
$message->setBodyText($data[self::JSON_PROPERTY_BODY_TEXT]);
}
if (isset($data[self::JSON_PROPERTY_BODY_HTML])) {
$message->setBodyHtml($data[self::JSON_PROPERTY_BODY_HTML]);
}
if (isset($data[self::JSON_PROPERTY_ATTACHMENTS])) {
$message->setAttachments(array_map(fn($a) => Attachment::fromArray($a), $data[self::JSON_PROPERTY_ATTACHMENTS]));
}
if (isset($data[self::JSON_PROPERTY_HEADERS])) {
$message->setHeaders($data[self::JSON_PROPERTY_HEADERS]);
}
return $message;
}
/**
* @inheritDoc
*/
public function getId(): ?string {
return $this->id;
}
/**
* @inheritDoc
*/
public function setId(?string $id): self {
$this->id = $id;
return $this;
}
/**
* @inheritDoc
*/
public function getSubject(): string {
return $this->subject;
}
/**
* @inheritDoc
*/
public function setSubject(string $subject): self {
$this->subject = $subject;
return $this;
}
/**
* @inheritDoc
*/
public function getFrom(): ?IAddress {
return $this->from;
}
/**
* @inheritDoc
*/
public function setFrom(?IAddress $from): self {
$this->from = $from;
return $this;
}
/**
* @inheritDoc
*/
public function getReplyTo(): ?IAddress {
return $this->replyTo;
}
/**
* @inheritDoc
*/
public function setReplyTo(?IAddress $replyTo): self {
$this->replyTo = $replyTo;
return $this;
}
/**
* @inheritDoc
*/
public function getTo(): array {
return $this->to;
}
/**
* @inheritDoc
*/
public function setTo(array $to): self {
$this->to = $to;
return $this;
}
/**
* @inheritDoc
*/
public function addTo(IAddress $address): self {
$this->to[] = $address;
return $this;
}
/**
* @inheritDoc
*/
public function getCc(): array {
return $this->cc;
}
/**
* @inheritDoc
*/
public function setCc(array $cc): self {
$this->cc = $cc;
return $this;
}
/**
* @inheritDoc
*/
public function addCc(IAddress $address): self {
$this->cc[] = $address;
return $this;
}
/**
* @inheritDoc
*/
public function getBcc(): array {
return $this->bcc;
}
/**
* @inheritDoc
*/
public function setBcc(array $bcc): self {
$this->bcc = $bcc;
return $this;
}
/**
* @inheritDoc
*/
public function addBcc(IAddress $address): self {
$this->bcc[] = $address;
return $this;
}
/**
* @inheritDoc
*/
public function getDate(): ?DateTimeImmutable {
return $this->date;
}
/**
* @inheritDoc
*/
public function setDate(?DateTimeImmutable $date): self {
$this->date = $date;
return $this;
}
/**
* @inheritDoc
*/
public function getBodyText(): ?string {
return $this->bodyText;
}
/**
* @inheritDoc
*/
public function setBodyText(?string $text): self {
$this->bodyText = $text;
return $this;
}
/**
* @inheritDoc
*/
public function getBodyHtml(): ?string {
return $this->bodyHtml;
}
/**
* @inheritDoc
*/
public function setBodyHtml(?string $html): self {
$this->bodyHtml = $html;
return $this;
}
/**
* @inheritDoc
*/
public function getAttachments(): array {
return $this->attachments;
}
/**
* @inheritDoc
*/
public function setAttachments(array $attachments): self {
$this->attachments = $attachments;
return $this;
}
/**
* @inheritDoc
*/
public function addAttachment(IAttachment $attachment): self {
$this->attachments[] = $attachment;
return $this;
}
/**
* @inheritDoc
*/
public function getHeaders(): array {
return $this->headers;
}
/**
* @inheritDoc
*/
public function getHeader(string $name): ?string {
return $this->headers[$name] ?? null;
}
/**
* @inheritDoc
*/
public function setHeaders(array $headers): self {
$this->headers = $headers;
return $this;
}
/**
* @inheritDoc
*/
public function setHeader(string $name, string $value): self {
$this->headers[$name] = $value;
return $this;
}
/**
* @inheritDoc
*/
public function hasRecipients(): bool {
return !empty($this->to) || !empty($this->cc) || !empty($this->bcc);
}
/**
* @inheritDoc
*/
public function hasBody(): bool {
return ($this->bodyText !== null && $this->bodyText !== '')
|| ($this->bodyHtml !== null && $this->bodyHtml !== '');
}
/**
* @inheritDoc
*/
public function jsonSerialize(): array {
$data = [
self::JSON_PROPERTY_TYPE => self::JSON_TYPE,
];
if ($this->id !== null) {
$data[self::JSON_PROPERTY_ID] = $this->id;
}
$data[self::JSON_PROPERTY_SUBJECT] = $this->subject;
if ($this->from !== null) {
$data[self::JSON_PROPERTY_FROM] = $this->from;
}
if ($this->replyTo !== null) {
$data[self::JSON_PROPERTY_REPLY_TO] = $this->replyTo;
}
if (!empty($this->to)) {
$data[self::JSON_PROPERTY_TO] = $this->to;
}
if (!empty($this->cc)) {
$data[self::JSON_PROPERTY_CC] = $this->cc;
}
if (!empty($this->bcc)) {
$data[self::JSON_PROPERTY_BCC] = $this->bcc;
}
if ($this->date !== null) {
$data[self::JSON_PROPERTY_DATE] = $this->date->format('c');
}
if ($this->bodyText !== null) {
$data[self::JSON_PROPERTY_BODY_TEXT] = $this->bodyText;
}
if ($this->bodyHtml !== null) {
$data[self::JSON_PROPERTY_BODY_HTML] = $this->bodyHtml;
}
if (!empty($this->attachments)) {
$data[self::JSON_PROPERTY_ATTACHMENTS] = $this->attachments;
}
if (!empty($this->headers)) {
$data[self::JSON_PROPERTY_HEADERS] = $this->headers;
}
return $data;
}
}