From 1d8244fd99ff84935fa4b843d745f03a348594e7 Mon Sep 17 00:00:00 2001
From: Mathieu <mathieu@mathieu-Terra3-PC.home>
Date: Tue, 3 Apr 2018 12:30:37 +0200
Subject: [PATCH] =?UTF-8?q?=20correction=20:=20filtre=20adresse=20e-mail?=
 =?UTF-8?q?=20avec=20nom=20de=20domaine=20internationalis=C3=A9=20=20https?=
 =?UTF-8?q?://framagit.org/framasoft/framadate/merge=5Frequests/268?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../Framadate/Services/InputService.php       |  42 ++---
 composer.json                                 |   3 +-
 composer.lock                                 | 167 ++++++++++++------
 3 files changed, 127 insertions(+), 85 deletions(-)

diff --git a/app/classes/Framadate/Services/InputService.php b/app/classes/Framadate/Services/InputService.php
index 32283b10..5f308851 100644
--- a/app/classes/Framadate/Services/InputService.php
+++ b/app/classes/Framadate/Services/InputService.php
@@ -18,6 +18,8 @@
  */
 namespace Framadate\Services;
 use DateTime;
+use Egulias\EmailValidator\EmailValidator;
+use Egulias\EmailValidator\Validation\RFCValidation;
 
 /**
  * This class helps to clean all inputs from the users or external services.
@@ -66,42 +68,24 @@ class InputService {
 
     public function filterMail($mail) {
         
-        $mail = mb_strtolower(trim($mail));
+    	///////////////////////////////////////////////////////////////////////////////////////
+        // formatting
         
+    	$mail = trim($mail);
         
-        $decoupage = explode("@", $mail, 2);
+    	///////////////////////////////////////////////////////////////////////////////////////
+        // e-mail validation
         
         $resultat = FALSE;
         
-        
-        if (isset($decoupage[1])) {
-            
-            $domaine = idn_to_ascii(
-                  $decoupage[1]
-                , IDNA_DEFAULT
-                , INTL_IDNA_VARIANT_UTS46
-            );
-            
-            $adresseConvertie = "{$decoupage[0]}@$domaine";
-            
-            $adresseFiltree = filter_var(
-                  $adresseConvertie
-                , FILTER_VALIDATE_EMAIL
-                , ["flags" => FILTER_FLAG_EMAIL_UNICODE] // permet d'utiliser des accents avant le @
-            );
-            
-            if ($adresseConvertie === $adresseFiltree) {
-                
-                $testMX = getmxrr($domaine, $_); // tester sur le domaine indique un serveur MX
-                
-                if ($testMX) {
-                    $resultat = $mail;
-                }
-                
-            }
-            
+    	$validator = new EmailValidator();
+    	
+        if ($validator->isValid($mail, new RFCValidation())) {
+            $resultat = $mail;
         }
         
+        ///////////////////////////////////////////////////////////////////////////////////////
+        // return
         
         return $resultat;
     }
diff --git a/composer.json b/composer.json
index f48c4aa3..d19901f9 100644
--- a/composer.json
+++ b/composer.json
@@ -61,7 +61,8 @@
         "phpmailer/phpmailer": "^5.2",
         "ircmaxell/password-compat": "dev-master",
         "roave/security-advisories": "dev-master",
-        "erusev/parsedown": "^1.7"
+        "erusev/parsedown": "^1.7",
+        "egulias/email-validator": "~2.1"
     },
 
     "require-dev": {
diff --git a/composer.lock b/composer.lock
index 6e33e0f8..e855b8c3 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,8 +4,119 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
         "This file is @generated automatically"
     ],
-    "content-hash": "a3ca2dd4f87562095f8c19a94560fed7",
+    "content-hash": "40759eac537218b0212ed923261b9850",
     "packages": [
+        {
+            "name": "doctrine/lexer",
+            "version": "v1.0.1",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/doctrine/lexer.git",
+                "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/doctrine/lexer/zipball/83893c552fd2045dd78aef794c31e694c37c0b8c",
+                "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c",
+                "shasum": ""
+            },
+            "require": {
+                "php": ">=5.3.2"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "1.0.x-dev"
+                }
+            },
+            "autoload": {
+                "psr-0": {
+                    "Doctrine\\Common\\Lexer\\": "lib/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Roman Borschel",
+                    "email": "roman@code-factory.org"
+                },
+                {
+                    "name": "Guilherme Blanco",
+                    "email": "guilhermeblanco@gmail.com"
+                },
+                {
+                    "name": "Johannes Schmitt",
+                    "email": "schmittjoh@gmail.com"
+                }
+            ],
+            "description": "Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.",
+            "homepage": "http://www.doctrine-project.org",
+            "keywords": [
+                "lexer",
+                "parser"
+            ],
+            "time": "2014-09-09T13:34:57+00:00"
+        },
+        {
+            "name": "egulias/email-validator",
+            "version": "2.1.3",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/egulias/EmailValidator.git",
+                "reference": "1bec00a10039b823cc94eef4eddd47dcd3b2ca04"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/1bec00a10039b823cc94eef4eddd47dcd3b2ca04",
+                "reference": "1bec00a10039b823cc94eef4eddd47dcd3b2ca04",
+                "shasum": ""
+            },
+            "require": {
+                "doctrine/lexer": "^1.0.1",
+                "php": ">= 5.5"
+            },
+            "require-dev": {
+                "dominicsayers/isemail": "dev-master",
+                "phpunit/phpunit": "^4.8.35",
+                "satooshi/php-coveralls": "^1.0.1"
+            },
+            "suggest": {
+                "ext-intl": "PHP Internationalization Libraries are required to use the SpoofChecking validation"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "2.0.x-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Egulias\\EmailValidator\\": "EmailValidator"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Eduardo Gulias Davis"
+                }
+            ],
+            "description": "A library for validating emails against several RFCs",
+            "homepage": "https://github.com/egulias/EmailValidator",
+            "keywords": [
+                "email",
+                "emailvalidation",
+                "emailvalidator",
+                "validation",
+                "validator"
+            ],
+            "time": "2017-11-15T23:40:40+00:00"
+        },
         {
             "name": "erusev/parsedown",
             "version": "1.7.1",
@@ -613,60 +724,6 @@
             ],
             "time": "2015-06-14T21:17:01+00:00"
         },
-        {
-            "name": "doctrine/lexer",
-            "version": "v1.0.1",
-            "source": {
-                "type": "git",
-                "url": "https://github.com/doctrine/lexer.git",
-                "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c"
-            },
-            "dist": {
-                "type": "zip",
-                "url": "https://api.github.com/repos/doctrine/lexer/zipball/83893c552fd2045dd78aef794c31e694c37c0b8c",
-                "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c",
-                "shasum": ""
-            },
-            "require": {
-                "php": ">=5.3.2"
-            },
-            "type": "library",
-            "extra": {
-                "branch-alias": {
-                    "dev-master": "1.0.x-dev"
-                }
-            },
-            "autoload": {
-                "psr-0": {
-                    "Doctrine\\Common\\Lexer\\": "lib/"
-                }
-            },
-            "notification-url": "https://packagist.org/downloads/",
-            "license": [
-                "MIT"
-            ],
-            "authors": [
-                {
-                    "name": "Roman Borschel",
-                    "email": "roman@code-factory.org"
-                },
-                {
-                    "name": "Guilherme Blanco",
-                    "email": "guilhermeblanco@gmail.com"
-                },
-                {
-                    "name": "Johannes Schmitt",
-                    "email": "schmittjoh@gmail.com"
-                }
-            ],
-            "description": "Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.",
-            "homepage": "http://www.doctrine-project.org",
-            "keywords": [
-                "lexer",
-                "parser"
-            ],
-            "time": "2014-09-09T13:34:57+00:00"
-        },
         {
             "name": "friendsofphp/php-cs-fixer",
             "version": "v2.10.4",
-- 
GitLab