diff --git a/htdocs/emailcollector/class/emailcollector.class.php b/htdocs/emailcollector/class/emailcollector.class.php index 0844cff2057..5b7d394dce0 100644 --- a/htdocs/emailcollector/class/emailcollector.class.php +++ b/htdocs/emailcollector/class/emailcollector.class.php @@ -2013,6 +2013,9 @@ class EmailCollector extends CommonObject // TEXT if ($p->type == 0 && $data) { + if(!empty($params['charset'])) { + $data = $this->convertStringEncoding($data, $params['charset']); + } // Messages may be split in different parts because of inline attachments, // so append parts together with blank row. if (strtolower($p->subtype) == 'plain') @@ -2028,6 +2031,9 @@ class EmailCollector extends CommonObject // There are no PHP functions to parse embedded messages, // so this just appends the raw source to the main message. elseif ($p->type == 2 && $data) { + if(!empty($params['charset'])) { + $data = $this->convertStringEncoding($data, $params['charset']); + } $plainmsg .= $data."\n\n"; } @@ -2039,4 +2045,18 @@ class EmailCollector extends CommonObject } } } + + protected function convertStringEncoding($string, $fromEncoding, $toEncoding='UTF-8') { + if(!$string || $fromEncoding == $toEncoding) { + return $string; + } + $convertedString = function_exists('iconv') ? @iconv($fromEncoding, $toEncoding . '//IGNORE', $string) : null; + if(!$convertedString && extension_loaded('mbstring')) { + $convertedString = @mb_convert_encoding($string, $toEncoding, $fromEncoding); + } + if(!$convertedString) { + throw new Exception('Mime string encoding conversion failed'); + } + return $convertedString; + } }