From 3d4e333534695cfd16101585f629d952020af0bf Mon Sep 17 00:00:00 2001
From: Andreas Gohr <andi@splitbrain.org>
Date: Fri, 26 May 2017 21:37:21 +0200
Subject: [PATCH] moved EmailAdressValidator to composer install #1970

---
 composer.json                                 |   3 +-
 composer.lock                                 |  43 +++++-
 inc/load.php                                  |   1 -
 inc/mail.php                                  |   6 +-
 .../email-address-validator/.gitignore        |   1 +
 .../EmailAddressValidator.php                 | 128 ++++++++----------
 .../email-address-validator/README.md         |  59 ++++++++
 .../email-address-validator/composer.json     |  26 ++++
 vendor/composer/autoload_namespaces.php       |   1 +
 vendor/composer/autoload_static.php           |   7 +
 vendor/composer/installed.json                |  43 ++++++
 11 files changed, 243 insertions(+), 75 deletions(-)
 create mode 100644 vendor/aziraphale/email-address-validator/.gitignore
 rename {inc => vendor/aziraphale/email-address-validator}/EmailAddressValidator.php (52%)
 create mode 100644 vendor/aziraphale/email-address-validator/README.md
 create mode 100644 vendor/aziraphale/email-address-validator/composer.json

diff --git a/composer.json b/composer.json
index 715f97dbf..51e359824 100644
--- a/composer.json
+++ b/composer.json
@@ -11,7 +11,8 @@
         "paragonie/random_compat": "^2.0",
         "simplepie/simplepie": "^1.4",
         "geshi/geshi": "^1.0",
