public static function isValid(string $email, bool $useExampleDomainCheck = false, bool $useTypoInDomainCheck = false, bool $useTemporaryDomainCheck = false, bool $useDnsCheck = false): bool
    {
        if (!isset($email[0])) {
            return false;
        }

        // make sure string length is limited to avoid DOS attacks
        $emailStringLength = \strlen($email);
        if (
            $emailStringLength >= 320
            ||
            $emailStringLength <= 2 // i@y //
        ) {
            return false;
        }
        unset($emailStringLength);

        $email = \str_replace(
            [
                '.', // non-Latin chars are also allowed | https://tools.ietf.org/html/rfc6530
                '＠', // non-Latin chars are also allowed | https://tools.ietf.org/html/rfc6530
            ],
            [
                '.',
                '@',
            ],
            $email
        );

        if (
            (\strpos($email, '@') === false) // "at" is needed
            ||
            (\strpos($email, '.') === false && \strpos($email, ':') === false) // "dot" or "colon" is needed
        ) {
            return false;
        }

        if (!\preg_match('/^(?<local>.*<?)(?:.*)@(?<domain>.*)(?:>?)$/', $email, $parts)) {
            return false;
        }

        $local = $parts['local'];
        $domain = $parts['domain'];

        if (!$local) {
            return false;
        }

        if (!$domain) {
            return false;
        }

        // Escaped spaces are allowed in the "local"-part.
        $local = \str_replace('\\ ', '', $local);

        // Spaces in quotes e.g. "firstname lastname"@foo.bar are also allowed in the "local"-part.
        $quoteHelperForIdn = false;
        if (\preg_match('/^"(?<inner>[^"]*)"$/mU', $local, $parts)) {
            $quoteHelperForIdn = true;
            $local = \trim(
                \str_replace(
                    $parts['inner'],
                    \str_replace(' ', '', $parts['inner']),
                    $local
                ),
                '"'
            );
        }

        if (
            \strpos($local, ' ') !== false // no spaces allowed, anymore
            ||
            \strpos($local, '".') !== false // no quote + dot allowed
        ) {
            return false;
        }

        list($local, $domain) = self::punnycode($local, $domain);

        if ($quoteHelperForIdn === true) {
            $local = '"' . $local . '"';
        }

        $email = $local . '@' . $domain;

        if (!\filter_var($email, \FILTER_VALIDATE_EMAIL)) {
            return false;
        }

        if ($useExampleDomainCheck === true && self::isExampleDomain($domain) === true) {
            return false;
        }

        if ($useTypoInDomainCheck === true && self::isTypoInDomain($domain) === true) {
            return false;
        }

        if ($useTemporaryDomainCheck === true && self::isTemporaryDomain($domain) === true) {
            return false;
        }

        if ($useDnsCheck === true && self::isDnsError($domain) === true) {
            return false;
        }

        return true;
    }