split mailbuilder types

This commit is contained in:
nupplaPhil 2020-02-04 21:27:52 +01:00
parent 34dce9fd76
commit cb08912926
No known key found for this signature in database
GPG Key ID: D8365C3D36B77D90
4 changed files with 34 additions and 12 deletions

View File

@ -502,7 +502,7 @@ function notification($params)
Hook::callAll('enotify_mail', $datarray);
$builder = DI::emailer()
->newNotifyMail($l10n)
->newNotifyMail()
->addHeaders($datarray['headers'])
->withRecipient($params['to_email'])
->forUser($datarray['uid'])

View File

@ -13,8 +13,18 @@ use Friendica\Network\HTTPException\InternalServerErrorException;
/**
* Builder for notification emails (notification, source, links, ...)
*/
class NotifyMailBuilder extends SystemMailBuilder
class NotifyMailBuilder extends MailBuilder
{
/** @var string */
protected $subject;
/** @var string */
protected $preamble;
/** @var string */
protected $body;
/** @var string */
protected $siteAdmin;
/** @var bool */
private $contentAllowed = true;
/** @var string */
@ -42,7 +52,16 @@ class NotifyMailBuilder extends SystemMailBuilder
public function __construct(L10n $l10n, BaseURL $baseUrl, IConfig $config, string $siteEmailAddress, string $siteName)
{
parent::__construct($l10n, $baseUrl, $config, $siteEmailAddress, $siteName);
parent::__construct($l10n, $baseUrl, $config);
if ($this->config->get('config', 'admin_name')) {
$this->siteAdmin = $l10n->t('%1$s, %2$s Administrator', $this->config->get('config', 'admin_name'), $siteName);
} else {
$this->siteAdmin = $l10n->t('%s Administrator', $siteName);
}
// Set the system wide site address/name as sender (default for system mails)
$this->withSender($siteName, $siteEmailAddress, $siteEmailAddress);
// check whether sending post content in email notifications is allowed
$this->contentAllowed = $this->config->get('system', 'enotify_no_content');
@ -60,9 +79,16 @@ class NotifyMailBuilder extends SystemMailBuilder
*/
public function withNotification(string $subject, string $preamble, string $title, string $body = null)
{
$this->title = stripslashes($title);
if (!isset($body)) {
$body = $preamble;
}
return $this->withMessage($subject, $preamble, $body);
$this->title = stripslashes($title);
$this->subject = $subject;
$this->preamble = $preamble;
$this->body = $body;
return $this;
}
/**

View File

@ -38,9 +38,7 @@ class SystemMailBuilder extends MailBuilder
}
// Set the system wide site address/name as sender (default for system mails)
$this->senderName = $siteName;
$this->senderAddress = $siteEmailAddress;
$this->senderNoReply = $siteEmailAddress;
$this->withSender($siteName, $siteEmailAddress, $siteEmailAddress);
}
/**

View File

@ -96,13 +96,11 @@ class Emailer
*
* @see Notify
*
* @param L10n $l10n The chosen language for the new email
*
* @return NotifyMailBuilder
*/
public function newNotifyMail(L10n $l10n)
public function newNotifyMail()
{
return new NotifyMailBuilder($l10n, $this->baseUrl, $this->config,
return new NotifyMailBuilder($this->l10n, $this->baseUrl, $this->config,
$this->getSiteEmailAddress(), $this->getSiteEmailName());
}