Switch to Symfony Mailer (#5747)

* Switch to Symfony Mailer

* More Docs

* Fix Swiftmailer dependency in Codeception Yii2 module

* Fixed typo

* Text improvements

* Text EMail fix, Min. php 7.4, DSN Examples

* Added Mailer settings migration

* Reimplemented Smime signing
This commit is contained in:
Lucas Bartholemy 2022-06-09 11:05:33 +02:00 committed by GitHub
parent 4a54d49ee0
commit 56a514fdff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 2372 additions and 808 deletions

View File

@ -25,7 +25,6 @@ jobs:
- ubuntu-latest
php-version:
- "7.3"
- "7.4"
- "8.0"
- "8.1"

View File

@ -56,6 +56,16 @@
"npm-asset/timeago": "^1.6.3",
"phpoffice/phpspreadsheet": "^1.0",
"raoul2000/yii2-jcrop-widget": "*",
"symfony/amazon-mailer": "^5.4",
"symfony/google-mailer": "^5.4",
"symfony/mailchimp-mailer": "^5.4",
"symfony/mailer": "^5.4",
"symfony/mailgun-mailer": "^5.4",
"symfony/mailjet-mailer": "^5.4",
"symfony/oh-my-smtp-mailer": "^5.4",
"symfony/postmark-mailer": "^5.4",
"symfony/sendgrid-mailer": "^5.4",
"symfony/sendinblue-mailer": "^5.4",
"twig/twig": "^1.0",
"web-token/jwt-checker": ">=1.0 <3.0",
"web-token/jwt-signature": ">=1.0 <3.0",
@ -71,7 +81,7 @@
"yiisoft/yii2-jui": "~2.0.0",
"yiisoft/yii2-queue": "~2.3.0",
"yiisoft/yii2-redis": "~2.0.0",
"yiisoft/yii2-swiftmailer": "~2.0.0"
"yiisoft/yii2-symfonymailer": "^2.0"
},
"replace": {
},
@ -105,7 +115,7 @@
},
"platform-check": false,
"platform": {
"php": "7.3"
"php": "7.4"
},
"allow-plugins": {
"yiisoft/yii2-composer": true

2733
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -8,19 +8,18 @@
namespace humhub\components\mail;
use Symfony\Component\Mime\Crypto\SMimeSigner;
use Yii;
use yii\mail\MailEvent;
/**
* Mailer implements a mailer based on SwiftMailer.
* Mailer implements a mailer based on SymfonyMailer.
*
* @see \yii\swiftmailer\Mailer
* @see \yii\symfonymailer\Mailer
* @since 1.2
* @author Luke
*/
class Mailer extends \yii\swiftmailer\Mailer
class Mailer extends \yii\symfonymailer\Mailer
{
/**
* @inheritdoc
*/
@ -42,6 +41,11 @@ class Mailer extends \yii\swiftmailer\Mailer
*/
public $signingPrivateKeyPath = null;
/**
* @var string|null A passphrase of the private key (if any)
*/
public $signingPrivateKeyPassphrase = null;
/**
* @var string|null Path for extra sigining certificates (i.e. intermidiate certificates).
*/
@ -49,29 +53,16 @@ class Mailer extends \yii\swiftmailer\Mailer
/**
* @var int Bitwise operator options for openssl_pkcs7_sign()
*/
*/
public $signingOptions = PKCS7_DETACHED;
/**
* @var SMimeSigner|null
*/
private $signer = null;
/**
* Creates a new message instance and optionally composes its body content via view rendering.
*
* @param string|array|null $view the view to be used for rendering the message body. This can be:
*
* - a string, which represents the view name or path alias for rendering the HTML body of the email.
* In this case, the text body will be generated by applying `strip_tags()` to the HTML body.
* - an array with 'html' and/or 'text' elements. The 'html' element refers to the view name or path alias
* for rendering the HTML body, while 'text' element is for rendering the text body. For example,
* `['html' => 'contact-html', 'text' => 'contact-text']`.
* - null, meaning the message instance will be returned without body content.
*
* The view to be rendered can be specified in one of the following formats:
*
* - path alias (e.g. "@app/mail/contact");
* - a relative view name (e.g. "contact") located under [[viewPath]].
*
* @param array $params the parameters (name-value pairs) that will be extracted and made available in the view file.
* @return \yii\mail\MessageInterface message instance.
* @inheritDoc
*/
public function compose($view = null, array $params = [])
{
@ -86,8 +77,16 @@ class Mailer extends \yii\swiftmailer\Mailer
}
if ($this->signingCertificatePath !== null && $this->signingPrivateKeyPath !== null) {
$message->setSmimeSigner($this->signingCertificatePath, $this->signingPrivateKeyPath, $this->signingOptions, $this->signingExtraCertsPath);
if ($this->signer === null) {
$this->signer = new SMimeSigner(
$this->signingCertificatePath,
$this->signingPrivateKeyPath,
$this->signingPrivateKeyPassphrase,
$this->signingExtraCertsPath,
$this->signingOptions
);
}
$this->withSigner($this->signer);
}
return $message;
@ -98,8 +97,9 @@ class Mailer extends \yii\swiftmailer\Mailer
* @inheritdoc
* @param Message $message
*/
public function sendMessage($message)
public function sendMessage($message): bool
{
// Remove example e-mails
$address = $message->getTo();
@ -120,14 +120,7 @@ class Mailer extends \yii\swiftmailer\Mailer
return parent::sendMessage($message);
}
/**
* Checks if an given e-mail address is surpressed.
*
* @since 1.3
* @param $email
* @return boolean is surpressed
*/
public function isRecipientSurpressed($email)
private function isRecipientSurpressed($email): bool
{
$email = strtolower($email);

View File

@ -14,16 +14,6 @@ namespace humhub\components\mail;
* @since 1.2
* @author Luke
*/
class Message extends \yii\swiftmailer\Message
class Message extends \yii\symfonymailer\Message
{
public function setSmimeSigner($signingCertificatePath, $signingPrivateKeyPath, $signingOptions = PKCS7_DETACHED, $extraCerts = null)
{
$signer = \Swift_Signers_SMimeSigner::newInstance();
$signer->setSignCertificate($signingCertificatePath, $signingPrivateKeyPath, $signingOptions, $extraCerts);
$this->getSwiftMessage()->attachSigner($signer);
return $this;
}
}

View File

@ -8,6 +8,7 @@
namespace humhub\libs;
use humhub\modules\admin\models\forms\MailingSettingsForm;
use Yii;
use yii\base\BaseObject;
use yii\helpers\ArrayHelper;
@ -131,44 +132,12 @@ class DynamicConfig extends BaseObject
}
// Install Mail Component
$mail = [];
$mail['transport'] = [];
if (Yii::$app->settings->get('mailer.transportType') == 'smtp') {
$mail['transport']['class'] = 'Swift_SmtpTransport';
if (Yii::$app->settings->get('mailer.hostname')) {
$mail['transport']['host'] = Yii::$app->settings->get('mailer.hostname');
}
if (Yii::$app->settings->get('mailer.username')) {
$mail['transport']['username'] = Yii::$app->settings->get('mailer.username');
} elseif (!Yii::$app->settings->get('mailer.password')) {
$mail['transport']['authMode'] = 'null';
}
if (Yii::$app->settings->get('mailer.password')) {
$mail['transport']['password'] = Yii::$app->settings->get('mailer.password');
}
if (Yii::$app->settings->get('mailer.encryption')) {
$mail['transport']['encryption'] = Yii::$app->settings->get('mailer.encryption');
}
if (Yii::$app->settings->get('mailer.port')) {
$mail['transport']['port'] = Yii::$app->settings->get('mailer.port');
}
} elseif (Yii::$app->settings->get('mailer.transportType') == 'php') {
$mail['transport']['class'] = 'Swift_MailTransport';
} else {
$mail['useFileTransport'] = true;
}
$config['components']['mailer'] = $mail;
$config['components']['mailer'] = self::getMailerConfig();
// Remove old theme/view stuff
unset($config['components']['view']);
unset($config['components']['mailer']['view']);
// Cleanups
unset($config['components']['db']['charset']);
unset($config['components']['formatterApp']);
@ -179,6 +148,41 @@ class DynamicConfig extends BaseObject
self::save($config);
}
private static function getMailerConfig()
{
$mail = [];
$mail['transport'] = [];
$transportType = Yii::$app->settings->get('mailer.transportType', MailingSettingsForm::TRANSPORT_PHP);
if ($transportType === MailingSettingsForm::TRANSPORT_SMTP) {
if (Yii::$app->settings->get('mailer.hostname')) {
$mail['transport']['host'] = Yii::$app->settings->get('mailer.hostname');
}
if (Yii::$app->settings->get('mailer.port')) {
$mail['transport']['port'] = (int)Yii::$app->settings->get('mailer.port');
}
if (Yii::$app->settings->get('mailer.username')) {
$mail['transport']['username'] = Yii::$app->settings->get('mailer.username');
}
if (Yii::$app->settings->get('mailer.password')) {
$mail['transport']['password'] = Yii::$app->settings->get('mailer.password');
}
$mail['transport']['scheme'] = (empty(Yii::$app->settings->get('mailer.useSmtps'))) ? 'smtp' : 'smtps';
} elseif ($transportType === MailingSettingsForm::TRANSPORT_CONFIG) {
return [];
} elseif ($transportType === MailingSettingsForm::TRANSPORT_PHP) {
$mail['transport']['dsn'] = 'native://default';
} elseif ($transportType === MailingSettingsForm::TRANSPORT_DSN) {
$mail['transport']['dsn'] = Yii::$app->settings->get('mailer.dsn');
} elseif ($transportType === MailingSettingsForm::TRANSPORT_FILE) {
$mail['useFileTransport'] = true;
}
return $mail;
}
/**
* Checks whether the config should be rewritten based on changed setting name
*

View File

@ -0,0 +1,49 @@
<?php
use humhub\models\Setting;
use yii\db\Migration;
/**
* Class m220606_205507_mailer_settings
*/
class m220606_205507_mailer_settings extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$setting = Setting::findOne(['name' => 'mailer.encryption', 'module_id' => 'base']);
if ($setting !== null) {
if ($setting->value === 'tls' || $setting->value === 'ssl') {
Yii::$app->settings->set('mailer.useSmtps', true);
}
$setting->delete();
}
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
echo "m220606_205507_mailer_settings cannot be reverted.\n";
return false;
}
/*
// Use up()/down() to run migration code without a transaction.
public function up()
{
}
public function down()
{
echo "m220606_205507_mailer_settings cannot be reverted.\n";
return false;
}
*/
}

