3 namespace Friendica\Util\EMailer;
7 use Friendica\App\BaseURL;
8 use Friendica\Content\Text\BBCode;
9 use Friendica\Core\Config\IConfig;
10 use Friendica\Core\L10n;
11 use Friendica\Core\Renderer;
12 use Friendica\Network\HTTPException\InternalServerErrorException;
15 * Builder for system-wide emails without any dependency to concrete entities (like items, activities, ..)
17 class SystemMailBuilder extends MailBuilder
29 public function __construct(L10n $l10n, BaseURL $baseUrl, IConfig $config, string $siteEmailAddress, string $siteName)
31 parent::__construct($l10n, $baseUrl, $config);
33 if ($this->config->get('config', 'admin_name')) {
34 $this->siteAdmin = $l10n->t('%1$s, %2$s Administrator', $this->config->get('config', 'admin_name'), $siteName);
36 $this->siteAdmin = $l10n->t('%s Administrator', $siteName);
39 // Set the system wide site address/name as sender (default for system mails)
40 $this->withSender($siteEmailAddress, $siteName);
46 * @param string $subject The subject of the email
47 * @param string $preamble The preamble of the email
48 * @param string|null $body The body of the email (if not set, the preamble will get used as body)
52 public function withMessage(string $subject, string $preamble, string $body = null)
58 $this->subject = $subject;
59 $this->preamble = $preamble;
68 protected function getSubject()
70 return $this->subject;
76 * @throws InternalServerErrorException
79 protected function getHtmlMessage()
81 $htmlVersion = BBCode::convert($this->body);
83 // load the template for private message notifications
84 $tpl = Renderer::getMarkupTemplate('email/system/html.tpl');
85 return Renderer::replaceMacros($tpl, [
86 '$preamble' => str_replace("\n", "<br>\n", $this->preamble),
87 '$thanks' => $this->l10n->t('thanks'),
88 '$site_admin' => $this->siteAdmin,
89 '$htmlversion' => $htmlVersion,
98 protected function getPlaintextMessage()
100 $textVersion = BBCode::toPlaintext($this->body);
102 // load the template for private message notifications
103 $tpl = Renderer::getMarkupTemplate('email/system/text.tpl');
104 return Renderer::replaceMacros($tpl, [
105 '$preamble' => $this->preamble,
106 '$thanks' => $this->l10n->t('thanks'),
107 '$site_admin' => $this->siteAdmin,
108 '$textversion' => $textVersion,