From ecc3ba134e754b5bf288765e14ac1b0a906208b5 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Sat, 30 Jun 2012 18:41:18 +0200 Subject: Show explicit error message when provided hostname is invalid (#1488550) Conflicts: program/include/rcmail.php --- program/include/rcmail.php | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) (limited to 'program/include/rcmail.php') diff --git a/program/include/rcmail.php b/program/include/rcmail.php index 66e9a5c06..b287acc2e 100644 --- a/program/include/rcmail.php +++ b/program/include/rcmail.php @@ -131,6 +131,11 @@ class rcmail private $shutdown_functions = array(); private $expunge_cache = false; + const ERROR_STORAGE = -2; + const ERROR_INVALID_REQUEST = 1; + const ERROR_INVALID_HOST = 2; + const ERROR_COOKIES_DISABLED = 3; + /** * This implements the 'singleton' design pattern @@ -814,15 +819,23 @@ class rcmail * @param string Mail storage (IMAP) user name * @param string Mail storage (IMAP) password * @param string Mail storage (IMAP) host + * @param bool Enables cookie check * * @return boolean True on success, False on failure */ - function login($username, $pass, $host=NULL) + function login($username, $pass, $host = null, $cookiecheck = false) { + $this->login_error = null; + if (empty($username)) { return false; } + if ($cookiecheck && empty($_COOKIE)) { + $this->login_error = self::ERROR_COOKIES_DISABLED; + return false; + } + $config = $this->config->all(); if (!$host) @@ -839,11 +852,18 @@ class rcmail break; } } - if (!$allowed) - return false; + if (!$allowed) { + $host = null; } - else if (!empty($config['default_host']) && $host != rcube_parse_host($config['default_host'])) + } + else if (!empty($config['default_host']) && $host != rcube_parse_host($config['default_host'])) { + $host = null; + } + + if (!$host) { + $this->login_error = self::ERROR_INVALID_HOST; return false; + } // parse $host URL $a_host = parse_url($host); @@ -983,6 +1003,23 @@ class rcmail } + /** + * Returns error code of last login operation + * + * @return int Error code + */ + public function login_error() + { + if ($this->login_error) { + return $this->login_error; + } + + if ($this->storage && $this->storage->get_error_code() < -1) { + return self::ERROR_STORAGE; + } + } + + /** * Set storage parameters. * This must be done AFTER connecting to the server! -- cgit v1.2.3