From eba66e87266fd3f8627e6fe4760631f7db030a3c Mon Sep 17 00:00:00 2001 From: Alexandros Sigalas Date: Mon, 1 Apr 2019 09:16:32 +0300 Subject: [PATCH] If other charset than utf-8 is wrongly reported, use utf-8 --- api/src/Mail.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/api/src/Mail.php b/api/src/Mail.php index a9df47944a..7affc41a5e 100644 --- a/api/src/Mail.php +++ b/api/src/Mail.php @@ -1699,6 +1699,11 @@ class Mail $this->fetchPartContents($uid, $_structure, false,true); $headerObject['BODYPREVIEW']=trim(str_replace(array("\r\n","\r","\n"),' ',mb_substr(Mail\Html::convertHTMLToText($_structure->getContents()),0,((int)$_fetchPreviews<300?300:$_fetchPreviews)))); $charSet = $part->getCharset(); + // check if client set a wrong charset and content is utf-8 --> use utf-8 + if (strtolower($charSet) !='utf-8' && preg_match('//u', $headerObject['BODYPREVIEW'])) + { + $charSet['charSet'] = 'UTF-8'; + } // add line breaks to $bodyParts //error_log(__METHOD__.' ('.__LINE__.') '.' Charset:'.$bodyParts[$i]['charSet'].'->'.$bodyParts[$i]['body']); $headerObject['BODYPREVIEW'] = Translation::convert_jsonsafe($headerObject['BODYPREVIEW'], $charSet);