diff options
author | Aleksander Machniak <alec@alec.pl> | 2021-12-07 17:07:54 +0300 |
---|---|---|
committer | Aleksander Machniak <alec@alec.pl> | 2021-12-07 17:07:54 +0300 |
commit | 893216cb297268d222ae49099e6654a304b72e3f (patch) | |
tree | 417fc69e5e91a743c0a9675fe30132de237860d4 /program/include/rcmail.php | |
parent | 9aa6789c6527f22592ceb1a4829d759cf924f83e (diff) |
Unified and simplified services connection options (#8310)
Diffstat (limited to 'program/include/rcmail.php')
-rw-r--r-- | program/include/rcmail.php | 47 |
1 files changed, 17 insertions, 30 deletions
diff --git a/program/include/rcmail.php b/program/include/rcmail.php index 941d073a1..87ad2d3cb 100644 --- a/program/include/rcmail.php +++ b/program/include/rcmail.php @@ -669,8 +669,7 @@ class rcmail extends rcube return false; } - $default_host = $this->config->get('default_host'); - $default_port = $this->config->get('default_port'); + $imap_host = $this->config->get('imap_host', 'tls://localhost:143'); $username_domain = $this->config->get('username_domain'); $login_lc = $this->config->get('login_lc', 2); @@ -682,45 +681,33 @@ class rcmail extends rcube // host is validated in rcmail::autoselect_host(), so here // we'll only handle unset host (if possible) - if (!$host && !empty($default_host)) { - if (is_array($default_host)) { - $key = key($default_host); - $host = is_numeric($key) ? $default_host[$key] : $key; + if (!$host && !empty($imap_host)) { + if (is_array($imap_host)) { + $key = key($imap_host); + $host = is_numeric($key) ? $imap_host[$key] : $key; } else { - $host = $default_host; + $host = $imap_host; } - - $host = rcube_utils::parse_host($host); } + $host = rcube_utils::parse_host($host); + if (!$host) { $this->login_error = self::ERROR_INVALID_HOST; return false; } // parse $host URL - $a_host = parse_url($host); - $ssl = false; - $port = null; - - if (!empty($a_host['host'])) { - $host = $a_host['host']; - - if (isset($a_host['scheme']) && in_array($a_host['scheme'], ['ssl', 'imaps', 'tls'])) { - $ssl = $a_host['scheme']; - } - - if (!empty($a_host['port'])) { - $port = $a_host['port']; - } - else if ($ssl && $ssl != 'tls' && (!$default_port || $default_port == 143)) { - $port = 993; - } - } + $url = parse_url($host); + $ssl = false; + $port = 143; - if (empty($port)) { - $port = $default_port; + if (!empty($url['host'])) { + $host = $url['host']; + $scheme = $url['scheme'] ?? null; + $ssl = in_array($scheme, ['ssl', 'imaps', 'tls']) ? $scheme : false; + $port = $url['port'] ?? ($ssl && $ssl != 'tls' ? 993 : 143); } // Check if we need to add/force domain to username @@ -969,7 +956,7 @@ class rcmail extends rcube */ public function autoselect_host() { - $default_host = $this->config->get('default_host'); + $default_host = $this->config->get('imap_host'); $host = null; if (is_array($default_host)) { |