]> git.mxchange.org Git - friendica.git/commitdiff
Set Sitename / site email as sender for system emails
authornupplaPhil <admin+github@philipp.info>
Sat, 1 Feb 2020 21:30:10 +0000 (22:30 +0100)
committernupplaPhil <admin+github@philipp.info>
Sun, 2 Feb 2020 21:43:39 +0000 (22:43 +0100)
mod/lostpass.php
mod/removeme.php
src/Core/Update.php
src/Model/User.php
src/Module/Admin/Users.php
src/Util/EMailer/MailBuilder.php
src/Util/EMailer/SystemMailBuilder.php
src/Util/Emailer.php

index e412c495865dcb7f101025bd37437f22a6508dd6..04316a0996fcbbadb3cc4a033ebbc03f5d2e2a44 100644 (file)
@@ -65,7 +65,7 @@ function lostpass_post(App $a)
                Login Name:     %3$s', $resetlink, DI::baseUrl(), $user['nickname']));
 
        $email = DI::emailer()
-                  ->newSystemMail((!empty($user['language'])) ? DI::l10n()->withLang($user['language']) : DI::l10n())
+                  ->newSystemMail(DI::app(), (!empty($user['language'])) ? DI::l10n()->withLang($user['language']) : DI::l10n())
                   ->withMessage(DI::l10n()->t('Password reset requested at %s', $sitename), $preamble, $body)
                   ->forUser($user['uid'] ?? 0)
                   ->withRecipient($user['email'])
@@ -157,7 +157,7 @@ function lostpass_generate_password($user)
                ', DI::baseUrl(), $user['nickname'], $new_password));
 
                $email = DI::emailer()
-                          ->newSystemMail((!empty($user['language'])) ? DI::l10n()->withLang($user['language']) : DI::l10n())
+                          ->newSystemMail(DI::app(), (!empty($user['language'])) ? DI::l10n()->withLang($user['language']) : DI::l10n())
                           ->withMessage(DI::l10n()->t('Your password has been changed at %s', $sitename), $preamble, $body)
                           ->forUser($user['uid'] ?? 0)
                           ->withRecipient($user['email'])
index 86d1f04e34c15e96f29609b8a9466a5968a1b9f7..01a9b86da8e0003d146f8e41ef7599dd4162179d 100644 (file)
@@ -42,7 +42,7 @@ function removeme_post(App $a)
                }
 
                $email = DI::emailer()
-                          ->newSystemMail((!empty($admin['language'])) ? DI::l10n()->withLang($admin['language']) : DI::l10n()->withLang('en'))
+                          ->newSystemMail(DI::app(), (!empty($admin['language'])) ? DI::l10n()->withLang($admin['language']) : DI::l10n()->withLang('en'))
                           ->withMessage(DI::l10n()->t('[Friendica System Notify]') . ' ' . DI::l10n()->t('User deleted their account'),
                                   DI::l10n()->t('On your Friendica node an user deleted their account. Please ensure that their data is removed from the backups.'),
                                   DI::l10n()->t('The user id is %d', local_user()))
index 2a3b3a68d69ad9b26bcd37cc6a9578ca0ddb8c1a..6eb056f57370421653183217f879c9e76ffa9c9b 100644 (file)
@@ -264,7 +264,7 @@ class Update
                        $body     = $l10n->t("The error message is\n[pre]%s[/pre]", $error_message);
 
                        $email = DI::emailer()
-                                  ->newSystemMail($l10n)
+                                  ->newSystemMail(DI::app(), $l10n)
                                   ->withMessage($l10n->t('[Friendica Notify] Database update'), $preamble, $body)
                                   ->forUser($admin['uid'] ?? 0)
                                   ->withRecipient($admin['email'])
@@ -300,7 +300,7 @@ class Update
                                        $from_build, $to_build));
 
                                $email = DI::emailer()
-                                          ->newSystemMail($l10n)
+                                          ->newSystemMail(DI::app(), $l10n)
                                           ->withMessage($l10n->t('[Friendica Notify] Database update'), $preamble)
                                           ->forUser($admin['uid'] ?? 0)
                                           ->withRecipient($admin['email'])
index cc6b96ae5853cd564b2cd1a2fcbd22b888f5bbb4..dd944137588069675a51d958b41dc073545025c8 100644 (file)
@@ -898,7 +898,7 @@ class User
                ));
 
                $email = DI::emailer()
