public static function encodeEmail($email)
    {
        if (($pos = strpos($email, '@')) === false) {
            return;
        }
        if (!preg_match('~[\x80-\xFF]~', $email)) {
            return $email;
        }
        $domain = substr($email, ++$pos);
        return substr($email, 0, $pos) . idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46);
    }