3 namespace Friendica\Util\EMailer;
6 use Friendica\App\BaseURL;
7 use Friendica\Content\Text\BBCode;
8 use Friendica\Core\Config\IConfig;
9 use Friendica\Core\L10n;
10 use Friendica\Core\Renderer;
11 use Friendica\Network\HTTPException\InternalServerErrorException;
12 use Psr\Log\LoggerInterface;
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, LoggerInterface $logger,
30 string $siteEmailAddress, string $siteName)
32 parent::__construct($l10n, $baseUrl, $config, $logger);
34 if ($this->config->get('config', 'admin_name')) {
35 $this->siteAdmin = $l10n->t('%1$s, %2$s Administrator', $this->config->get('config', 'admin_name'), $siteName);
37 $this->siteAdmin = $l10n->t('%s Administrator', $siteName);
40 // Set the system wide site address/name as sender (default for system mails)
41 $this->senderName = $siteName;
42 $this->senderAddress = $siteEmailAddress;
43 $this->senderNoReply = $siteEmailAddress;
49 * @param string $subject The subject of the email
50 * @param string $preamble The preamble of the email
51 * @param string|null $body The body of the email (if not set, the preamble will get used as body)
55 public function withMessage(string $subject, string $preamble, string $body = null)
61 $this->subject = $subject;
62 $this->preamble = $preamble;
71 protected function getSubject()
73 return $this->subject;
79 * @throws InternalServerErrorException
82 protected function getHtmlMessage()
84 $htmlVersion = BBCode::convert($this->body);
86 // load the template for private message notifications
87 $tpl = Renderer::getMarkupTemplate('email/system/html.tpl');
88 return Renderer::replaceMacros($tpl, [
89 '$preamble' => str_replace("\n", "<br>\n", $this->preamble),
90 '$thanks' => $this->l10n->t('thanks'),
91 '$site_admin' => $this->siteAdmin,
92 '$htmlversion' => $htmlVersion,
101 protected function getPlaintextMessage()
103 $textVersion = BBCode::toPlaintext($this->body);
105 // load the template for private message notifications
106 $tpl = Renderer::getMarkupTemplate('email/system/text.tpl');
107 return Renderer::replaceMacros($tpl, [
108 '$preamble' => $this->preamble,
109 '$thanks' => $this->l10n->t('thanks'),
110 '$site_admin' => $this->siteAdmin,
111 '$textversion' => $textVersion,