email note strip reply part
This commit is contained in:
@@ -207,6 +207,20 @@ class Email extends Entity
|
||||
return $this->hasInContainer('bodyPlain') && $this->getFromContainer('bodyPlain');
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 9.0.0
|
||||
*/
|
||||
public function getBodyPlainWithReplyPart(): ?string
|
||||
{
|
||||
$body = $this->getBodyPlain();
|
||||
|
||||
if (!$body) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return EmailUtil::stripBodyPlainQuotePart($body) ?: null;
|
||||
}
|
||||
|
||||
public function getBodyPlain(): ?string
|
||||
{
|
||||
if ($this->getFromContainer('bodyPlain')) {
|
||||
|
||||
@@ -63,4 +63,35 @@ class Util
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
static public function stripBodyPlainQuotePart(string $body): string
|
||||
{
|
||||
if (!$body) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$lines = preg_split("/\r\n|\n|\r/", $body);
|
||||
|
||||
if (!is_array($lines)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$endIndex = count($lines) - 1;
|
||||
|
||||
for ($i = count($lines) - 1; $i >= 0; $i--) {
|
||||
$line = $lines[$i];
|
||||
|
||||
if (str_starts_with($line, '>')) {
|
||||
$endIndex = $i;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$lines = array_slice($lines, 0, $endIndex);
|
||||
|
||||
return implode("\r\n", $lines);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -506,7 +506,7 @@ class Service
|
||||
$withContent = $this->toStoreEmailContent($entityType);
|
||||
|
||||
if ($withContent) {
|
||||
$note->setPost($email->getBodyPlain());
|
||||
$note->setPost($email->getBodyPlainWithReplyPart());
|
||||
$data['attachmentsIds'] = $email->getAttachmentIdList();
|
||||
}
|
||||
|
||||
@@ -563,7 +563,7 @@ class Service
|
||||
$withContent = $this->toStoreEmailContent($entityType);
|
||||
|
||||
if ($withContent) {
|
||||
$note->setPost($email->getBodyPlain());
|
||||
$note->setPost($email->getBodyPlainWithReplyPart());
|
||||
$data['attachmentsIds'] = $email->getAttachmentIdList();
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
namespace tests\unit\Espo\Entities;
|
||||
|
||||
use Espo\Entities\Email;
|
||||
use Espo\Tools\Email\Util;
|
||||
|
||||
class EmailTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
@@ -475,13 +476,24 @@ class EmailTest extends \PHPUnit\Framework\TestCase
|
||||
$this->assertEquals('test <img src="cid:Id01">', $body);
|
||||
}
|
||||
|
||||
function testBodyPlain()
|
||||
public function testBodyPlain(): void
|
||||
{
|
||||
$this->email->set('body', '<br /> &');
|
||||
$bodyPlain = $this->email->getBodyPlain();
|
||||
$this->assertEquals("\r\n &", $bodyPlain);
|
||||
}
|
||||
|
||||
public function testBodyPlainWithoutQuotePart(): void
|
||||
{
|
||||
$body = "Test\nHello\n> Test\n> Test\r\n>> Test";
|
||||
|
||||
$this->email->set('bodyPlain', $body);
|
||||
|
||||
$expected = "Test\r\nHello";
|
||||
|
||||
$this->assertEquals($expected, $this->email->getBodyPlainWithReplyPart());
|
||||
}
|
||||
|
||||
public function testSubjectBody(): void
|
||||
{
|
||||
$email = $this->email;
|
||||
|
||||
Reference in New Issue
Block a user