Skip to content

Commit

Permalink
improve message preview
Browse files Browse the repository at this point in the history
Signed-off-by: hamza221 <hamzamahjoubi221@gmail.com>
  • Loading branch information
hamza221 committed Mar 17, 2023
1 parent 04f1842 commit 74c1d9c
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions lib/IMAP/MessageMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -888,38 +888,39 @@ public function getBodyStructureData(Horde_Imap_Client_Socket $client,
if ($part === null) {
return new MessageStructureData($hasAttachments, $text, $isImipMessage, $isEncrypted);
}
$htmlBody = ($htmlBodyId !== null) ? $part->getBodyPart($htmlBodyId) : null;
if (!empty($htmlBody)) {
$mimeHeaders = $part->getMimeHeader($htmlBodyId, Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
$textBody = $part->getBodyPart($textBodyId);
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();
}
$html = new Html2Text($htmlBody);
return new MessageStructureData(
$hasAttachments,
trim($html->getText()),
$textBody,
$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();
}
// 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,
$textBody,
trim($html->getText()),
$isImipMessage,
$isEncrypted,
);
}

return new MessageStructureData($hasAttachments, $text, $isImipMessage, $isEncrypted);
}, iterator_to_array($structures->getIterator()));
}
Expand Down

0 comments on commit 74c1d9c

Please sign in to comment.