Skip to content

Commit b5c7aa5

Browse files
authored
Merge pull request #8760 from nextcloud/fix/preview-text
Fix preview text
2 parents 71a082d + 8e0a970 commit b5c7aa5

File tree

3 files changed

+27
-30
lines changed

3 files changed

+27
-30
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"christophwurst/kitinerary-sys": "^0.2.1",
3333
"ezyang/htmlpurifier": "4.16.0",
3434
"gravatarphp/gravatar": "dev-master#6b9f6a45477ce48285738d9d0c3f0dbf97abe263",
35-
"html2text/html2text": "^4.3.1",
35+
"hamza221/html2text": "^1.0",
3636
"nextcloud/horde-managesieve": "^1.0",
3737
"nextcloud/horde-smtp": "^1.0.2",
3838
"phpmailer/dkimvalidator": "^0.3.0",

composer.lock

Lines changed: 11 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/IMAP/MessageMapper.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -928,35 +928,36 @@ public function getBodyStructureData(Horde_Imap_Client_Socket $client,
928928
if ($part === null) {
929929
return new MessageStructureData($hasAttachments, $text, $isImipMessage, $isEncrypted);
930930
}
931-
$textBody = $part->getBodyPart($textBodyId);
932-
if (!empty($textBody)) {
933-
$mimeHeaders = $part->getMimeHeader($textBodyId, Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
931+
932+
933+
$htmlBody = ($htmlBodyId !== null) ? $part->getBodyPart($htmlBodyId) : null;
934+
if (!empty($htmlBody)) {
935+
$mimeHeaders = $part->getMimeHeader($htmlBodyId, Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
934936
if ($enc = $mimeHeaders->getValue('content-transfer-encoding')) {
935937
$structure->setTransferEncoding($enc);
936-
$structure->setContents($textBody);
937-
$textBody = $structure->getContents();
938+
$structure->setContents($htmlBody);
939+
$htmlBody = $structure->getContents();
938940
}
941+
$html = new Html2Text($htmlBody, array('do_links' => 'none','alt_image' => 'hide'));
939942
return new MessageStructureData(
940943
$hasAttachments,
941-
$textBody,
944+
trim($html->getText()),
942945
$isImipMessage,
943946
$isEncrypted,
944947
);
945948
}
949+
$textBody = $part->getBodyPart($textBodyId);
946950

947-
$htmlBody = ($htmlBodyId !== null) ? $part->getBodyPart($htmlBodyId) : null;
948-
if (!empty($htmlBody)) {
949-
$mimeHeaders = $part->getMimeHeader($htmlBodyId, Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
951+
if (!empty($textBody)) {
952+
$mimeHeaders = $part->getMimeHeader($textBodyId, Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
950953
if ($enc = $mimeHeaders->getValue('content-transfer-encoding')) {
951954
$structure->setTransferEncoding($enc);
952-
$structure->setContents($htmlBody);
953-
$htmlBody = $structure->getContents();
955+
$structure->setContents($textBody);
956+
$textBody = $structure->getContents();
954957
}
955-
// TODO: add 'alt_image' => 'hide' once it's added to the Html2Text package
956-
$html = new Html2Text($htmlBody, array('do_links' => 'none',));
957958
return new MessageStructureData(
958959
$hasAttachments,
959-
trim($html->getText()),
960+
$textBody,
960961
$isImipMessage,
961962
$isEncrypted,
962963
);

0 commit comments

Comments
 (0)