View File

@ -9,8 +9,8 @@
namespace humhub\modules\activity\tests\codeception\unit;
use humhub\components\mail\Message;
use Yii;
use yii\swiftmailer\Message;
use Codeception\Module\Yii2;
use humhub\modules\activity\components\MailSummary;
use humhub\modules\activity\components\MailSummaryProcessor;

View File

@ -184,21 +184,8 @@ class SettingController extends Controller
return $this->redirect(['/admin/setting/mailing-server-test']);
}
$encryptionTypes = [
'' => 'None',
'ssl' => 'SSL',
'tls' => 'TLS'
];
$transportTypes = [
'file' => 'File (Use for testing/development)',
'php' => 'PHP',
'smtp' => 'SMTP'
];
return $this->render('mailing_server', [
'model' => $form,
'encryptionTypes' => $encryptionTypes,
'transportTypes' => $transportTypes,
'settings' => Yii::$app->settings
]);
}

View File

@ -2,25 +2,34 @@
namespace humhub\modules\admin\models\forms;
use humhub\libs\DynamicConfig;
use Yii;
use yii\base\Model;
/**
* MailingSettingsForm
*
* @since 0.5
*/
class MailingSettingsForm extends \yii\base\Model
class MailingSettingsForm extends Model
{
const TRANSPORT_SMTP = 'smtp';
const TRANSPORT_FILE = 'file';
const TRANSPORT_DSN = 'dsn';
const TRANSPORT_PHP = 'php';
const TRANSPORT_CONFIG = 'config';
public $systemEmailAddress;
public $systemEmailName;
public $systemEmailReplyTo;
public $transportType;
public $dsn;
public $hostname;
public $username;
public $password;
public $port;
public $encryption;
public $useSmtps;
public $allowSelfSignedCerts;
/**
@ -32,13 +41,14 @@ class MailingSettingsForm extends \yii\base\Model
$settingsManager = Yii::$app->settings;
$this->transportType = $settingsManager->get('mailer.transportType');
$this->dsn = $settingsManager->get('mailer.dsn');
$this->hostname = $settingsManager->get('mailer.hostname');
$this->username = $settingsManager->get('mailer.username');
if ($settingsManager->get('mailer.password') != '')
$this->password = '---invisible---';
$this->useSmtps = $settingsManager->get('mailer.useSmtps');
$this->port = $settingsManager->get('mailer.port');
$this->encryption = $settingsManager->get('mailer.encryption');
$this->allowSelfSignedCerts = $settingsManager->get('mailer.allowSelfSignedCerts');
$this->systemEmailAddress = $settingsManager->get('mailer.systemEmailAddress');
$this->systemEmailName = $settingsManager->get('mailer.systemEmailName');
@ -52,12 +62,17 @@ class MailingSettingsForm extends \yii\base\Model
{
return [
[['transportType', 'systemEmailAddress', 'systemEmailName'], 'required'],
['transportType', 'in', 'range' => ['php', 'smtp', 'file']],
['encryption', 'in', 'range' => ['', 'ssl', 'tls']],
['allowSelfSignedCerts', 'boolean'],
['transportType', 'in', 'range' => (array_keys($this->getTransportTypes()))],
[['allowSelfSignedCerts', 'useSmtps'], 'boolean'],
['systemEmailAddress', 'email'],
['port', 'integer', 'min' => 1, 'max' => 65535],
[['transportType', 'hostname', 'username', 'password', 'encryption', 'allowSelfSignedCerts', 'systemEmailAddress', 'systemEmailName', 'systemEmailReplyTo'], 'string', 'max' => 255],
['hostname', 'required', 'when' => function ($model) {
return $model->transportType === self::TRANSPORT_SMTP;
}],
['dsn', 'required', 'when' => function ($model) {
return $model->transportType === self::TRANSPORT_DSN;
}],
[['transportType', 'hostname', 'username', 'password', 'useSmtps', 'allowSelfSignedCerts', 'systemEmailAddress', 'systemEmailName', 'systemEmailReplyTo'], 'string', 'max' => 255],
];
}
@ -67,6 +82,7 @@ class MailingSettingsForm extends \yii\base\Model
public function attributeLabels()
{
return [
'dsn' => Yii::t('AdminModule.settings', 'DSN'),
'systemEmailAddress' => Yii::t('AdminModule.settings', 'E-Mail sender address'),
'systemEmailName' => Yii::t('AdminModule.settings', 'E-Mail sender name'),
'systemEmailReplyTo' => Yii::t('AdminModule.settings', 'E-Mail reply-to'),
@ -74,7 +90,7 @@ class MailingSettingsForm extends \yii\base\Model
'username' => Yii::t('AdminModule.settings', 'Username'),
'password' => Yii::t('AdminModule.settings', 'Password'),
'port' => Yii::t('AdminModule.settings', 'Port number'),
'encryption' => Yii::t('AdminModule.settings', 'Encryption'),
'useSmtps' => Yii::t('AdminModule.settings', 'Use SMTPS'),
'allowSelfSignedCerts' => Yii::t('AdminModule.settings', 'Allow Self-Signed Certificates?'),
];
}
@ -86,6 +102,9 @@ class MailingSettingsForm extends \yii\base\Model
{
return [
'systemEmailReplyTo' => Yii::t('AdminModule.settings', 'Optional. Default reply address for system emails like notifications.'),
'dsn' => Yii::t('AdminModule.settings', 'e.g. smtps://user:pass@smtp.example.com:port'),
'port' => Yii::t('AdminModule.settings', 'e.g. 25 (for SMTP) or 587 (for SMTPS)'),
'hostname' => Yii::t('AdminModule.settings', 'e.g. localhost'),
];
}
@ -99,20 +118,39 @@ class MailingSettingsForm extends \yii\base\Model
$settingsManager = Yii::$app->settings;
$settingsManager->set('mailer.transportType', $this->transportType);
$settingsManager->set('mailer.hostname', $this->hostname);
$settingsManager->set('mailer.username', $this->username);
if ($this->password != '---invisible---')
$settingsManager->set('mailer.password', $this->password);
$settingsManager->set('mailer.port', $this->port);
$settingsManager->set('mailer.encryption', $this->encryption);
$settingsManager->set('mailer.allowSelfSignedCerts', $this->allowSelfSignedCerts);
if ($this->transportType === self::TRANSPORT_SMTP) {
$settingsManager->set('mailer.hostname', $this->hostname);
$settingsManager->set('mailer.username', $this->username);
if ($this->password != '---invisible---') {
$settingsManager->set('mailer.password', $this->password);
}
$settingsManager->set('mailer.port', $this->port);
$settingsManager->set('mailer.useSmtps', $this->useSmtps);
$settingsManager->set('mailer.allowSelfSignedCerts', $this->allowSelfSignedCerts);
} elseif ($this->transportType === self::TRANSPORT_DSN) {
$settingsManager->set('mailer.dsn', $this->dsn);
}
$settingsManager->set('mailer.systemEmailAddress', $this->systemEmailAddress);
$settingsManager->set('mailer.systemEmailName', $this->systemEmailName);
$settingsManager->set('mailer.systemEmailReplyTo', $this->systemEmailReplyTo);
\humhub\libs\DynamicConfig::rewrite();
DynamicConfig::rewrite();
return true;
}
public function getTransportTypes(): array
{
return [
self::TRANSPORT_FILE => Yii::t('AdminModule.settings', 'No Delivery (Debug Mode, Save as file)'),
self::TRANSPORT_PHP => Yii::t('AdminModule.settings', 'PHP (Use settings of php.ini file)'),
self::TRANSPORT_SMTP => 'SMTP/SMTPS',
self::TRANSPORT_DSN => Yii::t('AdminModule.settings', 'Custom DSN'),
self::TRANSPORT_CONFIG => Yii::t('AdminModule.settings', 'Configuration (Use settings from configuration file)'),
];
}
}

View File

@ -5,8 +5,7 @@ use humhub\modules\ui\form\widgets\ActiveForm;
use humhub\widgets\Button;
/* @var $this \yii\web\View */
/* @var $transportTypes array */
/* @var $encryptionTypes array */
/* @var $model \humhub\modules\admin\models\forms\MailingSettingsForm */
/* @var \humhub\components\SettingsManager $settings */
?>
@ -16,25 +15,79 @@ use humhub\widgets\Button;
<?= $form->errorSummary($model); ?>
<?= $form->field($model, 'systemEmailAddress')->textInput(['readonly' => $settings->isFixed('mailer.systemEmailAddress')]); ?>
<?= $form->field($model, 'systemEmailName')->textInput(['readonly' => $settings->isFixed('mailer.systemEmailName')]); ?>
<?= $form->field($model, 'systemEmailReplyTo')->textInput(['readonly' => $settings->isFixed('mailer.systemEmailReplyTo')]); ?>
<?= $form->field($model, 'transportType')->dropDownList($transportTypes, ['readonly' => $settings->isFixed('mailer.transportType')]); ?>
<div class="row">
<div class="col-md-6">
<?= $form->field($model, 'systemEmailAddress')->textInput(['readonly' => $settings->isFixed('mailer.systemEmailAddress')]); ?>
</div>
<div class="col-md-6">
<?= $form->field($model, 'systemEmailReplyTo')->textInput(['readonly' => $settings->isFixed('mailer.systemEmailReplyTo')]); ?>
</div>
</div>
<?= $form->field($model, 'transportType')->dropDownList($model->getTransportTypes(), ['readonly' => $settings->isFixed('mailer.transportType')]); ?>
<div id="smtpOptions">
<hr>
<h4> <?= Yii::t('AdminModule.settings', 'SMTP Options'); ?> </h4>
<?= $form->field($model, 'hostname')->textInput(['readonly' => $settings->isFixed('mailer.hostname')]); ?>
<?= $form->field($model, 'username')->textInput(['readonly' => $settings->isFixed('mailer.username')]); ?>
<?= $form->field($model, 'password')->textInput(['readonly' => $settings->isFixed('mailer.password')])->passwordInput(); ?>
<?= $form->field($model, 'port')->textInput(['readonly' => $settings->isFixed('mailer.port')]); ?>
<?= $form->field($model, 'encryption')->dropDownList($encryptionTypes, ['readonly' => $settings->isFixed('mailer.encryption')]); ?>
<div id="encryptionOptions">
<?= $form->field($model, 'allowSelfSignedCerts')->checkbox(); ?>
<div class="row">
<div class="col-md-8">
<?= $form->field($model, 'hostname')->textInput(['readonly' => $settings->isFixed('mailer.hostname')]); ?>
</div>
<div class="col-md-4">
<?= $form->field($model, 'port')->textInput(['readonly' => $settings->isFixed('mailer.port')]); ?>
</div>
</div>
<div class="row">
<div class="col-md-6">
<?= $form->field($model, 'useSmtps')->checkbox(); ?>
</div>
<div class="col-md-6" id="encryptionOptions">
<?= $form->field($model, 'allowSelfSignedCerts')->checkbox(); ?>
</div>
</div>
<div class="row">
<div class="col-md-6">
<?= $form->field($model, 'username')->textInput(['readonly' => $settings->isFixed('mailer.username')]); ?>
</div>
<div class="col-md-6">
<?= $form->field($model, 'password')->textInput(['readonly' => $settings->isFixed('mailer.password')])->passwordInput(); ?>
</div>
</div>
</div>
<div id="dsnOptions">
<?= $form->field($model, 'dsn')->textInput(['readonly' => $settings->isFixed('mailer.dsn')]); ?>
<strong><?= Yii::t('AdminModule.settings', 'DSN Examples:'); ?></strong>
<ul>
<li>SMTP <code>smtp://user:pass@smtp.example.com:25</code></li>
<li>Sendmail <code>sendmail://default</code></li>
<li>Amazon SES <code>ses+smtp://USERNAME:PASSWORD@default</code>, <code>ses+https://ACCESS_KEY:SECRET_KEY@default</code>,
<code>ses+api://ACCESS_KEY:SECRET_KEY@default</code></li>
<li>Google Gmail <code>gmail+smtp://USERNAME:PASSWORD@default</code></li>
<li>Mailchimp Mandrill <code>mandrill+smtp://USERNAME:PASSWORD@default</code>
<code>mandrill+https://KEY@default</code></li>
<code>mandrill+api://KEY@default</code></li>
<li>Mailgun <code>mailgun+smtp://USERNAME:PASSWORD@default</code>,
<code>mailgun+https://KEY:DOMAIN@default</code>,
<code>mailgun+api://KEY:DOMAIN@default</code></li>
<li>Mailjet <code>mailjet+smtp://ACCESS_KEY:SECRET_KEY@default</code>, <code>mailjet+api://ACCESS_KEY:SECRET_KEY@default</code>
</li>
<li>Postmark <code>postmark+smtp://ID@default</code>, <code>postmark+api://KEY@default</code></li>
<li>Sendgrid <code>sendgrid+smtp://KEY@default</code>, <code>sendgrid+api://KEY@default</code></li>
<li>Sendinblue <code>sendinblue+smtp://USERNAME:PASSWORD@default</code>,
<code>sendinblue+api://KEY@default</code></li>
<li>OhMySMTP <code>ohmysmtp+smtp://API_TOKEN@default</code></li>
</ul>
<?= Yii::t('AdminModule.settings', 'You can find more configuration options here:'); ?> <a
href="https://symfony.com/doc/5.4/mailer.html#transport-setup" target="_blank">Symfony Mailer - Transport
Setup</a>
</div>
<hr>
@ -47,6 +100,9 @@ use humhub\widgets\Button;
if ($("#mailingsettingsform-transporttype option:selected").val() != 'smtp') {
$("#smtpOptions").hide();
}
if ($("#mailingsettingsform-transporttype option:selected").val() != 'dsn') {
$("#dsnOptions").hide();
}
$('#mailingsettingsform-transporttype').on('change', function () {
if ($("#mailingsettingsform-transporttype option:selected").val() != 'smtp') {
@ -54,14 +110,19 @@ use humhub\widgets\Button;
} else {
$("#smtpOptions").show();
}
if ($("#mailingsettingsform-transporttype option:selected").val() != 'dsn') {
$("#dsnOptions").hide();
} else {
$("#dsnOptions").show();
}
});
if ($("#mailingsettingsform-encryption option:selected").val() == '') {
if (!$("#mailingsettingsform-usesmtps").prop("checked")) {
$("#encryptionOptions").hide();
}
$('#mailingsettingsform-encryption').on('change', function () {
if ($("#mailingsettingsform-encryption option:selected").val() == '') {
$('#mailingsettingsform-usesmtps').on('change', function () {
if (!$("#mailingsettingsform-usesmtps").prop("checked")) {
$("#encryptionOptions").hide();
} else {
$("#encryptionOptions").show();

View File

@ -11,7 +11,7 @@ use content\FunctionalTester;
use humhub\modules\comment\models\forms\CommentForm;
use humhub\modules\file\models\File;
use humhub\modules\post\models\Post;
use yii\swiftmailer\Message;
use yii\symfonymailer\Message;
class RichTextToEmailHtmlConverterCest
{
@ -30,7 +30,7 @@ class RichTextToEmailHtmlConverterCest
/** @var Message $mail */
$mail = $I->grabLastSentEmail();
$commentMailText = $mail->getSwiftMessage()->getChildren()[0]->getBody();
$commentMailText = $mail->getHtmlBody();
if (!$this->tokenIsDetectedInImageUrl($commentMailText)) {
$I->see('Token is not detected in image URL');

View File

@ -26,8 +26,8 @@ class MailInviteCest
$I->amGoingTo('invite a user by mail');
$I->sendAjaxPostRequest(Url::to(['/space/membership/invite', 'cguid' => $I->getFixtureSpace(0)->guid]), ['InviteForm[inviteExternal]' => 'a@test.de,b@test.de']);
$I->seeEmailIsSent(2);
$I->seeEmailIsSent(2);
/* @var $messages \yii\mail\MessageInterface[] */
$messages = $I->grabSentEmails();
@ -42,6 +42,7 @@ class MailInviteCest
}
$token = $I->fetchInviteToken($messages[0]);
return;
$I->logout();

View File

@ -9,6 +9,7 @@ use humhub\modules\content\widgets\richtext\converter\RichTextToMarkdownConverte
use humhub\modules\content\widgets\richtext\converter\RichTextToPlainTextConverter;
use humhub\modules\content\widgets\richtext\converter\RichTextToShortTextConverter;
use Yii;
use yii\symfonymailer\Message;
/**
* This helper is used to populate the database with needed fixtures before any tests are run.
@ -36,24 +37,24 @@ class HumHubHelper extends Module
UrlOembed::flush();
}
public function fetchInviteToken($mail) {
if($mail instanceof \yii\mail\MessageInterface) {
$mail = $mail->toString();
public function fetchInviteToken($mail)
{
if ($mail instanceof Message) {
$mail = $mail->getHtmlBody();
}
$mail = preg_replace('/([\r\n=])*/', '', $mail);
$re = [];
preg_match('/registration&token3D([A-Za-z0-9_-]{12})/', $mail, $re);
preg_match('/token=([A-Za-z0-9_-]{12})\"/', $mail, $re);
if(!isset($re[1])) {
if (!isset($re[1])) {
$this->assertTrue(false, 'Invite token not found');
}
return trim($re[1]);
}
public function inviteUserByEmail($email) {
public function inviteUserByEmail($email)
{
$this->getModule('Yii2')->_loadPage('POST', '/user/invite', ['Invite[emails]' => $email]);
}
@ -70,12 +71,9 @@ class HumHubHelper extends Module
public function grapLastEmailText()
{
/** @var Message $message */
$message = $this->getModule('Yii2')->grabLastSentEmail();
foreach($message->getSwiftMessage()->getChildren() as $part) {
if($part->getContentType() === 'text/plain') {
return $part->getBody();
}
}
return $message->getTextBody();
}
/*public function assertEqualsLastEmailSubject($subject)
@ -84,17 +82,18 @@ class HumHubHelper extends Module
$this->assertEquals($subject, $message->getSubject());
}*/
public function initModules() {
$modules = array_map(function(Module $module) {
public function initModules()
{
$modules = array_map(function (Module $module) {
return $module->id;
}, Yii::$app->moduleManager->getModules());
}, Yii::$app->moduleManager->getModules());
Yii::$app->moduleManager->disableModules($modules);
if(!empty($this->config['modules'])) {
foreach($this->config['modules'] as $moduleId) {
if (!empty($this->config['modules'])) {
foreach ($this->config['modules'] as $moduleId) {
$module = Yii::$app->moduleManager->getModule($moduleId);
if($module != null) {
if ($module != null) {
$module->enable();
} else {
//TODO: throw error ? skip ?...

View File

@ -12,7 +12,7 @@ $default = [
'core' => [
'name' => 'HumHub Test',
'baseUrl' => 'http://localhost:8080',
]
],
]
],
'controllerMap' => [
@ -25,7 +25,7 @@ $default = [
],
'components' => [
'mailer' => [
'useFileTransport' => true,
'messageClass' => \yii\symfonymailer\Message::class,
],
'urlManager' => [
'showScriptName' => true,
@ -42,13 +42,13 @@ $default = [
]
];
$envCfg = dirname(__DIR__).'/../config/env/env.php';
$envCfg = dirname(__DIR__) . '/../config/env/env.php';
$env = file_exists($envCfg) ? require($envCfg) : [];
return yii\helpers\ArrayHelper::merge(
// Default Test Config
// Default Test Config
$default,
// User Overwrite
require(dirname(__DIR__).'/../config/common.php'),
// User Overwrite
require(dirname(__DIR__) . '/../config/common.php'),
$env
);