Set Sitename / site email as sender for system emails

This commit is contained in:
nupplaPhil 2020-02-01 22:30:10 +01:00
parent 0966cdbb26
commit 9428466d1d
No known key found for this signature in database
GPG Key ID: D8365C3D36B77D90
8 changed files with 27 additions and 17 deletions

View File

@ -65,7 +65,7 @@ function lostpass_post(App $a)
Login Name: %3$s', $resetlink, DI::baseUrl(), $user['nickname'])); Login Name: %3$s', $resetlink, DI::baseUrl(), $user['nickname']));
$email = DI::emailer() $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) ->withMessage(DI::l10n()->t('Password reset requested at %s', $sitename), $preamble, $body)
->forUser($user['uid'] ?? 0) ->forUser($user['uid'] ?? 0)
->withRecipient($user['email']) ->withRecipient($user['email'])
@ -157,7 +157,7 @@ function lostpass_generate_password($user)
', DI::baseUrl(), $user['nickname'], $new_password)); ', DI::baseUrl(), $user['nickname'], $new_password));
$email = DI::emailer() $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) ->withMessage(DI::l10n()->t('Your password has been changed at %s', $sitename), $preamble, $body)
->forUser($user['uid'] ?? 0) ->forUser($user['uid'] ?? 0)
->withRecipient($user['email']) ->withRecipient($user['email'])

View File

@ -42,7 +42,7 @@ function removeme_post(App $a)
} }
$email = DI::emailer() $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'), ->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('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())) DI::l10n()->t('The user id is %d', local_user()))

View File

@ -264,7 +264,7 @@ class Update
$body = $l10n->t("The error message is\n[pre]%s[/pre]", $error_message); $body = $l10n->t("The error message is\n[pre]%s[/pre]", $error_message);
$email = DI::emailer() $email = DI::emailer()
->newSystemMail($l10n) ->newSystemMail(DI::app(), $l10n)
->withMessage($l10n->t('[Friendica Notify] Database update'), $preamble, $body) ->withMessage($l10n->t('[Friendica Notify] Database update'), $preamble, $body)
->forUser($admin['uid'] ?? 0) ->forUser($admin['uid'] ?? 0)
->withRecipient($admin['email']) ->withRecipient($admin['email'])
@ -300,7 +300,7 @@ class Update
$from_build, $to_build)); $from_build, $to_build));
$email = DI::emailer() $email = DI::emailer()
->newSystemMail($l10n) ->newSystemMail(DI::app(), $l10n)
->withMessage($l10n->t('[Friendica Notify] Database update'), $preamble) ->withMessage($l10n->t('[Friendica Notify] Database update'), $preamble)
->forUser($admin['uid'] ?? 0) ->forUser($admin['uid'] ?? 0)
->withRecipient($admin['email']) ->withRecipient($admin['email'])

View File

@ -898,7 +898,7 @@ class User
)); ));
$email = DI::emailer() $email = DI::emailer()
->newSystemMail(DI::l10n()) ->newSystemMail(DI::app(), DI::l10n())
->withMessage(DI::l10n()->t('Registration at %s', $sitename), $body) ->withMessage(DI::l10n()->t('Registration at %s', $sitename), $body)
->forUser($user['uid'] ?? 0) ->forUser($user['uid'] ?? 0)
->withRecipient($user['email']) ->withRecipient($user['email'])
@ -966,7 +966,7 @@ class User
)); ));
$email = DI::emailer() $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) ->withMessage(DI::l10n()->t('Registration details for %s', $sitename), $preamble, $body)
->forUser($user['uid'] ?? 0) ->forUser($user['uid'] ?? 0)
->withRecipient($user['email']) ->withRecipient($user['email'])

View File

@ -77,7 +77,7 @@ class Users extends BaseAdmin
$body = sprintf($body, DI::baseUrl()->get(), $user['nickname'], $result['password'], DI::config()->get('config', 'sitename')); $body = sprintf($body, DI::baseUrl()->get(), $user['nickname'], $result['password'], DI::config()->get('config', 'sitename'));
$email = DI::emailer() $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) ->withMessage(DI::l10n()->t('Registration details for %s', DI::config()->get('config', 'sitename')), $preamble, $body)
->forUser($user['uid'] ?? 0) ->forUser($user['uid'] ?? 0)
->withRecipient($user['email']) ->withRecipient($user['email'])

View File

@ -138,11 +138,7 @@ abstract class MailBuilder
*/ */
public function build(bool $raw = false) public function build(bool $raw = false)
{ {
if (empty($this->recipientAddress)) { if ((empty($this->recipientAddress)) &&
throw new InternalServerErrorException('Recipient address is missing.');
}
if ((empty($this->senderName) || empty($this->senderAddress)) &&
!empty($this->recipientUid)) { !empty($this->recipientUid)) {
$user = User::getById($this->recipientUid, ['username', 'email']); $user = User::getById($this->recipientUid, ['username', 'email']);

View File

@ -3,13 +3,13 @@
namespace Friendica\Util\EMailer; namespace Friendica\Util\EMailer;
use Exception; use Exception;
use Friendica\App;
use Friendica\App\BaseURL; use Friendica\App\BaseURL;
use Friendica\Content\Text\BBCode; use Friendica\Content\Text\BBCode;
use Friendica\Core\Config\IConfig; use Friendica\Core\Config\IConfig;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Util\Emailer;
/** /**
* Builder for system-wide emails without any dependency to concrete entities (like items, activities, ..) * Builder for system-wide emails without any dependency to concrete entities (like items, activities, ..)
@ -26,7 +26,7 @@ class SystemMailBuilder extends MailBuilder
/** @var string */ /** @var string */
protected $siteAdmin; 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); parent::__construct($l10n, $baseUrl, $config);
@ -37,6 +37,8 @@ class SystemMailBuilder extends MailBuilder
} else { } else {
$this->siteAdmin = $l10n->t('%s Administrator', $siteName); $this->siteAdmin = $l10n->t('%s Administrator', $siteName);
} }
$this->senderAddress = $a->getSenderEmailAddress();
} }
/** /**
@ -107,4 +109,15 @@ class SystemMailBuilder extends MailBuilder
'$textversion' => $textVersion, '$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);
}
} }

View File

@ -40,13 +40,14 @@ class Emailer
/** /**
* Creates a new system email * Creates a new system email
* *
* @param App $a The Friendica app
* @param L10n $l10n The chosen language for the new email * @param L10n $l10n The chosen language for the new email
* *
* @return SystemMailBuilder * @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);
} }
/** /**