-                          ->newSystemMail(DI::l10n())
+                          ->newSystemMail(DI::app(), DI::l10n())
                           ->withMessage(DI::l10n()->t('Registration at %s', $sitename), $body)
                           ->forUser($user['uid'] ?? 0)
                           ->withRecipient($user['email'])
@@ -966,7 +966,7 @@ class User
                ));
 
                $email = DI::emailer()
-                          ->newSystemMail((!empty($user['language'])) ? DI::l10n()->withLang($user['language']) : DI::l10n())
+                          ->newSystemMail(DI::app(), $l10n)
                           ->withMessage(DI::l10n()->t('Registration details for %s', $sitename), $preamble, $body)
                           ->forUser($user['uid'] ?? 0)
                           ->withRecipient($user['email'])
index 5ca50d11ac51de4e8b2623d9d99a2d4733fd5f99..d4e19da4795c986f5f71e32adf26bc675ca65e8a 100644 (file)
@@ -77,7 +77,7 @@ class Users extends BaseAdmin
                        $body = sprintf($body, DI::baseUrl()->get(), $user['nickname'], $result['password'], DI::config()->get('config', 'sitename'));
 
                        $email = DI::emailer()
-                                  ->newSystemMail((!empty($user['language'])) ? DI::l10n()->withLang($user['language']) : DI::l10n())
+                                  ->newSystemMail(DI::app(), (!empty($user['language'])) ? DI::l10n()->withLang($user['language']) : DI::l10n())
                                   ->withMessage(DI::l10n()->t('Registration details for %s', DI::config()->get('config', 'sitename')), $preamble, $body)
                                   ->forUser($user['uid'] ?? 0)
                                   ->withRecipient($user['email'])
index fab6c8862d4c0b0aa285042829487a3d72ae58bf..fe801bd562239941d2acbf9ee80048cd88b5c005 100644 (file)
@@ -138,11 +138,7 @@ abstract class MailBuilder
         */
        public function build(bool $raw = false)
        {
-               if (empty($this->recipientAddress)) {
-                       throw new InternalServerErrorException('Recipient address is missing.');
-               }
-
-               if ((empty($this->senderName) || empty($this->senderAddress)) &&
+               if ((empty($this->recipientAddress)) &&
                    !empty($this->recipientUid)) {
                        $user = User::getById($this->recipientUid, ['username', 'email']);
 
index 56ae620ec94686d1b97dff7b02de132cd35605a6..41d758ba0a3a173f9cf8d37e041609405ff1a8b5 100644 (file)
@@ -3,13 +3,13 @@
 namespace Friendica\Util\EMailer;
 
 use Exception;
+use Friendica\App;
 use Friendica\App\BaseURL;
 use Friendica\Content\Text\BBCode;
 use Friendica\Core\Config\IConfig;
 use Friendica\Core\L10n;
 use Friendica\Core\Renderer;
 use Friendica\Network\HTTPException\InternalServerErrorException;
-use Friendica\Util\Emailer;
 
 /**
  * Builder for system-wide emails without any dependency to concrete entities (like items, activities, ..)
@@ -26,7 +26,7 @@ class SystemMailBuilder extends MailBuilder
        /** @var string */
        protected $siteAdmin;
 
-       public function __construct(L10n $l10n, BaseURL $baseUrl, IConfig $config)
+       public function __construct(App $a, L10n $l10n, BaseURL $baseUrl, IConfig $config)
        {
                parent::__construct($l10n, $baseUrl, $config);
 
@@ -37,6 +37,8 @@ class SystemMailBuilder extends MailBuilder
                } else {
                        $this->siteAdmin = $l10n->t('%s Administrator', $siteName);
                }
+
+               $this->senderAddress = $a->getSenderEmailAddress();
        }
 
        /**
@@ -107,4 +109,15 @@ 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 ed4ea4d87c5606ee0c69297e1df1556384d17284..3f9a491d7677ff71e914d10cb0c701f3d4ec9526 100644 (file)
@@ -40,13 +40,14 @@ class Emailer
        /**
         * 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(L10n $l10n)
+       public function newSystemMail(App $a, L10n $l10n)
        {
-               return new SystemMailBuilder($l10n, $this->baseUrl, $this->config);
+               return new SystemMailBuilder($a, $l10n, $this->baseUrl, $this->config);
        }
 
        /**