email body plain fix

This commit is contained in:
yuri
2018-04-10 11:35:45 +03:00
parent 38b9f1d68c
commit 66e4b89d1a
2 changed files with 29 additions and 3 deletions

View File

@@ -84,7 +84,33 @@ class Email extends \Espo\Core\ORM\Entity
$breaks = array("<br />","<br>","<br/>","<br />","&lt;br /&gt;","&lt;br/&gt;","&lt;br&gt;");
$body = str_ireplace($breaks, "\r\n", $body);
$body = strip_tags($body);
$body = str_ireplace('&nbsp;', ' ', $body);
$reList = [
'/&(quot|#34);/i',
'/&(amp|#38);/i',
'/&(lt|#60);/i',
'/&(gt|#62);/i',
'/&(nbsp|#160);/i',
'/&(iexcl|#161);/i',
'/&(cent|#162);/i',
'/&(pound|#163);/i',
'/&(copy|#169);/i',
'/&(reg|#174);/i'
];
$replaceList = [
'',
'&',
'<',
'>',
' ',
chr(161),
chr(162),
chr(163),
chr(169),
chr(174)
];
$body = preg_replace($reList, $replaceList, $body);
return $body;
}

View File

@@ -467,8 +467,8 @@ class EmailTest extends \PHPUnit\Framework\TestCase
function testBodyPlain()
{
$this->email->set('body', '<br />&nbsp;');
$this->email->set('body', '<br />&nbsp;&amp;');
$bodyPlain = $this->email->getBodyPlain();
$this->assertEquals($bodyPlain, "\r\n ");
$this->assertEquals($bodyPlain, "\r\n &");
}
}