summaryrefslogtreecommitdiff
path: root/program/include/main.inc
diff options
context:
space:
mode:
authoralecpl <alec@alec.pl>2011-02-03 13:58:07 +0000
committeralecpl <alec@alec.pl>2011-02-03 13:58:07 +0000
commite8d5bdc84ecfdf6fe5008655215a258bbdf0c521 (patch)
tree24e98fca92b72bcc0ba4b5519f5d2c9265a7c8d5 /program/include/main.inc
parent9ebac6616d32d7672ea59da67321380037e2324c (diff)
- Fix IDNA support when IDN/INTL modules are in use (#1487742)
Diffstat (limited to 'program/include/main.inc')
-rw-r--r--program/include/main.inc33
1 files changed, 33 insertions, 0 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