Skip to content

Commit

Permalink
Merge pull request #70 from asig2016/master_fix_sneak_preview_encoding
Browse files Browse the repository at this point in the history
Mail, fix sneak preview encoding
  • Loading branch information
ralfbecker committed Apr 2, 2019
1 parent 0f184f6 commit a15f944
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion api/src/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -1698,7 +1698,12 @@ function getHeaders($_folderName, $_startMessage, $_numberOfMessages, $_sort, $_
$_structure=$part;
$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=Translation::detect_encoding($headerObject['BODYPREVIEW']);
$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);
Expand Down
3 changes: 2 additions & 1 deletion api/src/Mail/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ static function convertHTMLToText($_html,$displayCharset=false,$stripcrl=false,$
$_html = str_replace('#lower#than#','<',$_html);
$_html = str_replace('#greater#than#','>',$_html);
//error_log(__METHOD__.__LINE__.' Charset:'.$displayCharset.' -> '.$_html);
$_html = html_entity_decode($_html, ENT_COMPAT, $displayCharset);
$_html = Api\Translation::convert($_html, $displayCharset, 'utf-8');
$_html = html_entity_decode($_html, ENT_COMPAT, 'utf-8');
//error_log(__METHOD__.__LINE__.' Charset:'.$displayCharset.' After html_entity_decode: -> '.$_html);
//self::replaceEmailAdresses($_html);
$pos = strpos($_html, 'blockquote');
Expand Down

0 comments on commit a15f944

Please sign in to comment.