]> git.mxchange.org Git - friendica.git/commitdiff
Move "App::getSenderEmailAddress()" to "Emailer::getSiteEmailAddress()"
authornupplaPhil <admin+github@philipp.info>
Sat, 1 Feb 2020 22:32:03 +0000 (23:32 +0100)
committernupplaPhil <admin+github@philipp.info>
Sun, 2 Feb 2020 21:43:40 +0000 (22:43 +0100)
include/enotify.php
src/App.php
src/Module/Invite.php
src/Util/EMailer/SystemMailBuilder.php
src/Util/Emailer.php

index 54bf48234169948a00242dcbfc47b51056abb589..4423a36a0890e1d926d10a14eee0419377b59f15 100644 (file)
@@ -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']]);
index ceb11dd797ecdb567691e59208d82343d54626da..892a4c7790e4955283f13f05de000326e3f92645 100644 (file)
@@ -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.
         *
index df569377b9a9bb722470cac3fd954c59b993dcf5..fc8b4abf90671fdd99b4e4a78d95605750939ffb 100644 (file)
@@ -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';
 
index 41d758ba0a3a173f9cf8d37e041609405ff1a8b5..93e5cc349f4664c348fffcdffa62631f1f208b73 100644 (file)
@@ -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);
-       }
 }
index 3f9a491d7677ff71e914d10cb0c701f3d4ec9526..485857b9d7f8fd131e826be519f1e21dcf2c882e 100644 (file)
@@ -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());
        }
 
        /**