refactor: mail interfaces
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -21,188 +21,161 @@ use KTXF\Resource\Provider\Node\NodePropertiesBaseAbstract;
|
||||
*/
|
||||
abstract class MessagePropertiesBaseAbstract extends NodePropertiesBaseAbstract implements MessagePropertiesBaseInterface {
|
||||
|
||||
public const JSON_TYPE = MessagePropertiesBaseInterface::JSON_TYPE;
|
||||
protected string $type = 'mail.message';
|
||||
|
||||
/**
|
||||
* @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;
|
||||
public function jsonSerialize(): array {
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getSize(): ?int {
|
||||
return $this->data['size'] ?? null;
|
||||
return $this->data[static::PROPERTY_SIZE] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getSender(): ?AddressInterface {
|
||||
return $this->data['sender'] ?? null;
|
||||
public function getHeaders(): array {
|
||||
return $this->data[static::PROPERTY_HEADERS] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getFrom(): ?AddressInterface {
|
||||
return $this->data['from'] ?? null;
|
||||
public function getHeader(string $name): string|array|null {
|
||||
return $this->data[static::PROPERTY_HEADERS][$name] ?? 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'] ?? [];
|
||||
public function getUrid(): ?string {
|
||||
return $this->data[static::PROPERTY_URID] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getInReplyTo(): ?string {
|
||||
return $this->data['inReplyTo'] ?? null;
|
||||
return $this->data[static::PROPERTY_IN_REPLY_TO] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getReferences(): array {
|
||||
return $this->data['references'] ?? [];
|
||||
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['subject'] ?? '';
|
||||
return $this->data[static::PROPERTY_SUBJECT] ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getSnippet(): ?string {
|
||||
return $this->data['snippet'] ?? null;
|
||||
public function getBody(): ?MessagePartInterface {
|
||||
return $this->data[static::PROPERTY_BODY] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getBodyText(): ?string {
|
||||
return $this->data['bodyText'] ?? null;
|
||||
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 getBodyTextCharset(): ?string {
|
||||
return $this->data['bodyTextCharset'] ?? null;
|
||||
public function getBodyTextPlain(): ?string {
|
||||
return $this->data[static::PROPERTY_BODY_TEXT_PLAIN] ?? 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;
|
||||
public function getBodyTextHtml(): ?string {
|
||||
return $this->data[static::PROPERTY_BODY_TEXT_HTML] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getAttachments(): array {
|
||||
return $this->data['attachments'] ?? [];
|
||||
return $this->data[static::PROPERTY_ATTACHMENTS] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getFlags(): array {
|
||||
return $this->data['flags'] ?? [
|
||||
return $this->data[static::PROPERTY_FLAGS] ?? [
|
||||
'read' => false,
|
||||
'starred' => false,
|
||||
'important' => false,
|
||||
@@ -218,179 +191,7 @@ abstract class MessagePropertiesBaseAbstract extends NodePropertiesBaseAbstract
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getFlag(string $name): bool {
|
||||
return $this->data['flags'][$name] ?? false;
|
||||
return $this->data[static::PROPERTY_FLAGS][$name] ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets message labels
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function getLabels(): array {
|
||||
return $this->data['labels'] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets message tags
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
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_SCHEMA => $this->data['schema'] ?? 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'];
|
||||
}
|
||||
if (!empty($this->data['flags'])) {
|
||||
$data[self::JSON_PROPERTY_FLAGS] = $this->data['flags'];
|
||||
}
|
||||
|
||||
$data[self::JSON_PROPERTY_SUBJECT] = $this->data['subject'] ?? null;
|
||||
$data[self::JSON_PROPERTY_BODY] = $this->data['body'] ?? null;
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user