From 5f9db6489a69ca0fd7efa188522adea209b1ea33 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Mon, 13 Apr 2020 10:57:41 +0300 Subject: [PATCH] mail parsing attachment fix: fetch binary content --- .../Espo/Core/Mail/Parsers/MailMimeParser.php | 41 ++----------------- 1 file changed, 4 insertions(+), 37 deletions(-) diff --git a/application/Espo/Core/Mail/Parsers/MailMimeParser.php b/application/Espo/Core/Mail/Parsers/MailMimeParser.php index 056b19d339..122c0a3b77 100644 --- a/application/Espo/Core/Mail/Parsers/MailMimeParser.php +++ b/application/Espo/Core/Mail/Parsers/MailMimeParser.php @@ -198,8 +198,6 @@ class MailMimeParser foreach ($attachmentObjList as $attachmentObj) { $attachment = $this->getEntityManager()->getEntity('Attachment'); - $content = $attachmentObj->getContent(); - $disposition = $attachmentObj->getHeaderValue('Content-Disposition'); $attachment = $this->getEntityManager()->getEntity('Attachment'); @@ -213,17 +211,10 @@ class MailMimeParser $attachment->set('name', $filename); $attachment->set('type', $contentType); - $charset = $attachmentObj->getHeaderParameter('Content-Type', 'charset'); - - if (!$charset && $content && in_array($contentType, ['text/plain', 'text/html'])) { - $binaryContentStream = $attachmentObj->getBinaryContentStream(); - if ($binaryContentStream) { - $rawContent = $binaryContentStream->getContents(); - $encoding = $this->detectEncodingByBom($rawContent); - if ($encoding) { - $content = $rawContent; - } - } + $content = ''; + $binaryContentStream = $attachmentObj->getBinaryContentStream(); + if ($binaryContentStream) { + $content = $binaryContentStream->getContents(); } $contentId = $attachmentObj->getHeaderValue('Content-ID'); @@ -271,28 +262,4 @@ class MailMimeParser $email->set('body', $body); } } - - protected function detectEncodingByBom(string $contents) : ?string - { - $first2 = substr($contents, 0, 2); - $first3 = substr($contents, 0, 3); - $first4 = substr($contents, 0, 4); - - if ($first3 == chr(0xEF) . chr(0xBB) . chr(0xBF)) - return 'UTF-8'; - else - if ($first4 == chr(0x00) . chr(0x00) . chr(0xFE) . chr(0xFF)) - return 'UTF-32BE'; - else - if ($first4 == chr(0xFF) . chr(0xFE) . chr(0x00) . chr(0x00)) - return 'UTF-32LE'; - else - if ($first2 == chr(0xFE) . chr(0xFF)) - return 'UTF-16BE'; - else - if ($first2 == chr(0xFF) . chr(0xFE)) - return 'UTF-16LE'; - - return null; - } }