3 * @copyright Copyright (C) 2010-2022, the Friendica project
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\Capability\IManageConfigValues;
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
39 protected $subject = '';
41 protected $preamble = '';
48 public function __construct(L10n $l10n, BaseURL $baseUrl, IManageConfigValues $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 $body The body of the email (optional)
72 public function withMessage(string $subject, string $preamble, string $body = '')
74 $this->subject = $subject;
75 $this->preamble = $preamble;
84 protected function getSubject()
86 return $this->subject;
92 * @throws InternalServerErrorException
95 protected function getHtmlMessage()
97 // load the template for private message notifications
98 $tpl = Renderer::getMarkupTemplate('email/system/html.tpl');
99 return Renderer::replaceMacros($tpl, [
100 '$preamble' => str_replace("\n", "<br>\n", $this->preamble),
101 '$thanks' => $this->l10n->t('thanks'),
102 '$site_admin' => $this->siteAdmin,
103 '$htmlversion' => BBCode::convert($this->body),
112 protected function getPlaintextMessage()
114 // load the template for private message notifications
115 $tpl = Renderer::getMarkupTemplate('email/system/text.tpl');
116 return Renderer::replaceMacros($tpl, [
117 '$preamble' => $this->preamble,
118 '$thanks' => $this->l10n->t('thanks'),
119 '$site_admin' => $this->siteAdmin,
120 '$textversion' => BBCode::toPlaintext($this->body),