* SPDX-License-Identifier: AGPL-3.0-or-later */ namespace KTXF\Mail\Object; use DateTimeImmutable; /** * Abstract Message Properties Mutable Class * * Provides common implementation for mutable message properties * * @since 2025.05.01 */ abstract class MessagePropertiesMutableAbstract extends MessagePropertiesBaseAbstract implements MessagePropertiesMutableInterface { public const JSON_TYPE = MessagePropertiesBaseInterface::JSON_TYPE; /** * @inheritDoc */ public function setHeaders(array $value): static { $this->data['headers'] = $value; return $this; } /** * @inheritDoc */ public function setHeader(string $name, string|array $value): static { $this->data['headers'][$name] = $value; return $this; } /** * @inheritDoc */ public function setUrid(?string $value): static { $this->data['urid'] = $value; return $this; } /** * @inheritDoc */ public function setCreated(DateTimeImmutable $value): static { $this->data['created'] = $value; return $this; } /** * @inheritDoc */ public function setModified(DateTimeImmutable $value): static { $this->data['modified'] = $value; return $this; } /** * @inheritDoc */ public function setDate(DateTimeImmutable $value): static { $this->data['date'] = $value; return $this; } /** * @inheritDoc */ public function setReceived(?DateTimeImmutable $value): static { $this->data['received'] = $value; return $this; } /** * @inheritDoc */ public function setSize(?int $value): static { $this->data['size'] = $value; return $this; } /** * @inheritDoc */ public function setSender(?AddressInterface $value): static { $this->data['sender'] = $value; return $this; } /** * @inheritDoc */ public function setFrom(AddressInterface $value): static { $this->data['from'] = $value; return $this; } /** * @inheritDoc */ public function setReplyTo(AddressInterface ...$value): static { $this->data['replyTo'] = $value; return $this; } /** * @inheritDoc */ public function setTo(AddressInterface ...$value): static { $this->data['to'] = $value; return $this; } /** * @inheritDoc */ public function setCc(AddressInterface ...$value): static { $this->data['cc'] = $value; return $this; } /** * @inheritDoc */ public function setBcc(AddressInterface ...$value): static { $this->data['bcc'] = $value; return $this; } /** * @inheritDoc */ public function setInReplyTo(?string $value): static { $this->data['inReplyTo'] = $value; return $this; } /** * @inheritDoc */ public function setReferences(string ...$value): static { $this->data['references'] = $value; return $this; } /** * @inheritDoc */ public function setSubject(string $value): static { $this->data['subject'] = $value; return $this; } /** * @inheritDoc */ public function setSnippet(?string $value): static { $this->data['snippet'] = $value; return $this; } /** * @inheritDoc */ public function setBodyText(?string $value): static { $this->data['bodyText'] = $value; return $this; } /** * Sets the plain text body charset * * @since 2025.05.01 * * @param string $value * * @return static */ public function setBodyTextCharset(string $value): static { $this->data['bodyTextCharset'] = $value; return $this; } /** * Sets the plain text body size * * @since 2025.05.01 * * @param int $value * * @return static */ public function setBodyTextSize(int $value): static { $this->data['bodyTextSize'] = $value; return $this; } /** * @inheritDoc */ public function setBodyHtml(?string $value): static { $this->data['bodyHtml'] = $value; return $this; } /** * Sets the HTML body charset * * @since 2025.05.01 * * @param string $value * * @return static */ public function setBodyHtmlCharset(string $value): static { $this->data['bodyHtmlCharset'] = $value; return $this; } /** * Sets the HTML body size * * @since 2025.05.01 * * @param int $value * * @return static */ public function setBodyHtmlSize(int $value): static { $this->data['bodyHtmlSize'] = $value; return $this; } /** * @inheritDoc */ public function setAttachments(AttachmentInterface ...$value): static { $this->data['attachments'] = $value; return $this; } /** * @inheritDoc */ public function addAttachment(AttachmentInterface $value): static { $this->data['attachments'][] = $value; return $this; } /** * Sets message flags * * @since 2025.05.01 * * @param array $value * * @return static */ public function setFlags(array $value): static { if (!isset($this->data['flags'])) { $this->data['flags'] = [ 'read' => false, 'starred' => false, 'important' => false, 'answered' => false, 'forwarded' => false, 'draft' => false, 'deleted' => false, 'flagged' => false, ]; } $this->data['flags'] = array_merge($this->data['flags'], $value); return $this; } /** * @inheritDoc */ public function setFlag(string $name, bool $value): static { if (!isset($this->data['flags'])) { $this->data['flags'] = [ 'read' => false, 'starred' => false, 'important' => false, 'answered' => false, 'forwarded' => false, 'draft' => false, 'deleted' => false, 'flagged' => false, ]; } if (array_key_exists($name, $this->data['flags'])) { $this->data['flags'][$name] = $value; } return $this; } /** * Sets message labels * * @since 2025.05.01 * * @param string ...$value * * @return static */ public function setLabels(string ...$value): static { $this->data['labels'] = $value; return $this; } /** * Adds a message label * * @since 2025.05.01 * * @param string $value * * @return static */ public function addLabel(string $value): static { $this->data['labels'][] = $value; return $this; } /** * Sets message tags * * @since 2025.05.01 * * @param string ...$value * * @return static */ public function setTags(string ...$value): static { $this->data['tags'] = $value; return $this; } /** * Adds a message tag * * @since 2025.05.01 * * @param string $value * * @return static */ public function addTag(string $value): static { $this->data['tags'][] = $value; return $this; } /** * Sets message priority * * @since 2025.05.01 * * @param string $value * * @return static */ public function setPriority(string $value): static { $this->data['priority'] = $value; return $this; } /** * Sets message sensitivity * * @since 2025.05.01 * * @param string $value * * @return static */ public function setSensitivity(string $value): static { $this->data['sensitivity'] = $value; return $this; } /** * Sets encryption information * * @since 2025.05.01 * * @param array $value * * @return static */ public function setEncryption(array $value): static { if (!isset($this->data['encryption'])) { $this->data['encryption'] = [ 'method' => null, 'signed' => false, 'encrypted' => false, ]; } $this->data['encryption'] = array_merge($this->data['encryption'], $value); return $this; } /** * Sets delivery receipt flag * * @since 2025.05.01 * * @param bool $value * * @return static */ public function setDeliveryReceipt(bool $value): static { $this->data['deliveryReceipt'] = $value; return $this; } /** * Sets read receipt flag * * @since 2025.05.01 * * @param bool $value * * @return static */ public function setReadReceipt(bool $value): static { $this->data['readReceipt'] = $value; return $this; } /** * @inheritDoc */ public function jsonDeserialize(array|string $data): static { if (is_string($data)) { $data = json_decode($data, true); } // Merge deserialized data into internal storage foreach ($data as $key => $value) { if (!in_array($key, ['collection', 'identifier', 'signature', 'created', 'modified'])) { $this->data[$key] = $value; } } return $this; } }