X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FObject%2FEmail.php;h=fdde4e96ddd751a329f4e16e434acdaddd79607f;hb=c2c563be26697169f734f2654ab491a4e8ffff2f;hp=4f9c4e7bd94164678e2ad3f63d147a1a5a1743a2;hpb=f2547947c9c699d3075882f46a11d3681bf1f306;p=friendica.git diff --git a/src/Object/Email.php b/src/Object/Email.php index 4f9c4e7bd9..fdde4e96dd 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; @@ -91,12 +110,12 @@ class Email implements IEmail /** * {@inheritDoc} */ - public function getMessage(bool $plain = false) + public function getMessage(bool $plain = false): string { if ($plain) { return $this->msgText; } else { - return $this->msgHtml; + return $this->msgHtml ?? ''; } } @@ -108,6 +127,26 @@ class Email implements IEmail return $this->additionalMailHeader; } + /** + * {@inheritDoc} + */ + public function getAdditionalMailHeaderString() + { + $headerString = ''; + + foreach ($this->additionalMailHeader as $name => $values) { + if (!is_array($values)) { + $values = [$values]; + } + + foreach ($values as $value) { + $headerString .= "$name: $value\r\n"; + } + } + + return $headerString; + } + /** * {@inheritDoc} */ @@ -117,40 +156,53 @@ 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; } /** - * Creates a new Email instance based on a given prototype - * - * @param static $prototype The base prototype - * @param array $data The delta-data (key must be an existing property) + * {@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 static The new email instance + * @return array */ - public static function createFromPrototype(Email $prototype, array $data = []) + private function toArray() { - $newMail = clone $prototype; + return get_object_vars($this); + } - foreach ($data as $key => $value) { - if (property_exists($newMail, $key)) { - $newMail->{$key} = $value; - } - } + /** + * @inheritDoc + */ + public function __toString() + { + return json_encode($this->toArray()); + } - return $newMail; + /** + * @inheritDoc + */ + #[\ReturnTypeWillChange] + public function jsonSerialize() + { + return $this->toArray(); } }