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(App $a, L10n $l10n, BaseURL $baseUrl, IConfig $config)
31 parent::__construct($l10n, $baseUrl, $config);
33 $siteName = $this->config->get('config', 'sitename');
35 if ($this->config->get('config', 'admin_name')) {
36 $this->siteAdmin = $l10n->t('%1$s, %2$s Administrator', $this->config->get('config', 'admin_name'), $siteName);
38 $this->siteAdmin = $l10n->t('%s Administrator', $siteName);
41 $this->senderAddress = $a->getSenderEmailAddress();
47 * @param string $subject The subject of the email
48 * @param string $preamble The preamble of the email
49 * @param string|null $body The body of the email (if not set, the preamble will get used as body)
53 public function withMessage(string $subject, string $preamble, string $body = null)
59 $this->subject = $subject;
60 $this->preamble = $preamble;
69 protected function getSubject()
71 return $this->subject;
77 * @throws InternalServerErrorException
80 protected function getHtmlMessage()
82 $htmlVersion = BBCode::convert($this->body);
84 // load the template for private message notifications
85 $tpl = Renderer::getMarkupTemplate('email/system/html.tpl');
86 return Renderer::replaceMacros($tpl, [
87 '$preamble' => str_replace("\n", "<br>\n", $this->preamble),
88 '$thanks' => $this->l10n->t('thanks'),
89 '$site_admin' => $this->siteAdmin,
90 '$htmlversion' => $htmlVersion,
99 protected function getPlaintextMessage()
101 $textVersion = BBCode::toPlaintext($this->body);
103 // load the template for private message notifications
104 $tpl = Renderer::getMarkupTemplate('email/system/text.tpl');
105 return Renderer::replaceMacros($tpl, [
106 '$preamble' => $this->preamble,
107 '$thanks' => $this->l10n->t('thanks'),
108 '$site_admin' => $this->siteAdmin,
109 '$textversion' => $textVersion,
116 public function build(bool $raw = false)
118 // for system emails, always use the sitename/site address as the sender
119 $this->withSender($this->config->get('config', 'sitename'), $this->senderAddress);
121 return parent::build($raw);