From 8e0a970c322ea44fbad901d94dbf9e52294c42b9 Mon Sep 17 00:00:00 2001 From: hamza221 Date: Wed, 16 Aug 2023 14:36:48 +0200 Subject: [PATCH] Fix preview text Signed-off-by: hamza221 --- composer.json | 2 +- composer.lock | 26 +++++++++++--------------- lib/IMAP/MessageMapper.php | 29 +++++++++++++++-------------- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/composer.json b/composer.json index 8de65ba98e..ca9f5e8410 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "christophwurst/kitinerary-sys": "^0.2.1", "ezyang/htmlpurifier": "4.16.0", "gravatarphp/gravatar": "dev-master#6b9f6a45477ce48285738d9d0c3f0dbf97abe263", - "html2text/html2text": "^4.3.1", + "hamza221/html2text": "^1.0", "nextcloud/horde-managesieve": "^1.0", "nextcloud/horde-smtp": "^1.0.2", "phpmailer/dkimvalidator": "^0.3.0", diff --git a/composer.lock b/composer.lock index 387e2e79f7..84ab34fd9e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "db63d1a1c3d4c47b0e5f997c51520b55", + "content-hash": "379457e9febd4200b4472c3aafaae0cf", "packages": [ { "name": "amphp/amp", @@ -1951,21 +1951,21 @@ "time": "2021-12-01T16:22:57+00:00" }, { - "name": "html2text/html2text", - "version": "4.3.1", + "name": "hamza221/html2text", + "version": "v1.0.0", "source": { "type": "git", - "url": "https://github.com/mtibben/html2text.git", - "reference": "61ad68e934066a6f8df29a3d23a6460536d0855c" + "url": "https://github.com/hamza221/html2text.git", + "reference": "77498a184e4bd59698a8daf458addd6d94c8dbf5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/mtibben/html2text/zipball/61ad68e934066a6f8df29a3d23a6460536d0855c", - "reference": "61ad68e934066a6f8df29a3d23a6460536d0855c", + "url": "https://api.github.com/repos/hamza221/html2text/zipball/77498a184e4bd59698a8daf458addd6d94c8dbf5", + "reference": "77498a184e4bd59698a8daf458addd6d94c8dbf5", "shasum": "" }, "require-dev": { - "phpunit/phpunit": "~4" + "phpunit/phpunit": "~4|^9.0" }, "suggest": { "ext-mbstring": "For best performance", @@ -1974,10 +1974,7 @@ "type": "library", "autoload": { "psr-4": { - "Html2Text\\": [ - "src/", - "test/" - ] + "Html2Text\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -1986,10 +1983,9 @@ ], "description": "Converts HTML to formatted plain text", "support": { - "issues": "https://github.com/mtibben/html2text/issues", - "source": "https://github.com/mtibben/html2text/tree/4.3.1" + "source": "https://github.com/hamza221/html2text/tree/v1.0.0" }, - "time": "2020-04-16T23:44:31+00:00" + "time": "2023-08-16T11:30:50+00:00" }, { "name": "nextcloud/horde-managesieve", diff --git a/lib/IMAP/MessageMapper.php b/lib/IMAP/MessageMapper.php index 02529f3228..fa60347578 100644 --- a/lib/IMAP/MessageMapper.php +++ b/lib/IMAP/MessageMapper.php @@ -928,35 +928,36 @@ public function getBodyStructureData(Horde_Imap_Client_Socket $client, if ($part === null) { return new MessageStructureData($hasAttachments, $text, $isImipMessage, $isEncrypted); } - $textBody = $part->getBodyPart($textBodyId); - if (!empty($textBody)) { - $mimeHeaders = $part->getMimeHeader($textBodyId, Horde_Imap_Client_Data_Fetch::HEADER_PARSE); + + + $htmlBody = ($htmlBodyId !== null) ? $part->getBodyPart($htmlBodyId) : null; + if (!empty($htmlBody)) { + $mimeHeaders = $part->getMimeHeader($htmlBodyId, Horde_Imap_Client_Data_Fetch::HEADER_PARSE); if ($enc = $mimeHeaders->getValue('content-transfer-encoding')) { $structure->setTransferEncoding($enc); - $structure->setContents($textBody); - $textBody = $structure->getContents(); + $structure->setContents($htmlBody); + $htmlBody = $structure->getContents(); } + $html = new Html2Text($htmlBody, array('do_links' => 'none','alt_image' => 'hide')); return new MessageStructureData( $hasAttachments, - $textBody, + trim($html->getText()), $isImipMessage, $isEncrypted, ); } + $textBody = $part->getBodyPart($textBodyId); - $htmlBody = ($htmlBodyId !== null) ? $part->getBodyPart($htmlBodyId) : null; - if (!empty($htmlBody)) { - $mimeHeaders = $part->getMimeHeader($htmlBodyId, Horde_Imap_Client_Data_Fetch::HEADER_PARSE); + if (!empty($textBody)) { + $mimeHeaders = $part->getMimeHeader($textBodyId, Horde_Imap_Client_Data_Fetch::HEADER_PARSE); if ($enc = $mimeHeaders->getValue('content-transfer-encoding')) { $structure->setTransferEncoding($enc); - $structure->setContents($htmlBody); - $htmlBody = $structure->getContents(); + $structure->setContents($textBody); + $textBody = $structure->getContents(); } - // TODO: add 'alt_image' => 'hide' once it's added to the Html2Text package - $html = new Html2Text($htmlBody, array('do_links' => 'none',)); return new MessageStructureData( $hasAttachments, - trim($html->getText()), + $textBody, $isImipMessage, $isEncrypted, );