3 namespace Friendica\Object;
5 use Friendica\Object\EMail\IEmail;
8 * The default implementation of the IEmail interface
10 * Provides the possibility to reuse the email instance with new recipients (@see Email::withRecipient())
12 class Email implements IEmail
26 /** @var string|null */
32 private $additionalMailHeader = '';
34 private $toUid = null;
36 public function __construct(string $fromName, string $fromAddress, string $replyTo, string $toAddress,
37 string $subject, string $msgHtml, string $msgText,
38 string $additionalMailHeader = '', int $toUid = null)
40 $this->fromName = $fromName;
41 $this->fromAddress = $fromAddress;
42 $this->replyTo = $replyTo;
43 $this->toAddress = $toAddress;
44 $this->subject = $subject;
45 $this->msgHtml = $msgHtml;
46 $this->msgText = $msgText;
47 $this->additionalMailHeader = $additionalMailHeader;
48 $this->toUid = $toUid;
54 public function getFromName()
56 return $this->fromName;
62 public function getFromAddress()
64 return $this->fromAddress;
70 public function getReplyTo()
72 return $this->replyTo;
78 public function getToAddress()
80 return $this->toAddress;
86 public function getSubject()
88 return $this->subject;
94 public function getMessage(bool $plain = false)
97 return $this->msgText;
99 return $this->msgHtml;
106 public function getAdditionalMailHeader()
108 return $this->additionalMailHeader;
114 public function getRecipientUid()
122 public function withRecipient(string $address, int $uid = null)
124 $newEmail = clone $this;
125 $newEmail->toAddress = $address;
126 $newEmail->toUid = $uid;
134 public function withMessage(string $plaintext, string $html = null)
136 $newMail = clone $this;
137 $newMail->msgText = $plaintext;
138 $newMail->msgHtml = $html;
144 * Returns the properties of the email as an array
148 private function toArray()
150 return get_object_vars($this);
156 public function __toString()
158 return json_encode($this->toArray());
164 public function jsonSerialize()
166 return $this->toArray();