diff --git a/lib/IMAP/MessageMapper.php b/lib/IMAP/MessageMapper.php index 27e88b7178..6e5d610f3e 100644 --- a/lib/IMAP/MessageMapper.php +++ b/lib/IMAP/MessageMapper.php @@ -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())); }