From 625c579c82a06f2afaa21e130a4fd9f6c99c20ed Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Thu, 5 Dec 2024 08:23:09 +0100 Subject: [PATCH] fix(imap): Consider charset for preview text decoding Signed-off-by: Christoph Wurst --- lib/IMAP/MessageMapper.php | 12 ++++++++---- tests/Unit/IMAP/MessageMapperTest.php | 5 +++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/IMAP/MessageMapper.php b/lib/IMAP/MessageMapper.php index f076d6f4f4..f61279ef74 100644 --- a/lib/IMAP/MessageMapper.php +++ b/lib/IMAP/MessageMapper.php @@ -25,6 +25,7 @@ use OCA\Mail\Attachment; use OCA\Mail\Db\Mailbox; use OCA\Mail\Exception\ServiceException; +use OCA\Mail\IMAP\Charset\Converter; use OCA\Mail\Model\IMAPMessage; use OCA\Mail\Service\SmimeService; use OCA\Mail\Support\PerformanceLoggerTask; @@ -50,9 +51,12 @@ class MessageMapper { private SMimeService $smimeService; private ImapMessageFetcherFactory $imapMessageFactory; - public function __construct(LoggerInterface $logger, + public function __construct( + LoggerInterface $logger, SmimeService $smimeService, - ImapMessageFetcherFactory $imapMessageFactory, ) { + ImapMessageFetcherFactory $imapMessageFactory, + private Converter $converter, + ) { $this->logger = $logger; $this->smimeService = $smimeService; $this->imapMessageFactory = $imapMessageFactory; @@ -937,7 +941,7 @@ public function getBodyStructureData(Horde_Imap_Client_Socket $client, if ($enc = $mimeHeaders->getValue('content-transfer-encoding')) { $structure->setTransferEncoding($enc); $structure->setContents($htmlBody); - $htmlBody = $structure->getContents(); + $htmlBody = $this->converter->convert($structure); } $mentionsUser = $this->checkLinks($htmlBody, $emailAddress); $html = new Html2Text($htmlBody, ['do_links' => 'none','alt_image' => 'hide']); @@ -956,7 +960,7 @@ public function getBodyStructureData(Horde_Imap_Client_Socket $client, if ($enc = $mimeHeaders->getValue('content-transfer-encoding')) { $structure->setTransferEncoding($enc); $structure->setContents($textBody); - $textBody = $structure->getContents(); + $textBody = $this->converter->convert($structure); } return new MessageStructureData( $hasAttachments, diff --git a/tests/Unit/IMAP/MessageMapperTest.php b/tests/Unit/IMAP/MessageMapperTest.php index bf8b7656b9..39bb179d3b 100644 --- a/tests/Unit/IMAP/MessageMapperTest.php +++ b/tests/Unit/IMAP/MessageMapperTest.php @@ -17,6 +17,7 @@ use Horde_Imap_Client_Ids; use Horde_Imap_Client_Socket; use OCA\Mail\Db\Mailbox; +use OCA\Mail\IMAP\Charset\Converter; use OCA\Mail\IMAP\ImapMessageFetcher; use OCA\Mail\IMAP\ImapMessageFetcherFactory; use OCA\Mail\IMAP\MessageMapper; @@ -40,17 +41,21 @@ class MessageMapperTest extends TestCase { /** @var ImapMessageFetcherFactory|MockObject */ private $imapMessageFactory; + private Converter|MockObject $converter; + protected function setUp(): void { parent::setUp(); $this->logger = $this->createMock(LoggerInterface::class); $this->sMimeService = $this->createMock(SmimeService::class); $this->imapMessageFactory = $this->createMock(ImapMessageFetcherFactory::class); + $this->converter = $this->createMock(Converter::class); $this->mapper = new MessageMapper( $this->logger, $this->sMimeService, $this->imapMessageFactory, + $this->converter, ); }