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\Util\EMailer;
25 use Friendica\App\BaseURL;
26 use Friendica\Content\Text\BBCode;
27 use Friendica\Core\Config\IConfig;
28 use Friendica\Core\L10n;
29 use Friendica\Core\Renderer;
30 use Friendica\Network\HTTPException\InternalServerErrorException;
31 use Psr\Log\LoggerInterface;
34 * Builder for system-wide emails without any dependency to concrete entities (like items, activities, ..)
36 class SystemMailBuilder extends MailBuilder
48 public function __construct(L10n $l10n, BaseURL $baseUrl, IConfig $config, LoggerInterface $logger,
49 string $siteEmailAddress, string $siteName)
51 parent::__construct($l10n, $baseUrl, $config, $logger);
53 if ($this->config->get('config', 'admin_name')) {
54 $this->siteAdmin = $l10n->t('%1$s, %2$s Administrator', $this->config->get('config', 'admin_name'), $siteName);
56 $this->siteAdmin = $l10n->t('%s Administrator', $siteName);
59 // Set the system wide site address/name as sender (default for system mails)
60 $this->withSender($siteName, $siteEmailAddress, $siteEmailAddress);
66 * @param string $subject The subject of the email
67 * @param string $preamble The preamble of the email
68 * @param string|null $body The body of the email (if not set, the preamble will get used as body)
72 public function withMessage(string $subject, string $preamble, string $body = null)
78 $this->subject = $subject;
79 $this->preamble = $preamble;
88 protected function getSubject()
90 return $this->subject;
96 * @throws InternalServerErrorException
99 protected function getHtmlMessage()
101 $htmlVersion = BBCode::convert($this->body);
103 // load the template for private message notifications
104 $tpl = Renderer::getMarkupTemplate('email/system/html.tpl');
105 return Renderer::replaceMacros($tpl, [
106 '$preamble' => str_replace("\n", "<br>\n", $this->preamble),
107 '$thanks' => $this->l10n->t('thanks'),
108 '$site_admin' => $this->siteAdmin,
109 '$htmlversion' => $htmlVersion,
118 protected function getPlaintextMessage()
120 $textVersion = BBCode::toPlaintext($this->body);
122 // load the template for private message notifications
123 $tpl = Renderer::getMarkupTemplate('email/system/text.tpl');
124 return Renderer::replaceMacros($tpl, [
125 '$preamble' => $this->preamble,
126 '$thanks' => $this->l10n->t('thanks'),
127 '$site_admin' => $this->siteAdmin,
128 '$textversion' => $textVersion,