summaryrefslogtreecommitdiff
path: root/program/include
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2012-06-30 18:41:18 +0200
committerAleksander Machniak <alec@alec.pl>2012-06-30 18:41:18 +0200
commit7c8fd8031038e7958ef4dbb059e86decd6fefa28 (patch)
tree98b788759409a2916a7f49e74b2aef1d12cf48e9 /program/include
parentf69eb5fd684a4b563308b9e024088bf7e0e5952a (diff)
Show explicit error message when provided hostname is invalid (#1488550)
Diffstat (limited to 'program/include')
-rw-r--r--program/include/rcmail.php46
1 files changed, 42 insertions, 4 deletions
diff --git a/program/include/rcmail.php b/program/include/rcmail.php
index 8ec8cfe47..63ae8e20f 100644
--- a/program/include/rcmail.php
+++ b/program/include/rcmail.php
@@ -58,6 +58,12 @@ class rcmail extends rcube
const JS_OBJECT_NAME = 'rcmail';
+ 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
*
@@ -366,15 +372,23 @@ class rcmail extends rcube
* @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)
@@ -391,11 +405,18 @@ class rcmail extends rcube
break;
}
}
- if (!$allowed)
- return false;
+ if (!$allowed) {
+ $host = null;
}
- else if (!empty($config['default_host']) && $host != rcube_utils::parse_host($config['default_host']))
+ }
+ else if (!empty($config['default_host']) && $host != rcube_utils::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);
@@ -534,6 +555,23 @@ class rcmail extends rcube
}
+ /**
+ * 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;
+ }
+ }
+
+
/**
* Auto-select IMAP host based on the posted login information
*