diff --git a/application/Espo/Entities/Email.php b/application/Espo/Entities/Email.php
index e46d3f7085..7a2e4beed4 100644
--- a/application/Espo/Entities/Email.php
+++ b/application/Espo/Entities/Email.php
@@ -84,7 +84,33 @@ class Email extends \Espo\Core\ORM\Entity
$breaks = array("
","
","
","
","<br />","<br/>","<br>");
$body = str_ireplace($breaks, "\r\n", $body);
$body = strip_tags($body);
- $body = str_ireplace(' ', ' ', $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;
}
diff --git a/tests/unit/Espo/Entities/EmailTest.php b/tests/unit/Espo/Entities/EmailTest.php
index 3440b8e351..3abb6db1dc 100644
--- a/tests/unit/Espo/Entities/EmailTest.php
+++ b/tests/unit/Espo/Entities/EmailTest.php
@@ -467,8 +467,8 @@ class EmailTest extends \PHPUnit\Framework\TestCase
function testBodyPlain()
{
- $this->email->set('body', '
');
+ $this->email->set('body', '
&');
$bodyPlain = $this->email->getBodyPlain();
- $this->assertEquals($bodyPlain, "\r\n ");
+ $this->assertEquals($bodyPlain, "\r\n &");
}
}