diff --git a/felamimail/inc/class.uicompose.inc.php b/felamimail/inc/class.uicompose.inc.php index fa691b3d84..8e8d78f95a 100644 --- a/felamimail/inc/class.uicompose.inc.php +++ b/felamimail/inc/class.uicompose.inc.php @@ -849,9 +849,19 @@ //if (json_last_error() != JSON_ERROR_NONE && strlen($singleBodyPart['body'])>0) if ($test=="null" && strlen($sessionData['body'])>0) { - // this should not be needed, unless something fails with charset detection/ wrong charset passed - error_log(__METHOD__.__LINE__.' Charset problem detected; Charset Detected:'.felamimail_bo::detect_encoding($sessionData['body'])); - $sessionData['body'] = utf8_encode($sessionData['body']); + // try to fix broken utf8 + $x = (function_exists('mb_convert_encoding')?mb_convert_encoding($sessionData['body'],'UTF-8','UTF-8'):(function_exists('iconv')?@iconv("UTF-8","UTF-8//IGNORE",$sessionData['body']):$sessionData['body'])); + $test = @json_encode($x); + if ($test=="null" && strlen($sessionData['body'])>0) + { + // this should not be needed, unless something fails with charset detection/ wrong charset passed + error_log(__METHOD__.__LINE__.' Charset problem detected; Charset Detected:'.felamimail_bo::detect_encoding($sessionData['body'])); + $sessionData['body'] = utf8_encode($sessionData['body']); + } + else + { + $sessionData['body'] = $x; + } } } //error_log(__METHOD__.__LINE__.$sessionData['body']); diff --git a/felamimail/inc/class.uidisplay.inc.php b/felamimail/inc/class.uidisplay.inc.php index c7ee10a2ab..e97c7bd7a5 100644 --- a/felamimail/inc/class.uidisplay.inc.php +++ b/felamimail/inc/class.uidisplay.inc.php @@ -1525,9 +1525,19 @@ blockquote[type=cite] { //if (json_last_error() != JSON_ERROR_NONE && strlen($singleBodyPart['body'])>0) if (($test=="null" || $test === false || is_null($test)) && strlen($singleBodyPart['body'])>0) { - // this should not be needed, unless something fails with charset detection/ wrong charset passed - error_log(__METHOD__.__LINE__.' Charset Reported:'.$singleBodyPart['charSet'].' Charset Detected:'.felamimail_bo::detect_encoding($singleBodyPart['body'])); - $singleBodyPart['body'] = utf8_encode($singleBodyPart['body']); + // try to fix broken utf8 + $x = (function_exists('mb_convert_encoding')?mb_convert_encoding($singleBodyPart['body'],'UTF-8','UTF-8'):(function_exists('iconv')?@iconv("UTF-8","UTF-8//IGNORE",$singleBodyPart['body']):$singleBodyPart['body'])); + $test = @json_encode($x); + if (($test=="null" || $test === false || is_null($test)) && strlen($singleBodyPart['body'])>0) + { + // this should not be needed, unless something fails with charset detection/ wrong charset passed + error_log(__METHOD__.__LINE__.' Charset Reported:'.$singleBodyPart['charSet'].' Charset Detected:'.felamimail_bo::detect_encoding($singleBodyPart['body'])); + $singleBodyPart['body'] = utf8_encode($singleBodyPart['body']); + } + else + { + $singleBodyPart['body'] = $x; + } } } //error_log($singleBodyPart['body']);