From 0cbdb53245ead79b5e2e74fcbd52885a1ba04f96 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Thu, 7 Dec 2023 08:52:35 +0100 Subject: [PATCH] fixup! fix(encoding): better character encoding Signed-off-by: Christoph Wurst --- lib/IMAP/Charset/Converter.php | 1 + lib/IMAP/ImapMessageFetcherFactory.php | 7 ++++++- tests/Unit/IMAP/Charset/ConverterTest.php | 10 ++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/IMAP/Charset/Converter.php b/lib/IMAP/Charset/Converter.php index 7052a11c9c..a1a07acba0 100644 --- a/lib/IMAP/Charset/Converter.php +++ b/lib/IMAP/Charset/Converter.php @@ -36,6 +36,7 @@ class Converter { * @throws ServiceException */ public function convert(Horde_Mime_Part $p): string { + /** @var null|string $data */ $data = $p->getContents(); if ($data === null) { return ''; diff --git a/lib/IMAP/ImapMessageFetcherFactory.php b/lib/IMAP/ImapMessageFetcherFactory.php index e0679c102f..ee1b2d9f48 100644 --- a/lib/IMAP/ImapMessageFetcherFactory.php +++ b/lib/IMAP/ImapMessageFetcherFactory.php @@ -27,17 +27,21 @@ namespace OCA\Mail\IMAP; use Horde_Imap_Client_Base; +use OCA\Mail\IMAP\Charset\Converter; use OCA\Mail\Service\Html; use OCA\Mail\Service\SmimeService; class ImapMessageFetcherFactory { private Html $htmlService; private SmimeService $smimeService; + private Converter $charsetConverter; public function __construct(Html $htmlService, - SmimeService $smimeService) { + SmimeService $smimeService, + Converter $charsetConverter) { $this->htmlService = $htmlService; $this->smimeService = $smimeService; + $this->charsetConverter = $charsetConverter; } public function build(int $uid, @@ -51,6 +55,7 @@ public function build(int $uid, $userId, $this->htmlService, $this->smimeService, + $this->charsetConverter, ); } } diff --git a/tests/Unit/IMAP/Charset/ConverterTest.php b/tests/Unit/IMAP/Charset/ConverterTest.php index 2bf4b0cc44..8a20120bc3 100644 --- a/tests/Unit/IMAP/Charset/ConverterTest.php +++ b/tests/Unit/IMAP/Charset/ConverterTest.php @@ -27,6 +27,8 @@ use ChristophWurst\Nextcloud\Testing\TestCase; use Horde_Mime_Part; use OCA\Mail\IMAP\Charset\Converter; +use function fopen; +use function fwrite; use function mb_convert_encoding; class ConverterTest extends TestCase { @@ -54,6 +56,13 @@ public function dataProviderMimeParts(): array { $utfMimePart->setType('text/plain'); $utfMimePart->setCharset('UTF-8'); $utfMimePart->setContents('😊'); + // UTF8 stream + $utfMimeStreamPart = new Horde_Mime_Part(); + $utfMimeStreamPart->setType('text/plain'); + $utfMimeStreamPart->setCharset('UTF-8'); + $fh = fopen("php://temp", 'r+'); + fwrite($fh, '💦'); + $utfMimeStreamPart->setContents($fh, [ 'usestream' => true, ]); // Hebrew $iso88591MimePart = new Horde_Mime_Part(); $iso88591MimePart->setType('text/plain'); @@ -81,6 +90,7 @@ public function dataProviderMimeParts(): array { return[ [$utfMimePart, '😊'], + [$utfMimeStreamPart, '💦'], [$iso88591MimePart, 'Ümlaut'], [$iso2022jpMimePart, '外せ園査リツハワ題'], [$iso88591MimePart_noCharset, 'בה בדף לחבר ממונרכיה, בקר בגרסה ואמנות דת'],