diff options
author | alecpl <alec@alec.pl> | 2011-02-03 13:58:07 +0000 |
---|---|---|
committer | alecpl <alec@alec.pl> | 2011-02-03 13:58:07 +0000 |
commit | e8d5bdc84ecfdf6fe5008655215a258bbdf0c521 (patch) | |
tree | 24e98fca92b72bcc0ba4b5519f5d2c9265a7c8d5 /program/include | |
parent | 9ebac6616d32d7672ea59da67321380037e2324c (diff) |
- Fix IDNA support when IDN/INTL modules are in use (#1487742)
Diffstat (limited to 'program/include')
-rw-r--r-- | program/include/main.inc | 33 | ||||
-rw-r--r-- | program/include/rcmail.php | 4 | ||||
-rw-r--r-- | program/include/rcube_config.php | 2 | ||||
-rw-r--r-- | program/include/rcube_ldap.php | 2 | ||||
-rw-r--r-- | program/include/rcube_shared.inc | 2 | ||||
-rw-r--r-- | program/include/rcube_smtp.php | 7 | ||||
-rwxr-xr-x | program/include/rcube_template.php | 2 |
7 files changed, 43 insertions, 9 deletions
diff --git a/program/include/main.inc b/program/include/main.inc index 7f4945692..697b3ff21 100644 --- a/program/include/main.inc +++ b/program/include/main.inc @@ -1891,6 +1891,39 @@ function check_email($email, $dns_check=true) return false; } +/* + * Idn_to_ascii wrapper. + * Intl/Idn modules version of this function doesn't work with e-mail address + */ +function rcube_idn_to_ascii($str) +{ + return rcube_idn_convert($str, true); +} + +/* + * Idn_to_ascii wrapper. + * Intl/Idn modules version of this function doesn't work with e-mail address + */ +function rcube_idn_to_utf8($str) +{ + return rcube_idn_convert($str, false); +} + +function rcube_idn_convert($input, $is_utf=false) +{ + if ($at = strpos($input, '@')) { + $user = substr($input, 0, $at); + $domain = substr($input, $at+1); + } + else { + $domain = $input; + } + + $domain = $is_utf ? idn_to_ascii($domain) : idn_to_utf8($domain); + + return $at ? $user . '@' . $domain : $domain; +} + /** * Helper class to turn relative urls into absolute ones diff --git a/program/include/rcmail.php b/program/include/rcmail.php index c2ca51aea..8c80fe20b 100644 --- a/program/include/rcmail.php +++ b/program/include/rcmail.php @@ -699,12 +699,12 @@ class rcmail // Here we need IDNA ASCII // Only rcube_contacts class is using domain names in Unicode - $host = idn_to_ascii($host); + $host = rcube_idn_to_ascii($host); if (strpos($username, '@')) { // lowercase domain name list($local, $domain) = explode('@', $username); $username = $local . '@' . mb_strtolower($domain); - $username = idn_to_ascii($username); + $username = rcube_idn_to_ascii($username); } // user already registered -> overwrite username diff --git a/program/include/rcube_config.php b/program/include/rcube_config.php index 058927dba..81b664a29 100644 --- a/program/include/rcube_config.php +++ b/program/include/rcube_config.php @@ -287,7 +287,7 @@ class rcube_config $domain = rcube_parse_host($this->prop['mail_domain']); if ($encode) - $domain = idn_to_ascii($domain); + $domain = rcube_idn_to_ascii($domain); return $domain; } diff --git a/program/include/rcube_ldap.php b/program/include/rcube_ldap.php index 4fe74e310..5db92201b 100644 --- a/program/include/rcube_ldap.php +++ b/program/include/rcube_ldap.php @@ -138,7 +138,7 @@ class rcube_ldap extends rcube_addressbook foreach ($this->prop['hosts'] as $host) { - $host = idn_to_ascii(rcube_parse_host($host)); + $host = rcube_idn_to_ascii(rcube_parse_host($host)); $this->_debug("C: Connect [$host".($this->prop['port'] ? ':'.$this->prop['port'] : '')."]"); if ($lc = @ldap_connect($host, $this->prop['port'])) diff --git a/program/include/rcube_shared.inc b/program/include/rcube_shared.inc index 83eefd6da..2aa110092 100644 --- a/program/include/rcube_shared.inc +++ b/program/include/rcube_shared.inc @@ -719,7 +719,7 @@ if (!function_exists('idn_to_utf8')) $loaded = true; } - if ($idn && $domain && preg_match('/(^|@|\.)xn--/i', $domain)) { + if ($idn && $domain && preg_match('/(^|\.)xn--/i', $domain)) { try { $domain = $idn->decode($domain); } diff --git a/program/include/rcube_smtp.php b/program/include/rcube_smtp.php index 3eaf052f1..654c7ef86 100644 --- a/program/include/rcube_smtp.php +++ b/program/include/rcube_smtp.php @@ -101,7 +101,7 @@ class rcube_smtp $helo_host = 'localhost'; // IDNA Support - $smtp_host = idn_to_ascii($smtp_host); + $smtp_host = rcube_idn_to_ascii($smtp_host); $this->conn = new Net_SMTP($smtp_host, $smtp_port, $helo_host); @@ -132,8 +132,9 @@ class rcube_smtp if ($smtp_user && $smtp_pass) { // IDNA Support - if (strpos($smtp_user, '@')) - $smtp_user = idn_to_ascii($smtp_user); + if (strpos($smtp_user, '@')) { + $smtp_user = rcube_idn_to_ascii($smtp_user); + } $result = $this->conn->auth($smtp_user, $smtp_pass, $smtp_auth_type, $use_tls, $smtp_authz); diff --git a/program/include/rcube_template.php b/program/include/rcube_template.php index 1d1a95b90..2102aaa1f 100755 --- a/program/include/rcube_template.php +++ b/program/include/rcube_template.php @@ -1034,7 +1034,7 @@ class rcube_template extends rcube_html_page $username = $this->app->user->get_username(); } - return idn_to_utf8($username); + return rcube_idn_to_utf8($username); } |