diff --git a/application/Espo/Entities/Email.php b/application/Espo/Entities/Email.php
index 3e222338ec..2a4b7575f4 100644
--- a/application/Espo/Entities/Email.php
+++ b/application/Espo/Entities/Email.php
@@ -46,6 +46,21 @@ class Email extends \Espo\Core\ORM\Entity
}
}
+ public function getBodyPlain()
+ {
+ $bodyPlain = $this->get('bodyPlain');
+ if (!empty($bodyPlain)) {
+ return $bodyPlain;
+ }
+
+ $body = $this->get('body');
+
+ $breaks = array("
","
","
","
","<br />","<br/>","<br>");
+ $body = str_ireplace($breaks, "\r\n", $body);
+ $body = strip_tags($body);
+ return $body;
+ }
+
public function getBodyPlainForSending()
{
$bodyPlain = $this->get('bodyPlain');
diff --git a/application/Espo/Modules/Crm/Services/InboundEmail.php b/application/Espo/Modules/Crm/Services/InboundEmail.php
index 30d8189166..aaff5f7473 100644
--- a/application/Espo/Modules/Crm/Services/InboundEmail.php
+++ b/application/Espo/Modules/Crm/Services/InboundEmail.php
@@ -262,6 +262,7 @@ class InboundEmail extends \Espo\Services\Record
'userId' => $inboundEmail->get('assignToUserId'),
);
$case = $this->emailToCase($email, $params);
+ $this->getServiceFactory()->create('Stream')->noteEmailReceived($case, $email);
$user = $this->getEntityManager()->getEntity('User', $case->get('assignedUserId'));
if ($inboundEmail->get('reply')) {
$this->autoReply($inboundEmail, $email, $case, $user);
diff --git a/application/Espo/Services/Stream.php b/application/Espo/Services/Stream.php
index e034006f0b..1a7ef94ca9 100644
--- a/application/Espo/Services/Stream.php
+++ b/application/Espo/Services/Stream.php
@@ -272,6 +272,10 @@ class Stream extends \Espo\Core\Services\Base
$note->set('type', 'EmailReceived');
$note->set('parentId', $entity->id);
$note->set('parentType', $entityName);
+
+ $bodyPlain = $email->getBodyPlain();
+
+ $note->set('post', $email->get)
$data = array();