X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FObject%2FEmail.php;h=62a6d4622433470438b93c677d921a0d2112b7a8;hb=d936cc5a5c2755a0056ff12a297bf0fa25dc6bf1;hp=23e1fcfcd585f702a9f05b753dcefee5df7505c7;hpb=df61be84fc3865f14c6ed84f0d20d86b2ad1f6e8;p=friendica.git diff --git a/src/Object/Email.php b/src/Object/Email.php index 23e1fcfcd5..62a6d46224 100644 --- a/src/Object/Email.php +++ b/src/Object/Email.php @@ -1,4 +1,23 @@ . + * + */ namespace Friendica\Object; @@ -23,19 +42,19 @@ class Email implements IEmail /** @var string */ private $subject; - /** @var string */ + /** @var string|null */ private $msgHtml; /** @var string */ private $msgText; - /** @var string */ - private $additionalMailHeader = ''; + /** @var string[][] */ + private $additionalMailHeader; /** @var int|null */ - private $toUid = null; + private $toUid; public function __construct(string $fromName, string $fromAddress, string $replyTo, string $toAddress, string $subject, string $msgHtml, string $msgText, - string $additionalMailHeader = '', int $toUid = null) + array $additionalMailHeader = [], int $toUid = null) { $this->fromName = $fromName; $this->fromAddress = $fromAddress; @@ -108,6 +127,25 @@ class Email implements IEmail return $this->additionalMailHeader; } + /** + * {@inheritDoc} + */ + public function getAdditionalMailHeaderString() + { + $headerString = ''; + + foreach ($this->additionalMailHeader as $name => $values) { + if (is_array($values)) { + foreach ($values as $value) { + $headerString .= "$name: $value\n"; + } + } else { + $headerString .= "$name: $values\n"; + } + } + return $headerString; + } + /** * {@inheritDoc} */ @@ -117,19 +155,52 @@ class Email implements IEmail } /** - * Returns the current email with a new recipient - * - * @param string $email The email of the recipient - * @param int $uid The (optional) UID of the recipient for further infos - * - * @return static + * {@inheritDoc} */ - public function withRecipient(string $email, int $uid = null) + public function withRecipient(string $address, int $uid = null) { $newEmail = clone $this; - $newEmail->toAddress = $email; + $newEmail->toAddress = $address; $newEmail->toUid = $uid; return $newEmail; } + + /** + * {@inheritDoc} + */ + public function withMessage(string $plaintext, string $html = null) + { + $newMail = clone $this; + $newMail->msgText = $plaintext; + $newMail->msgHtml = $html; + + return $newMail; + } + + /** + * Returns the properties of the email as an array + * + * @return array + */ + private function toArray() + { + return get_object_vars($this); + } + + /** + * @inheritDoc + */ + public function __toString() + { + return json_encode($this->toArray()); + } + + /** + * @inheritDoc + */ + public function jsonSerialize() + { + return $this->toArray(); + } }