mirror of
https://github.com/humhub/humhub.git
synced 2025-01-29 20:38:26 +01:00
Fix: Ensure e-mails would always have a sender address set
This commit is contained in:
parent
82450b0530
commit
7b19fbeb54
@ -3,9 +3,10 @@ HumHub Changelog
|
||||
|
||||
1.16.0 (Unreleased)
|
||||
-------------------
|
||||
- Enh #6451: Introduce Archiveable, Deletable, Editable, Readable, & Viewable Interfaces
|
||||
- Enh #6512: Show error messages when DB connection configuration is invalid
|
||||
- Fix #6519: Ensure e-mails would always have a sender address set
|
||||
- Fix #6516: Humhub test case would fail on skipped tests
|
||||
- Enh #6512: Show error messages when DB connection configuration is invalid
|
||||
- Enh #6451: Introduce Archiveable, Deletable, Editable, Readable, & Viewable Interfaces
|
||||
|
||||
1.15.0-beta.2 (Unreleased)
|
||||
--------------------------
|
||||
|
@ -61,4 +61,9 @@ trait ApplicationTrait
|
||||
{
|
||||
$this->_homeUrl = $value;
|
||||
}
|
||||
|
||||
public function getMailer(): MailerInterface
|
||||
{
|
||||
return parent::getMailer();
|
||||
}
|
||||
}
|
||||
|
@ -8,8 +8,10 @@
|
||||
|
||||
namespace humhub\components\mail;
|
||||
|
||||
use humhub\interfaces\MailerInterface;
|
||||
use Symfony\Component\Mime\Crypto\SMimeSigner;
|
||||
use Yii;
|
||||
use yii\mail\MessageInterface;
|
||||
|
||||
/**
|
||||
* Mailer implements a mailer based on SymfonyMailer.
|
||||
@ -18,7 +20,7 @@ use Yii;
|
||||
* @since 1.2
|
||||
* @author Luke
|
||||
*/
|
||||
class Mailer extends \yii\symfonymailer\Mailer
|
||||
class Mailer extends \yii\symfonymailer\Mailer implements MailerInterface
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
@ -68,13 +70,7 @@ class Mailer extends \yii\symfonymailer\Mailer
|
||||
{
|
||||
$message = parent::compose($view, $params);
|
||||
|
||||
// Set HumHub default from values
|
||||
if (empty($message->getFrom())) {
|
||||
$message->setFrom([Yii::$app->settings->get('mailer.systemEmailAddress') => Yii::$app->settings->get('mailer.systemEmailName')]);
|
||||
if ($replyTo = Yii::$app->settings->get('mailer.systemEmailReplyTo')) {
|
||||
$message->setReplyTo($replyTo);
|
||||
}
|
||||
}
|
||||
self::ensureHumHubDefaultFromValues($message);
|
||||
|
||||
if ($this->signingCertificatePath !== null && $this->signingPrivateKeyPath !== null) {
|
||||
if ($this->signer === null) {
|
||||
@ -92,6 +88,25 @@ class Mailer extends \yii\symfonymailer\Mailer
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MessageInterface $message
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function ensureHumHubDefaultFromValues(MessageInterface $message): MessageInterface
|
||||
{
|
||||
// Set HumHub default from values
|
||||
if ($message->getFrom()) {
|
||||
return $message;
|
||||
}
|
||||
|
||||
$message->setFrom([Yii::$app->settings->get('mailer.systemEmailAddress') => Yii::$app->settings->get('mailer.systemEmailName')]);
|
||||
if ($replyTo = Yii::$app->settings->get('mailer.systemEmailReplyTo')) {
|
||||
$message->setReplyTo($replyTo);
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
|
@ -19,4 +19,6 @@ interface ApplicationInterface
|
||||
* @event ActionEvent an event raised on init of application.
|
||||
*/
|
||||
public const EVENT_ON_INIT = 'onInit';
|
||||
|
||||
public function getMailer(): MailerInterface;
|
||||
}
|
||||
|
13
protected/humhub/interfaces/MailerInterface.php
Normal file
13
protected/humhub/interfaces/MailerInterface.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @link https://www.humhub.org/
|
||||
* @copyright Copyright (c) 2023 HumHub GmbH & Co. KG
|
||||
* @license https://www.humhub.com/licences
|
||||
*/
|
||||
|
||||
namespace humhub\interfaces;
|
||||
|
||||
interface MailerInterface extends \yii\mail\MailerInterface
|
||||
{
|
||||
}
|
@ -68,7 +68,6 @@ class MailTarget extends BaseTarget
|
||||
], $notification->getViewParams());
|
||||
|
||||
$mail = Yii::$app->mailer->compose($this->view, $viewParams)
|
||||
->setFrom([Yii::$app->settings->get('mailer.systemEmailAddress') => Yii::$app->settings->get('mailer.systemEmailName')])
|
||||
->setTo($recipient->email)
|
||||
->setSubject(str_replace("\n", " ", trim($notification->getMailSubject())));
|
||||
if ($replyTo = Yii::$app->settings->get('mailer.systemEmailReplyTo')) {
|
||||
|
25
protected/humhub/tests/codeception/_support/TestMailer.php
Normal file
25
protected/humhub/tests/codeception/_support/TestMailer.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @link https://www.humhub.org/
|
||||
* @copyright Copyright (c) 2023 HumHub GmbH & Co. KG
|
||||
* @license https://www.humhub.com/licences
|
||||
*/
|
||||
|
||||
namespace tests\codeception\_support;
|
||||
|
||||
use humhub\components\mail\Mailer;
|
||||
use humhub\interfaces\MailerInterface;
|
||||
|
||||
/**
|
||||
* @since 1.15
|
||||
*/
|
||||
class TestMailer extends \Codeception\Lib\Connector\Yii2\TestMailer implements MailerInterface
|
||||
{
|
||||
public function compose($view = null, array $params = [])
|
||||
{
|
||||
$message = parent::compose($view, $params);
|
||||
|
||||
return Mailer::ensureHumHubDefaultFromValues($message);
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
/**
|
||||
* Application configuration shared by all test types
|
||||
*/
|
||||
|
||||
$default = [
|
||||
'name' => 'HumHub Test',
|
||||
'language' => 'en-US',
|
||||
@ -32,6 +33,13 @@ $default = [
|
||||
'scriptUrl' => '/index-test.php',
|
||||
],
|
||||
],
|
||||
'container' => [
|
||||
'definitions' => [
|
||||
\Codeception\Lib\Connector\Yii2\TestMailer::class => [
|
||||
'class' => \tests\codeception\_support\TestMailer::class,
|
||||
]
|
||||
]
|
||||
],
|
||||
'modules' => [
|
||||
'user' => [
|
||||
'passwordStrength' => [
|
||||
|
Loading…
x
Reference in New Issue
Block a user