3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Object;
24 use Friendica\Object\EMail\IEmail;
27 * The default implementation of the IEmail interface
29 * Provides the possibility to reuse the email instance with new recipients (@see Email::withRecipient())
31 class Email implements IEmail
45 /** @var string|null */
51 private $additionalMailHeader = '';
53 private $toUid = null;
55 public function __construct(string $fromName, string $fromAddress, string $replyTo, string $toAddress,
56 string $subject, string $msgHtml, string $msgText,
57 string $additionalMailHeader = '', int $toUid = null)
59 $this->fromName = $fromName;
60 $this->fromAddress = $fromAddress;
61 $this->replyTo = $replyTo;
62 $this->toAddress = $toAddress;
63 $this->subject = $subject;
64 $this->msgHtml = $msgHtml;
65 $this->msgText = $msgText;
66 $this->additionalMailHeader = $additionalMailHeader;
67 $this->toUid = $toUid;
73 public function getFromName()
75 return $this->fromName;
81 public function getFromAddress()
83 return $this->fromAddress;
89 public function getReplyTo()
91 return $this->replyTo;
97 public function getToAddress()
99 return $this->toAddress;
105 public function getSubject()
107 return $this->subject;
113 public function getMessage(bool $plain = false)
116 return $this->msgText;
118 return $this->msgHtml;
125 public function getAdditionalMailHeader()
127 return $this->additionalMailHeader;
133 public function getRecipientUid()
141 public function withRecipient(string $address, int $uid = null)
143 $newEmail = clone $this;
144 $newEmail->toAddress = $address;
145 $newEmail->toUid = $uid;
153 public function withMessage(string $plaintext, string $html = null)
155 $newMail = clone $this;
156 $newMail->msgText = $plaintext;
157 $newMail->msgHtml = $html;
163 * Returns the properties of the email as an array
167 private function toArray()
169 return get_object_vars($this);
175 public function __toString()
177 return json_encode($this->toArray());
183 public function jsonSerialize()
185 return $this->toArray();