From 4c641f2769b4a9fa88e81d3741b20c45b8e85b34 Mon Sep 17 00:00:00 2001 From: Lars Kneschke Date: Wed, 14 Feb 2007 11:44:01 +0000 Subject: [PATCH] iconv can not convert from/to utf7-imap. Added support for conversion based on the functions provided by the imap extension. Returning the unconverted string when conversion using iconv failed. This was also not working before. --- phpgwapi/inc/class.translation.inc.php | 35 +++++++++++++++++++------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/phpgwapi/inc/class.translation.inc.php b/phpgwapi/inc/class.translation.inc.php index 0f095d19cd..9b5e745b15 100644 --- a/phpgwapi/inc/class.translation.inc.php +++ b/phpgwapi/inc/class.translation.inc.php @@ -445,15 +445,32 @@ } if(function_exists('iconv')) { - if($from=='EUC-CN') $from='gb18030'; - // the above is to workaround patch #962307 - // if using EUC-CN, for iconv it strickly follow GB2312 and fail - // in an email on the first Traditional/Japanese/Korean character, - // but in reality when people send mails in GB2312, UMA mostly use - // extended GB13000/GB18030 which allow T/Jap/Korean characters. - if (($data = iconv($from,$to,$data))) - { - return $data; + // iconv can not convert from/to utf7-imap + if ($to == 'utf7-imap' && function_exists(imap_utf7_encode)) { + $convertedData = iconv($from, 'iso-8859-1', $ata); + $convertedData = imap_utf7_encode($convertedData); + + return $convertedData; + } + + if ($from == 'utf7-imap' && function_exists(imap_utf7_decode)) { + $convertedData = imap_utf7_decode($data); + $convertedData = iconv('iso-8859-1', $to, $convertedData); + + return $convertedData; + } + + // the following is to workaround patch #962307 + // if using EUC-CN, for iconv it strickly follow GB2312 and fail + // in an email on the first Traditional/Japanese/Korean character, + // but in reality when people send mails in GB2312, UMA mostly use + // extended GB13000/GB18030 which allow T/Jap/Korean characters. + if($from=='EUC-CN') { + $from='gb18030'; + } + + if (($convertedData = iconv($from,$to,$data))) { + return $convertedData; } } #die("

Can't convert from charset '$from' to '$to' without the mbstring extension !!!

");