Commit 7e95ee3a authored by Georg Ringer's avatar Georg Ringer Committed by Daniel Goerz
Browse files

[FEATURE] Improved Email Validation

The method :php`\TYPO3\CMS\Core\Utility\GeneralUtility::validEmail`
is used to validate a given email address through the core
and TYPO3 extensions.

The validation can now be configured by providing the used
validators to be used in the LocalConfiguration.php or
AdditionalConfiguration.php.

Example:

   $GLOBALS['TYPO3_CONF_VARS']['MAIL']['validators'] = [
     \Egulias\EmailValidator\Validation\RFCValidation::class,
     \Egulias\EmailValidator\Validation\DNSCheckValidation::class'
   ];

The RFCValidation validator is still be used as default.

Furthermore, following validators are available:

- Egulias\EmailValidator\Validation\DNSCheckValidation
- Egulias\EmailValidator\Validation\SpoofCheckValidation
- Egulias\EmailValidator\Validation\NoRFCWarningsValidation

It is also possible to provide own validators which must implement
the Egulias\EmailValidator\Validation\EmailValidation interface.

If multiple validators are provided, each validator must return TRUE.

Resolves: #92531
Releases: master
Change-Id: I9c5a0573c2f9bff56bf869dc221a2c0ffd75417b
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/66179


Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: default avatarJosef Glatz <josefglatz@gmail.com>
Reviewed-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
parent db61a944
......@@ -16,6 +16,8 @@
namespace TYPO3\CMS\Core\Utility;
use Egulias\EmailValidator\EmailValidator;
use Egulias\EmailValidator\Validation\EmailValidation;
use Egulias\EmailValidator\Validation\MultipleValidationWithAnd;
use Egulias\EmailValidator\Validation\RFCValidation;
use GuzzleHttp\Exception\RequestException;
use Psr\Container\ContainerInterface;
......@@ -801,8 +803,14 @@ class GeneralUtility
if (trim($email) !== $email) {
return false;
}
$validator = new EmailValidator();
return $validator->isValid($email, new RFCValidation());
$validators = [];
foreach ($GLOBALS['TYPO3_CONF_VARS']['MAIL']['validators'] ?? [RFCValidation::class] as $className) {
$validator = new $className();
if ($validator instanceof EmailValidation) {
$validators[] = $validator;
}
}
return (new EmailValidator())->isValid($email, new MultipleValidationWithAnd($validators));
}
/**
......
......@@ -1376,6 +1376,9 @@ return [
'transport_mbox_file' => '',
'transport_spool_type' => '',
'transport_spool_filepath' => '',
'validators' => [
\Egulias\EmailValidator\Validation\RFCValidation::class
],
'defaultMailFromAddress' => '',
'defaultMailFromName' => '',
'defaultMailReplyToAddress' => '',
......
......@@ -558,6 +558,9 @@ MAIL:
templateRootPaths:
type: array
description: 'List of paths to look for template files for templated emails. Should be specified as .txt and .html files.'
validators:
type: array
description: 'List of validators used to validate an email address. <br>Available validators are <code>\Egulias\EmailValidator\Validation\DNSCheckValidation</code>, <code>\Egulias\EmailValidator\Validation\SpoofCheckValidation</code>, <code>\Egulias\EmailValidator\Validation\NoRFCWarningsValidation</code> or by implementing a custom validator.'
transport:
type: text
description: '<dl><dt>smtp</dt><dd>Sends messages over the (standardized) Simple Message Transfer Protocol. It can deal with encryption and authentication. Most flexible option, requires a mail server and configurations in transport_smtp_* settings below. Works the same on Windows, Unix and MacOS.</dd><dt>sendmail</dt><dd>Sends messages by communicating with a locally installed MTA - such as sendmail. See setting transport_sendmail_command bellow.<dd><dt>mbox</dt><dd>This doesn''t send any mail out, but instead will write every outgoing mail to a file adhering to the RFC 4155 mbox format, which is a simple text file where the mails are concatenated. Useful for debugging the mail sending process and on development machines which cannot send mails to the outside. Configure the file to write to in the ''transport_mbox_file'' setting below</dd><dt>&lt;classname&gt;</dt><dd>Custom class which implements Swift_Transport. The constructor receives all settings from the MAIL section to make it possible to add custom settings.</dd></dl>'
......
.. include:: ../../Includes.txt
===========================================
Feature: #92531 - Improved Email Validation
===========================================
See :issue:`92531`
Description
===========
The method :php`\TYPO3\CMS\Core\Utility\GeneralUtility::validEmail` is used to
validate a given email address through the core and TYPO3 extensions.
The validation can now be configured by providing the used validators in
the :file:`LocalConfiguration.php` or :file:`AdditionalConfiguration.php`:
.. code-block:: php
$GLOBALS['TYPO3_CONF_VARS']['MAIL']['validators'] = [
\Egulias\EmailValidator\Validation\RFCValidation::class,
\Egulias\EmailValidator\Validation\DNSCheckValidation::class
];
By default, the validator :php:`\Egulias\EmailValidator\Validation\RFCValidation`
is used. The following validators are available by default:
- :php:`\Egulias\EmailValidator\Validation\DNSCheckValidation`
- :php:`\Egulias\EmailValidator\Validation\SpoofCheckValidation`
- :php:`\Egulias\EmailValidator\Validation\NoRFCWarningsValidation`
Additionally it is possible to provide an own implementation by implementing the
interface :php:`\Egulias\EmailValidator\Validation\EmailValidation`.
If multiple validators are provided, each validator must return `TRUE`.
Impact
======
Using additional validators can help to identify if a provided email address is
valid or not.
.. index:: LocalConfiguration, PHP-API, ext:core
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment