Skip to content

Commit

Permalink
Merge pull request #8760 from nextcloud/fix/preview-text
Browse files Browse the repository at this point in the history
Fix preview text
  • Loading branch information
hamza221 authored Aug 18, 2023
2 parents 71a082d + 8e0a970 commit b5c7aa5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 30 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
26 changes: 11 additions & 15 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 15 additions & 14 deletions lib/IMAP/MessageMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down

0 comments on commit b5c7aa5

Please sign in to comment.