瀏覽代碼

Update NormEmail

Visman 5 年之前
父節點
當前提交
fe21f25f36
共有 4 個文件被更改,包括 32 次插入22 次删除
  1. 4 4
      composer.lock
  2. 4 4
      vendor/composer/installed.json
  3. 5 2
      vendor/miovisman/normemail/README.md
  4. 19 12
      vendor/miovisman/normemail/src/NormEmail.php

+ 4 - 4
composer.lock

@@ -65,12 +65,12 @@
             "source": {
                 "type": "git",
                 "url": "https://github.com/MioVisman/NormEmail.git",
-                "reference": "c582b1359adf1ee2efa38809e8827ed21138a9ac"
+                "reference": "2e657463266b1249e97d15c6795dd14248097cb3"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/MioVisman/NormEmail/zipball/c582b1359adf1ee2efa38809e8827ed21138a9ac",
-                "reference": "c582b1359adf1ee2efa38809e8827ed21138a9ac",
+                "url": "https://api.github.com/repos/MioVisman/NormEmail/zipball/2e657463266b1249e97d15c6795dd14248097cb3",
+                "reference": "2e657463266b1249e97d15c6795dd14248097cb3",
                 "shasum": ""
             },
             "require": {
@@ -103,7 +103,7 @@
                 "email",
                 "normalization"
             ],
-            "time": "2019-12-24T15:42:43+00:00"
+            "time": "2020-01-11T04:21:13+00:00"
         },
         {
             "name": "miovisman/parserus",

+ 4 - 4
vendor/composer/installed.json

@@ -61,12 +61,12 @@
         "source": {
             "type": "git",
             "url": "https://github.com/MioVisman/NormEmail.git",
-            "reference": "c582b1359adf1ee2efa38809e8827ed21138a9ac"
+            "reference": "2e657463266b1249e97d15c6795dd14248097cb3"
         },
         "dist": {
             "type": "zip",
-            "url": "https://api.github.com/repos/MioVisman/NormEmail/zipball/c582b1359adf1ee2efa38809e8827ed21138a9ac",
-            "reference": "c582b1359adf1ee2efa38809e8827ed21138a9ac",
+            "url": "https://api.github.com/repos/MioVisman/NormEmail/zipball/2e657463266b1249e97d15c6795dd14248097cb3",
+            "reference": "2e657463266b1249e97d15c6795dd14248097cb3",
             "shasum": ""
         },
         "require": {
@@ -74,7 +74,7 @@
             "ext-mbstring": "*",
             "php": ">=5.6.0"
         },
-        "time": "2019-12-24T15:42:43+00:00",
+        "time": "2020-01-11T04:21:13+00:00",
         "type": "library",
         "installation-source": "dist",
         "autoload": {

+ 5 - 2
vendor/miovisman/normemail/README.md

@@ -23,16 +23,19 @@ $email = $nEmail->normalize($email);
 
 ```
 // some string
+                                      =>
 ExampLe                               => example
+ExampLe@                              => example@
 exaMple.COM                           => example.com
 .example.com                          => .example.com
-@example.com                          => example.com
-"example.com                          => "example.com
+@examPLe.com                          => example.com
+"examPLe.com                          => "example.com
 "USER+++NAME@EXAMpLE.com              => "USER+++NAME@example.com
 googlemail.com                        => gmail.com
 pm.me                                 => protonmail.com
 yandex.tj                             => yandex.ru
 ya.ru                                 => yandex.ru
+.ya.ru                                => .yandex.ru
 
 // Unicode
 ПОЛЬЗОВАТЕЛЬ@домен.РУ                 => пользователь@xn--d1acufc.xn--p1ag

+ 19 - 12
vendor/miovisman/normemail/src/NormEmail.php

@@ -131,20 +131,27 @@ class NormEmail
             $local = \substr($email, 0, $pos);
         }
 
-        $domain = \mb_strtolower($domain, 'UTF-8');
+        $prefix = '';
 
-        // TODO: Process the dot at the beginning of the domain for the ban of the domains array (ban by the domain name without the local part)
+        if (isset($domain[0])) {
+            $domain = \mb_strtolower($domain, 'UTF-8');
 
-        if ('[' !== $domain[0] && \preg_match('%[\x80-\xFF]%', $domain)) {
-            $parts = \explode('.', $domain);
-            foreach ($parts as &$part) {
-                $ascii = \idn_to_ascii($part, \IDNA_DEFAULT, \INTL_IDNA_VARIANT_UTS46);
-                if (false !== $ascii) {
-                    $part = $ascii;
+            if ('.' === $domain[0]) {
+                $prefix = '.';
+                $domain = \substr($domain, 1);
+            }
+
+            if ('[' !== $domain[0] && \preg_match('%[\x80-\xFF]%', $domain)) {
+                $parts = \explode('.', $domain);
+                foreach ($parts as &$part) {
+                    $ascii = \idn_to_ascii($part, \IDNA_DEFAULT, \INTL_IDNA_VARIANT_UTS46);
+                    if (false !== $ascii) {
+                        $part = $ascii;
+                    }
                 }
+                unset($part);
+                $domain = \implode('.', $parts);
             }
-            unset($part);
-            $domain = \implode('.', $parts);
         }
 
         do {
@@ -193,9 +200,9 @@ class NormEmail
         }
 
         if ('' == $local) {
-            return $domain; // '@myhost.com' --> 'myhost.com'
+            return $prefix . $domain; // '@myhost.com' --> 'myhost.com'
         } else {
-            return $local . '@' . $domain;
+            return $local . '@' . $prefix . $domain;
         }
     }
 }