/** * Tries to find an auth server and login * * @param $email * @param $password * @return bool * @throws \Exception */ public function login($email, $password) { if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { throw new \Exception('Not a valid email'); } $this->email = $email; $this->password = $password; $this->status = self::STATUS_UNKNOWN; $discover = new Discover(); if ($cfg = $discover->imap($email)) { if ($discover->mxServerRoot) { // assure that it's not Google or some other if (in_array($discover->mxServerRoot, ['google.com', 'outlook.com'])) { if ($this->config->tryRestricted) { return $this->imapAuth('imap.' . $discover->mxServerRoot); } $this->status = self::STATUS_OAUTH_NEEDED; return false; } } return $this->imapAuth($cfg['host'], $cfg['port']); } else { $domain = explode('@', $email); return $this->imapAuth('imap.' . $domain[1]); } }