diff options
author | alecpl <alec@alec.pl> | 2010-09-29 12:36:28 +0000 |
---|---|---|
committer | alecpl <alec@alec.pl> | 2010-09-29 12:36:28 +0000 |
commit | e99991996dbb9e7b0b0ff6cfa94dc0fb2522eb66 (patch) | |
tree | 8031feaef48d8d30de1253318993f8c0a2223674 /program/include/rcube_shared.inc | |
parent | d7f9eb573b82ca55c521b68f7cf3ad8de55ab8ba (diff) |
- Add Internationalized Domain Name (IDNA) support (#1483894)
Diffstat (limited to 'program/include/rcube_shared.inc')
-rw-r--r-- | program/include/rcube_shared.inc | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/program/include/rcube_shared.inc b/program/include/rcube_shared.inc index 575a28ae0..fb4a959f6 100644 --- a/program/include/rcube_shared.inc +++ b/program/include/rcube_shared.inc @@ -680,3 +680,51 @@ if (!extension_loaded('mbstring')) } } +/** + * intl replacement functions + */ + +if (!function_exists('idn_to_utf8')) +{ + function idn_to_utf8($domain, $flags=null) + { + static $idn, $loaded; + + if (!$loaded) { + $idn = new Net_IDNA2(); + $loaded = true; + } + + if ($idn && $domain && preg_match('/(^|@|\.)xn--/i', $domain)) { + try { + $domain = $idn->decode($domain); + } + catch (Exception $e) { + } + } + return $domain; + } +} + +if (!function_exists('idn_to_ascii')) +{ + function idn_to_ascii($domain, $flags=null) + { + static $idn, $loaded; + + if (!$loaded) { + $idn = new Net_IDNA2(); + $loaded = true; + } + + if ($idn && $domain && preg_match('/[^\x20-\x7E]/', $domain)) { + try { + $domain = $idn->encode($domain); + } + catch (Exception $e) { + } + } + return $domain; + } +} + |