-        "openpsa/universalfeedcreator": "^1.8"
+        "openpsa/universalfeedcreator": "^1.8",
+        "aziraphale/email-address-validator": "^2"
     },
     "suggest": {
         "squizlabs/php_codesniffer": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.",
diff --git a/composer.lock b/composer.lock
index e830d3882..f3971f982 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,8 +4,49 @@
         "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": "915e6fb408fdf5780e4f49b03325adcd",
+    "content-hash": "67e5a8bb8a3d52ab872761fe66bd5f26",
     "packages": [
+        {
+            "name": "aziraphale/email-address-validator",
+            "version": "2.0.1",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/aziraphale/email-address-validator.git",
+                "reference": "fa25bc22c1c0b6491657c91473fae3e40719a650"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/aziraphale/email-address-validator/zipball/fa25bc22c1c0b6491657c91473fae3e40719a650",
+                "reference": "fa25bc22c1c0b6491657c91473fae3e40719a650",
+                "shasum": ""
+            },
+            "require-dev": {
+                "phpunit/phpunit": "^5.7"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-0": {
+                    "EmailAddressValidator": ""
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Dave Child",
+                    "email": "dave@addedbytes.com"
+                },
+                {
+                    "name": "Andrew Gillard",
+                    "email": "andrew@lorddeath.net"
+                }
+            ],
+            "description": "Fork of AddedBytes' PHP EmailAddressValidator script, now with Composer support!",
+            "homepage": "https://github.com/aziraphale/email-address-validator",
+            "time": "2017-05-22T14:05:57+00:00"
+        },
         {
             "name": "geshi/geshi",
             "version": "v1.0.9.0",
diff --git a/inc/load.php b/inc/load.php
index d2a0e3442..b4004c579 100644
--- a/inc/load.php
+++ b/inc/load.php
@@ -64,7 +64,6 @@ function load_autoload($name){
         'cache_renderer'        => DOKU_INC.'inc/cache.php',
         'Doku_Event'            => DOKU_INC.'inc/events.php',
         'Doku_Event_Handler'    => DOKU_INC.'inc/events.php',
-        'EmailAddressValidator' => DOKU_INC.'inc/EmailAddressValidator.php',
         'Input'                 => DOKU_INC.'inc/Input.class.php',
         'JpegMeta'              => DOKU_INC.'inc/JpegMeta.php',
         'SimplePie'             => DOKU_INC.'inc/SimplePie.php',
diff --git a/inc/mail.php b/inc/mail.php
index 1d02fd689..511401ce3 100644
--- a/inc/mail.php
+++ b/inc/mail.php
@@ -267,10 +267,8 @@ function mail_encode_address($string,$header='',$names=true){
  * @param   string $email the address to check
  * @return  bool          true if address is valid
  */
-function mail_isvalid($email){
-    $validator = new EmailAddressValidator;
-    $validator->allowLocalAddresses = true;
-    return $validator->check_email_address($email);
+function mail_isvalid($email) {
+    return EmailAddressValidator::checkEmailAddress($email, true);
 }
 
 /**
diff --git a/vendor/aziraphale/email-address-validator/.gitignore b/vendor/aziraphale/email-address-validator/.gitignore
new file mode 100644
index 000000000..57872d0f1
--- /dev/null
+++ b/vendor/aziraphale/email-address-validator/.gitignore
@@ -0,0 +1 @@
+/vendor/
diff --git a/inc/EmailAddressValidator.php b/vendor/aziraphale/email-address-validator/EmailAddressValidator.php
similarity index 52%
rename from inc/EmailAddressValidator.php
rename to vendor/aziraphale/email-address-validator/EmailAddressValidator.php
index fd6f3275b..21285bc05 100644
--- a/inc/EmailAddressValidator.php
+++ b/vendor/aziraphale/email-address-validator/EmailAddressValidator.php
@@ -1,110 +1,106 @@
 <?php
+
 /**
- * EmailAddressValidator Class
+ * Class EmailAddressValidator
  *
- * @author  Dave Child <dave@addedbytes.com>
- * @link    http://code.google.com/p/php-email-address-validation/
- * @license http://www.opensource.org/licenses/bsd-license.php
- * @version SVN r10 + Issue 15 fix + Issue 12 fix
+ * @link https://github.com/aziraphale/email-address-validator
+ * @link http://code.google.com/p/php-email-address-validation/
+ * @license New BSD license http://www.opensource.org/licenses/bsd-license.php
+ * @example if (EmailAddressValidator::checkEmailAddress('test@example.org')) {
+ * @example     // Email address is technically valid
+ * @example }
  */
-class EmailAddressValidator {
-    /**
-     * Set true to allow addresses like me@localhost
-     */
-    public $allowLocalAddresses = false;
-
+class EmailAddressValidator
+{
     /**
      * Check email address validity
-     * @param  string $strEmailAddress     Email address to be checked
-     * @return bool True if email is valid, false if not
+     * @param string $emailAddress Email address to be checked
+     * @param bool $allowLocal allow local domains
+     * @return bool Whether email is valid
      */
-    public function check_email_address($strEmailAddress) {
-
+    public static function checkEmailAddress($emailAddress, $allowLocal = false)
+    {
         // If magic quotes is "on", email addresses with quote marks will
         // fail validation because of added escape characters. Uncommenting
         // the next three lines will allow for this issue.
         //if (get_magic_quotes_gpc()) {
-        //    $strEmailAddress = stripslashes($strEmailAddress);
+        //    $emailAddress = stripslashes($emailAddress);
         //}
 
         // Control characters are not allowed
-        if (preg_match('/[\x00-\x1F\x7F-\xFF]/', $strEmailAddress)) {
+        if (preg_match('/[\x00-\x1F\x7F-\xFF]/', $emailAddress)) {
             return false;
         }
 
         // Check email length - min 3 (a@a), max 256
-        if (!$this->check_text_length($strEmailAddress, 3, 256)) {
+        if (!self::checkTextLength($emailAddress, 3, 256)) {
             return false;
         }
 
         // Split it into sections using last instance of "@"
-        $intAtSymbol = strrpos($strEmailAddress, '@');
-        if ($intAtSymbol === false) {
+        $atSymbol = strrpos($emailAddress, '@');
+        if ($atSymbol === false) {
             // No "@" symbol in email.
             return false;
         }
-        $arrEmailAddress[0] = substr($strEmailAddress, 0, $intAtSymbol);
-        $arrEmailAddress[1] = substr($strEmailAddress, $intAtSymbol + 1);
+        $emailAddressParts[0] = substr($emailAddress, 0, $atSymbol);
+        $emailAddressParts[1] = substr($emailAddress, $atSymbol + 1);
 
         // Count the "@" symbols. Only one is allowed, except where
         // contained in quote marks in the local part. Quickest way to
         // check this is to remove anything in quotes. We also remove
         // characters escaped with backslash, and the backslash
         // character.
-        $arrTempAddress[0] = preg_replace('/\./'
-                                         ,''
-                                         ,$arrEmailAddress[0]);
-        $arrTempAddress[0] = preg_replace('/"[^"]+"/'
-                                         ,''
-                                         ,$arrTempAddress[0]);
-        $arrTempAddress[1] = $arrEmailAddress[1];
-        $strTempAddress = $arrTempAddress[0] . $arrTempAddress[1];
+        $tempAddressParts[0] = preg_replace('/\./', '', $emailAddressParts[0]);
+        $tempAddressParts[0] = preg_replace('/"[^"]+"/', '', $tempAddressParts[0]);
+        $tempAddressParts[1] = $emailAddressParts[1];
+        $tempAddress = $tempAddressParts[0] . $tempAddressParts[1];
         // Then check - should be no "@" symbols.
-        if (strrpos($strTempAddress, '@') !== false) {
+        if (strrpos($tempAddress, '@') !== false) {
             // "@" symbol found
             return false;
         }
 
         // Check local portion
-        if (!$this->check_local_portion($arrEmailAddress[0])) {
+        if (!self::checkLocalPortion($emailAddressParts[0])) {
             return false;
         }
 
         // Check domain portion
-        if (!$this->check_domain_portion($arrEmailAddress[1])) {
+        if (!self::checkDomainPortion($emailAddressParts[1], $allowLocal)) {
             return false;
         }
 
         // If we're still here, all checks above passed. Email is valid.
         return true;
-
     }
 
     /**
      * Checks email section before "@" symbol for validity
-     * @param string  $strLocalPortion     Text to be checked
-     * @return bool True if local portion is valid, false if not
+     * @param string $localPortion Text to be checked
+     * @return bool Whether local portion is valid
      */
-    protected function check_local_portion($strLocalPortion) {
+    public static function checkLocalPortion($localPortion)
+    {
         // Local portion can only be from 1 to 64 characters, inclusive.
         // Please note that servers are encouraged to accept longer local
         // parts than 64 characters.
-        if (!$this->check_text_length($strLocalPortion, 1, 64)) {
+        if (!self::checkTextLength($localPortion, 1, 64)) {
             return false;
         }
         // Local portion must be:
         // 1) a dot-atom (strings separated by periods)
         // 2) a quoted string
         // 3) an obsolete format string (combination of the above)
-        $arrLocalPortion = explode('.', $strLocalPortion);
-        for ($i = 0, $max = sizeof($arrLocalPortion); $i < $max; $i++) {
+        $localPortionParts = explode('.', $localPortion);
+        for ($i = 0, $max = sizeof($localPortionParts); $i < $max; $i++) {
              if (!preg_match('.^('
                             .    '([A-Za-z0-9!#$%&\'*+/=?^_`{|}~-]'
                             .    '[A-Za-z0-9!#$%&\'*+/=?^_`{|}~-]{0,63})'
                             .'|'
                             .    '("[^\\\"]{0,62}")'
                             .')$.'
-                            ,$arrLocalPortion[$i])) {
+                            ,$localPortionParts[$i])) {
                 return false;
             }
         }
@@ -113,12 +109,14 @@ class EmailAddressValidator {
 
     /**
      * Checks email section after "@" symbol for validity
-     * @param  string $strDomainPortion     Text to be checked
-     * @return bool True if domain portion is valid, false if not
+     * @param string $domainPortion Text to be checked
+     * @param bool $allowLocal allow local domains?
+     * @return bool Whether domain portion is valid
      */
-    protected function check_domain_portion($strDomainPortion) {
+    public static function checkDomainPortion($domainPortion, $allowLocal = false)
+    {
         // Total domain can only be from 1 to 255 characters, inclusive
-        if (!$this->check_text_length($strDomainPortion, 1, 255)) {
+        if (!self::checkTextLength($domainPortion, 1, 255)) {
             return false;
         }
 
@@ -130,7 +128,7 @@ class EmailAddressValidator {
         $IPv4Address = "$dec_octet\\.$dec_octet\\.$dec_octet\\.$dec_octet";
         $ls32 = "(?:$h16:$h16|$IPv4Address)";
         $IPv6Address =
-            "(?:(?:{$IPv4Address})|(?:".
+            "(?:(?:{$IPv4Address})|(?:" .
             "(?:$h16:){6}$ls32" .
             "|::(?:$h16:){5}$ls32" .
             "|(?:$h16)?::(?:$h16:){4}$ls32" .
@@ -142,26 +140,25 @@ class EmailAddressValidator {
             "|(?:(?:$h16:){0,6}$h16)?::" .
             ")(?:\\/(?:12[0-8]|1[0-1][0-9]|[1-9][0-9]|[0-9]))?)";
 
-        // Check if domain is IP, possibly enclosed in square brackets.
-        if (preg_match("/^($IPv4Address|\[$IPv4Address\]|\[$IPv6Address\])$/",
-                        $strDomainPortion)){
+        if (preg_match("/^($IPv4Address|\\[$IPv4Address\\]|\\[$IPv6Address\\])$/",
+                            $domainPortion)){
             return true;
         } else {
-            $arrDomainPortion = explode('.', $strDomainPortion);
-            if (!$this->allowLocalAddresses && sizeof($arrDomainPortion) < 2) {
+            $domainPortionParts = explode('.', $domainPortion);
+            if (!$allowLocal && sizeof($domainPortionParts) < 2) {
                 return false; // Not enough parts to domain
             }
-            for ($i = 0, $max = sizeof($arrDomainPortion); $i < $max; $i++) {
+            for ($i = 0, $max = sizeof($domainPortionParts); $i < $max; $i++) {
                 // Each portion must be between 1 and 63 characters, inclusive
-                if (!$this->check_text_length($arrDomainPortion[$i], 1, 63)) {
+                if (!self::checkTextLength($domainPortionParts[$i], 1, 63)) {
                     return false;
                 }
                 if (!preg_match('/^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|'
-                   .'([A-Za-z0-9]+))$/', $arrDomainPortion[$i])) {
+                   .'([A-Za-z0-9]+))$/', $domainPortionParts[$i])) {
                     return false;
                 }
                 if ($i == $max - 1) { // TLD cannot be only numbers
-                    if (strlen(preg_replace('/[0-9]/', '', $arrDomainPortion[$i])) <= 0) {
+                    if (strlen(preg_replace('/[0-9]/', '', $domainPortionParts[$i])) <= 0) {
                         return false;
                     }
                 }
@@ -172,20 +169,15 @@ class EmailAddressValidator {
 
     /**
      * Check given text length is between defined bounds
-     * @param   string $strText     Text to be checked
-     * @param   int $intMinimum  Minimum acceptable length
-     * @param   int $intMaximum  Maximum acceptable length
-     * @return bool True if string is within bounds (inclusive), false if not
+     * @param string $text Text to be checked
+     * @param int $minimum Minimum acceptable length
+     * @param int $maximum Maximum acceptable length
+     * @return bool Whether string is within bounds (inclusive)
      */
-    protected function check_text_length($strText, $intMinimum, $intMaximum) {
+    protected static function checkTextLength($text, $minimum, $maximum)
+    {
         // Minimum and maximum are both inclusive
-        $intTextLength = strlen($strText);
-        if (($intTextLength < $intMinimum) || ($intTextLength > $intMaximum)) {
-            return false;
-        } else {
-            return true;
-        }
+        $textLength = strlen($text);
+        return ($textLength >= $minimum && $textLength <= $maximum);
     }
-
 }
-
diff --git a/vendor/aziraphale/email-address-validator/README.md b/vendor/aziraphale/email-address-validator/README.md
new file mode 100644
index 000000000..60bff6093
--- /dev/null
+++ b/vendor/aziraphale/email-address-validator/README.md
@@ -0,0 +1,59 @@
+Email-Address-Validator
+=======================
+
+This is a fork of [AddedBytes' EmailAddressValidator class](https://code.google.com/p/php-email-address-validation/).
+
+## Changes ##
+Changes include:
+
+- [Composer](https://getcomposer.org/) support
+- Refactored the class to be purely static
+- Opened up methods for checking the "local part" (the bit before the `@`) and the "domain part" (after the `@`) 
+to be public methods
+- Additional code style and docblock fixing to properly follow the [PHP-FIG PSR-1](http://www.php-fig.org/psr/psr-1/) 
+and [PSR-2](http://www.php-fig.org/psr/psr-2/) documents
+
+Note that this class is still **un-namespaced** - i.e. it's still declared in the global namespace. The `composer.json` 
+file is still set up to correctly load it when required, so this shouldn't be a problem in practice - it's just perhaps
+not best-practice.
+
+## Installation ##
+Use [Composer](https://getcomposer.org/):
+```
+php composer.phar require aziraphale/email-address-validator:^2
+```
+
+If you don't want to use Composer (why not?!), just download the `EmailAddressValidator.php` file, save it with your project, and `require` it where needed.
+
+Note that this updated version is **version 2.0.0**. I have kept the original class tagged as **version 1.0.10** (it was the 10th commit to the Google Code svn repository). If you want to use Composer to install the **old** class, simply specify `^1` as the version constraint (which will allow for backwards-compatible changes to be installed, if any get made, while never jumping to my modified class without your direct action):
+```
+php composer.phar require aziraphale/email-address-validator:^1
+```
+
+## Usage ##
+Due to the aforementioned changes, the way of using this class has completely changed. However it has such a small and simple interface that these changes shouldn't be problematic.
+
+As a recap, the **old usage** was like this:
+```php
+$validator = new EmailAddressValidator;
+if ($validator->check_email_address('test@example.org')) {
+    // Email address is technically valid
+}
+```
+
+The **new syntax** is as follows (ensure you have already included Composer's `autoload.php` file!):
+```php
+if (EmailAddressValidator::checkEmailAddress("test@example.org")) {
+    // Email address is technically valid
+}
+```
+
+with a couple of additional methods in case they're helpful:
+```php
+if (EmailAddressValidator::checkLocalPortion("test")) {
+    // "test" is technically a valid string to have before the "@" in an email address
+}
+if (EmailAddressValidator::checkDomainPotion("example.org")) {
+    // "example.org" is technically a valid email address host
+}
+```
diff --git a/vendor/aziraphale/email-address-validator/composer.json b/vendor/aziraphale/email-address-validator/composer.json
new file mode 100644
index 000000000..6c72ddb74
--- /dev/null
+++ b/vendor/aziraphale/email-address-validator/composer.json
@@ -0,0 +1,26 @@
+{
+    "name": "aziraphale/email-address-validator",
+    "version": "2.0.1",
+    "description": "Fork of AddedBytes' PHP EmailAddressValidator script, now with Composer support!",
+    "homepage": "https://github.com/aziraphale/email-address-validator",
+    "license": "MIT",
+    "authors": [
+        {
+            "name": "Dave Child",
+            "email": "dave@addedbytes.com"
+        },
+        {
+            "name": "Andrew Gillard",
+            "email": "andrew@lorddeath.net"
+        }
+    ],
+    "require": {},
+    "autoload": {
+        "psr-0": {
+            "EmailAddressValidator": ""
+        }
+    },
+    "require-dev": {
+        "phpunit/phpunit": "^5.7"
+    }
+}
diff --git a/vendor/composer/autoload_namespaces.php b/vendor/composer/autoload_namespaces.php
index 86667b950..6a43fa58f 100644
--- a/vendor/composer/autoload_namespaces.php
+++ b/vendor/composer/autoload_namespaces.php
@@ -7,4 +7,5 @@ $baseDir = dirname($vendorDir);
 
 return array(
     'SimplePie' => array($vendorDir . '/simplepie/simplepie/library'),
+    'EmailAddressValidator' => array($vendorDir . '/aziraphale/email-address-validator'),
 );
diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php
index 46be7ebe1..2e2f8c456 100644
--- a/vendor/composer/autoload_static.php
+++ b/vendor/composer/autoload_static.php
@@ -41,6 +41,13 @@ class ComposerStaticInita19a915ee98347a0c787119619d2ff9b
                 0 => __DIR__ . '/..' . '/simplepie/simplepie/library',
             ),
         ),
+        'E' => 
+        array (
+            'EmailAddressValidator' => 
+            array (
+                0 => __DIR__ . '/..' . '/aziraphale/email-address-validator',
+            ),
+        ),
     );
 
     public static $classMap = array (
diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json
index a9d312261..6be86c9da 100644
--- a/vendor/composer/installed.json
+++ b/vendor/composer/installed.json
@@ -349,5 +349,48 @@
             "pie",
             "rss"
         ]
+    },
+    {
+        "name": "aziraphale/email-address-validator",
+        "version": "2.0.1",
+        "version_normalized": "2.0.1.0",
+        "source": {
+            "type": "git",
+            "url": "https://github.com/aziraphale/email-address-validator.git",
+            "reference": "fa25bc22c1c0b6491657c91473fae3e40719a650"
+        },
+        "dist": {
+            "type": "zip",
+            "url": "https://api.github.com/repos/aziraphale/email-address-validator/zipball/fa25bc22c1c0b6491657c91473fae3e40719a650",
+            "reference": "fa25bc22c1c0b6491657c91473fae3e40719a650",
+            "shasum": ""
+        },
+        "require-dev": {
+            "phpunit/phpunit": "^5.7"
+        },
+        "time": "2017-05-22T14:05:57+00:00",
+        "type": "library",
+        "installation-source": "dist",
+        "autoload": {
+            "psr-0": {
+                "EmailAddressValidator": ""
+            }
+        },
+        "notification-url": "https://packagist.org/downloads/",
+        "license": [
+            "MIT"
+        ],
+        "authors": [
+            {
+                "name": "Dave Child",
+                "email": "dave@addedbytes.com"
+            },
+            {
+                "name": "Andrew Gillard",
+                "email": "andrew@lorddeath.net"
+            }
+        ],
+        "description": "Fork of AddedBytes' PHP EmailAddressValidator script, now with Composer support!",
+        "homepage": "https://github.com/aziraphale/email-address-validator"
     }
 ]
-- 
GitLab