diff --git a/include/enotify.php b/include/enotify.php index 54bf482341..4423a36a08 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -72,7 +72,7 @@ function notification($params) $hostname = substr($hostname, 0, strpos($hostname, ':')); } - $sender_email = $a->getSenderEmailAddress(); + $sender_email = DI::emailer()->getSiteEmailAddress(); $user = DBA::selectFirst('user', ['nickname', 'page-flags'], ['uid' => $params['uid']]); diff --git a/src/App.php b/src/App.php index ceb11dd797..892a4c7790 100644 --- a/src/App.php +++ b/src/App.php @@ -242,27 +242,6 @@ class App $this->baseURL->get(); } - /** - * Generates the site's default sender email address - * - * @return string - * @throws HTTPException\InternalServerErrorException - */ - public function getSenderEmailAddress() - { - $sender_email = $this->config->get('config', 'sender_email'); - if (empty($sender_email)) { - $hostname = $this->baseURL->getHostname(); - if (strpos($hostname, ':')) { - $hostname = substr($hostname, 0, strpos($hostname, ':')); - } - - $sender_email = 'noreply@' . $hostname; - } - - return $sender_email; - } - /** * Returns the current theme name. May be overriden by the mobile theme name. * diff --git a/src/Module/Invite.php b/src/Module/Invite.php index df569377b9..fc8b4abf90 100644 --- a/src/Module/Invite.php +++ b/src/Module/Invite.php @@ -77,7 +77,7 @@ class Invite extends BaseModule } $additional_headers = 'From: ' . $app->user['email'] . "\n" - . 'Sender: ' . $app->getSenderEmailAddress() . "\n" + . 'Sender: ' . DI::emailer()->getSiteEmailAddress() . "\n" . 'Content-type: text/plain; charset=UTF-8' . "\n" . 'Content-transfer-encoding: 8bit'; diff --git a/src/Util/EMailer/SystemMailBuilder.php b/src/Util/EMailer/SystemMailBuilder.php index 41d758ba0a..93e5cc349f 100644 --- a/src/Util/EMailer/SystemMailBuilder.php +++ b/src/Util/EMailer/SystemMailBuilder.php @@ -26,19 +26,18 @@ class SystemMailBuilder extends MailBuilder /** @var string */ protected $siteAdmin; - public function __construct(App $a, L10n $l10n, BaseURL $baseUrl, IConfig $config) + public function __construct(L10n $l10n, BaseURL $baseUrl, IConfig $config, string $siteEmailAddress, string $siteName) { parent::__construct($l10n, $baseUrl, $config); - $siteName = $this->config->get('config', 'sitename'); - 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); } - $this->senderAddress = $a->getSenderEmailAddress(); + // Set the system wide site address/name as sender (default for system mails) + $this->withSender($siteEmailAddress, $siteName); } /** @@ -109,15 +108,4 @@ class SystemMailBuilder extends MailBuilder '$textversion' => $textVersion, ]); } - - /** - * {@inheritDoc} - */ - public function build(bool $raw = false) - { - // for system emails, always use the sitename/site address as the sender - $this->withSender($this->config->get('config', 'sitename'), $this->senderAddress); - - return parent::build($raw); - } } diff --git a/src/Util/Emailer.php b/src/Util/Emailer.php index 3f9a491d76..485857b9d7 100644 --- a/src/Util/Emailer.php +++ b/src/Util/Emailer.php @@ -29,25 +29,62 @@ class Emailer /** @var App\BaseURL */ private $baseUrl; + /** @var string */ + private $siteEmailAddress; + /** @var string */ + private $siteEmailName; + public function __construct(IConfig $config, IPConfig $pConfig, App\BaseURL $baseURL, LoggerInterface $logger) { $this->config = $config; $this->pConfig = $pConfig; $this->logger = $logger; $this->baseUrl = $baseURL; + + $this->siteEmailAddress = $this->config->get('config', 'sender_email'); + if (empty($sysEmailAddress)) { + $hostname = $this->baseUrl->getHostname(); + if (strpos($hostname, ':')) { + $hostname = substr($hostname, 0, strpos($hostname, ':')); + } + + $this->siteEmailAddress = 'noreply@' . $hostname; + } + + $this->siteEmailName = $this->config->get('config', 'sitename', 'Friendica Social Network'); + } + + /** + * Gets the site's default sender email address + * + * @return string + */ + public function getSiteEmailAddress() + { + return $this->siteEmailAddress; + } + + /** + * Gets the site's default sender name + * + * @return string + */ + public function getSiteEmailName() + { + return $this->siteEmailName; } /** * Creates a new system email * - * @param App $a The Friendica app * @param L10n $l10n The chosen language for the new email * * @return SystemMailBuilder */ - public function newSystemMail(App $a, L10n $l10n) + public function newSystemMail(L10n $l10n) { - return new SystemMailBuilder($a, $l10n, $this->baseUrl, $this->config); + return new SystemMailBuilder($l10n, $this->baseUrl, $this->config, + $this->getSiteEmailAddress(), $this->getSiteEmailName()); } /**