* 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 { protected string $type = 'mail.message'; /** * @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; } /** * @inheritDoc */ public function setSize(?int $value): static { $this->data[static::PROPERTY_SIZE] = $value; return $this; } /** * @inheritDoc */ public function setHeaders(array $value): static { $this->data[static::PROPERTY_HEADERS] = $value; return $this; } /** * @inheritDoc */ public function setHeader(string $name, string|array $value): static { $this->data[static::PROPERTY_HEADERS][$name] = $value; return $this; } /** * @inheritDoc */ public function setUrid(?string $value): static { $this->data[static::PROPERTY_URID] = $value; return $this; } /** * @inheritDoc */ public function setInReplyTo(?string $value): static { $this->data[static::PROPERTY_IN_REPLY_TO] = $value; return $this; } /** * @inheritDoc */ public function setReferences(string ...$value): static { $this->data[static::PROPERTY_REFERENCES] = $value; return $this; } /** * @inheritDoc */ public function setReceived(?DateTimeImmutable $value): static { $this->data[static::PROPERTY_RECEIVED] = $value; return $this; } /** * @inheritDoc */ public function setSent(DateTimeImmutable $value): static { $this->data[static::PROPERTY_SENT] = $value; return $this; } /** * @inheritDoc */ public function setSender(?AddressInterface $value): static { $this->data[static::PROPERTY_SENDER] = $value; return $this; } /** * @inheritDoc */ public function setFrom(AddressInterface $value): static { $this->data[static::PROPERTY_FROM] = $value; return $this; } /** * @inheritDoc */ public function setReplyTo(AddressInterface ...$value): static { $this->data[static::PROPERTY_REPLY_TO] = $value; return $this; } /** * @inheritDoc */ public function setTo(AddressInterface ...$value): static { $this->data[static::PROPERTY_TO] = $value; return $this; } /** * @inheritDoc */ public function setCc(AddressInterface ...$value): static { $this->data[static::PROPERTY_CC] = $value; return $this; } /** * @inheritDoc */ public function setBcc(AddressInterface ...$value): static { $this->data[static::PROPERTY_BCC] = $value; return $this; } /** * @inheritDoc */ public function setSubject(string $value): static { $this->data[static::PROPERTY_SUBJECT] = $value; return $this; } /** * @inheritDoc */ public function setBody(?MessagePartInterface $value): static { $this->data[static::PROPERTY_BODY] = $value; return $this; } /** * @inheritDoc */ public function setBodyTextPlain(?string $value): static { $this->data[static::PROPERTY_BODY_TEXT_PLAIN] = $value; return $this; } /** * @inheritDoc */ public function setBodyTextHtml(?string $value): static { $this->data[static::PROPERTY_BODY_TEXT_HTML] = $value; return $this; } /** * @inheritDoc */ public function setAttachments(AttachmentInterface ...$value): static { $this->data[static::PROPERTY_ATTACHMENTS] = $value; return $this; } /** * @inheritDoc */ public function addAttachment(AttachmentInterface $value): static { $this->data[static::PROPERTY_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[static::PROPERTY_FLAGS])) { $this->data[static::PROPERTY_FLAGS] = [ 'read' => false, 'starred' => false, 'important' => false, 'answered' => false, 'forwarded' => false, 'draft' => false, 'deleted' => false, 'flagged' => false, ]; } $this->data[static::PROPERTY_FLAGS] = array_merge($this->data[static::PROPERTY_FLAGS], $value); return $this; } /** * @inheritDoc */ public function setFlag(string $name, bool $value): static { if (!isset($this->data[static::PROPERTY_FLAGS])) { $this->data[static::PROPERTY_FLAGS] = [ 'read' => false, 'starred' => false, 'important' => false, 'answered' => false, 'forwarded' => false, 'draft' => false, 'deleted' => false, 'flagged' => false, ]; } if (array_key_exists($name, $this->data[static::PROPERTY_FLAGS])) { $this->data[static::PROPERTY_FLAGS][$name] = $value; } return $this; } }