Internal method to obfuscate an email address
@param string $mail Mail address
@return string
510962
protected function obfuscate($mail)
    {
        return preg_replace_callback('/^([^@]+)(.*)$/', function ($matches) {
            $lenght = floor(strlen($matches[1]) / 2);
            $name = substr($matches[1], 0, $lenght) . str_repeat('*', $lenght);

            return $name . $matches[2];
        }, $mail);
    }
1238785
public function byUsernameOrEmail($usernameOrEmail) {
    if (filter_var($usernameOrEmail, FILTER_VALIDATE_EMAIL)) {
      return $this->byEmail($usernameOrEmail);
    }

    return $this->byUsername($usernameOrEmail);
  }
347793
public static function fix_email($email)
    {
        $parts = rcube_utils::explode_quoted_string('@', $email);
        foreach ($parts as $idx => $part) {
            // remove redundant quoting (#1490040)
            if ($part[0] == '"' && preg_match('/^"([a-zA-Z0-9._+=-]+)"$/', $part, $m)) {
                $parts[$idx] = $m[1];
            }
        }

        return implode('@', $parts);
    }
465745
public function validateEmail($email)
    {
        // Split email address up and disallow '..'
        $pattern = "/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i";
        if ((strpos($email, '..') === false) && preg_match( $pattern, $email))
        {
            return true;
        }

        return false;
    }
1067862
static function email2user($email)
    {
        $rcube = rcube::get_instance();
        $plugin = $rcube->plugins->exec_hook('email2user',
            array('email' => $email, 'user' => NULL));

        return $plugin['user'];
    }
1111998
protected static function validateEmailAddress($email) {
		if (empty($email)) {
			throw new InvalidEmailException();
		}

		$email = \trim($email);

		if (!\filter_var($email, \FILTER_VALIDATE_EMAIL)) {
			throw new InvalidEmailException();
		}

		return $email;
	}
381998
public static function emailToLink($text)
    {
        preg_match_all("/([\\\a-z0-9_\-\.]+)@([a-z0-9-]{1,64})\.([a-z]{2,10})/iu", $text, $emails);

        foreach ($emails[0] as $email) {
            $email = trim($email);

            if ($email[0] == '\\') {
                $text = str_replace($email, mb_substr($email, 1), $text);
            } else {
                $text = str_replace($email, static::emailObfuscator($email), $text);
            }
        }

        return $text;
    }
74923
private function overrideRecipient($email)
    {
        if (!$this->config->overrideRecipients()) {
            return $email;
        }

        if (!$this->config->overrideGmailStyle()) {
            return $this->config->getRecipientOverride();
        }

        list ($userPart, $domainPart) = explode('@', $this->config->getRecipientOverride());
        $reformattedEmail = trim(preg_replace('/([^a-z0-9]+)/i', '-', $email), '-');

        return sprintf('%s+%s@%s', $userPart, $reformattedEmail, $domainPart);
    }
918559
public static function protectEmail($email)
    {
        $chunks = explode('@', $email);
        $chunks[0] = substr($chunks[0], 0, 2) . '****';
        return implode('@', $chunks);
    }
82698
public static function parseEmailAddress($email)
    {
        $pattern = sprintf('/^(?<local>%s)@(?<domain>%s)$/iD', self::EMAIL_REGEX_LOCAL, self::EMAIL_REGEX_DOMAIN);

        if (!preg_match($pattern, $email, $parts)) {
            throw new InvalidEmailException(sprintf('"%s" is not a valid email', $email));
        }

        return array_map('strtolower', [$parts['local'], $parts['domain']]);
    }
78300
protected function _formatAddress($email, $name)
    {
        if ($name === '' || $name === null || $name === $email) {
            return $email;
        } else {
            $encodedName = $this->_encodeHeader($name);
            if ($encodedName === $name  &&  strcspn($name, '()<>[]:;@\\,') != strlen($name)) {
                $format = '"%s" <%s>';
            } else {
                $format = '%s <%s>';
            }
            return sprintf($format, $encodedName, $email);
        }
    }
1356635
public function normalizeEmail($email)
    {
        if (preg_match('#[^(\x20-\x7F)]+#', $email)) {

            list($user, $domain) = explode('@', $email);

            return $user . '@' . $this->punycode($domain);

        } else {
            return $email;
        }
    }
605941
public static function stripEmail($email) {
		if (strpos($email, '<') && substr($email, -1) == '>') {
			return substr($email, strpos($email, '<') + 1, (strlen($email) - strpos($email, '<')) - 2);
		}
		return $email;
	}
771528
public function setEmail($email)
    {
        $email = (string) $email;

        if ($this->exists() && $this->email !== $email) {
            $this->updated['email'] = true;
        }

        $this->email = $email;

        return $this;
    }
881363
protected function parse_email($email)
        {
            $parts  = explode('@', $email);
            $domain = array_pop($parts);
            $user   = implode('@', $parts);
            return array($user, $domain);
        }
143330
public function deleteVerifiedEmailAddress($email) {
		$rest = new SimpleEmailServiceRequest($this, 'DELETE');
		$rest->setParameter('Action', 'DeleteVerifiedEmailAddress');
		$rest->setParameter('EmailAddress', $email);

		$rest = $rest->getResponse();
		if($rest->error === false && $rest->code !== 200) {
			$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
		}
		if($rest->error !== false) {
			$this->__triggerError('deleteVerifiedEmailAddress', $rest->error);
			return false;
		}

		$response['RequestId'] = (string)$rest->body->ResponseMetadata->RequestId;
		return $response;
	}
796087
public function getModelForEmail($email)
    {
        $emailTemplates = $this->getEmailTemplates();

        foreach ($emailTemplates as $emailTemplate) {
            $emailRule = new Email($emailTemplate);

            if ($emailRule->check($email)) {
                return $this->bannedEmailsRepository->findByEmail($emailTemplate);
            }
        }

        return null;
    }