From b46e5b7407940499964d8a553c3eada05850f29d Mon Sep 17 00:00:00 2001 From: thomascube Date: Wed, 9 Feb 2011 10:51:50 +0000 Subject: Apply more bugfixes from trunk for 0.5.1 --- program/include/main.inc | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'program/include/main.inc') diff --git a/program/include/main.inc b/program/include/main.inc index b8d27d68c..f9cc4331b 100644 --- a/program/include/main.inc +++ b/program/include/main.inc @@ -1223,6 +1223,19 @@ function rcmail_remote_ip() } +/** + * Check whether the HTTP referer matches the current request + * + * @return boolean True if referer is the same host+path, false if not + */ +function rcube_check_referer() +{ + $uri = parse_url($_SERVER['REQUEST_URI']); + $referer = parse_url(rc_request_header('Referer')); + return $referer['host'] == rc_request_header('Host') && $referer['path'] == $uri['path']; +} + + /** * @access private * @return mixed @@ -1863,6 +1876,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 -- cgit v1.2.3