From 13c0396d4ac62bf64fab1fb889b204a1fc4903ad Mon Sep 17 00:00:00 2001 From: Klaus Leithoff Date: Tue, 19 Aug 2014 12:51:56 +0000 Subject: [PATCH] fix problem with wrong encoded header information; we rely on UTF8, if data are not provided accordingly, our json calls fail --- .../inc/class.emailadmin_imapbase.inc.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/emailadmin/inc/class.emailadmin_imapbase.inc.php b/emailadmin/inc/class.emailadmin_imapbase.inc.php index d654118cbd..b7c9ab419c 100644 --- a/emailadmin/inc/class.emailadmin_imapbase.inc.php +++ b/emailadmin/inc/class.emailadmin_imapbase.inc.php @@ -1986,6 +1986,24 @@ class emailadmin_imapbase else { $_string = translation::decodeMailHeader($_string,self::$displayCharset); + $test = @json_encode($_string); + //error_log(__METHOD__.__LINE__.' ->'.strlen($singleBodyPart['body']).' Error:'.json_last_error().'<- BodyPart:#'.$test.'#'); + if (($test=="null" || $test === false || is_null($test)) && strlen($_string)>0) + { + // try to fix broken utf8 + $x = utf8_encode($_string); + $test = @json_encode($x); + if (($test=="null" || $test === false || is_null($test)) && strlen($_string)>0) + { + // this should not be needed, unless something fails with charset detection/ wrong charset passed + $_string = (function_exists('mb_convert_encoding')?mb_convert_encoding($_string,'UTF-8','UTF-8'):(function_exists('iconv')?@iconv("UTF-8","UTF-8//IGNORE",$_string):$_string)); + } + else + { + $_string = $x; + } + } + if ($_tryIDNConversion===true && stripos($_string,'@')!==false) { $rfcAddr = imap_rfc822_parse_adrlist(str_replace(',','\,',$_string),'');