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->senderName = $siteName;
41 $this->senderAddress = $siteEmailAddress;
42 $this->senderNoReply = $siteEmailAddress;
48 * @param string $subject The subject of the email
49 * @param string $preamble The preamble of the email
50 * @param string|null $body The body of the email (if not set, the preamble will get used as body)
54 public function withMessage(string $subject, string $preamble, string $body = null)
60 $this->subject = $subject;
61 $this->preamble = $preamble;
70 protected function getSubject()
72 return $this->subject;
78 * @throws InternalServerErrorException
81 protected function getHtmlMessage()
83 $htmlVersion = BBCode::convert($this->body);
85 // load the template for private message notifications
86 $tpl = Renderer::getMarkupTemplate('email/system/html.tpl');
87 return Renderer::replaceMacros($tpl, [
88 '$preamble' => str_replace("\n", "<br>\n", $this->preamble),
89 '$thanks' => $this->l10n->t('thanks'),
90 '$site_admin' => $this->siteAdmin,
91 '$htmlversion' => $htmlVersion,
100 protected function getPlaintextMessage()
102 $textVersion = BBCode::toPlaintext($this->body);
104 // load the template for private message notifications
105 $tpl = Renderer::getMarkupTemplate('email/system/text.tpl');
106 return Renderer::replaceMacros($tpl, [
107 '$preamble' => $this->preamble,
108 '$thanks' => $this->l10n->t('thanks'),
109 '$site_admin' => $this->siteAdmin,
110 '$textversion' => $textVersion,