Skip to content

Commit f0cc21d

Browse files
st3inybackportbot[bot]
authored andcommitted
fix: decoding preview texts
Respect the content type charset when decoding bodies to use when generating preview texts. Signed-off-by: Richard Steinmetz <[email protected]> [skip ci]
1 parent 6aaf571 commit f0cc21d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

lib/IMAP/MessageMapper.php

+30
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
use Horde_Imap_Client_Socket;
3636
use Horde_Mime_Exception;
3737
use Horde_Mime_Headers;
38+
use Horde_Mime_Headers_ContentParam_ContentType;
39+
use Horde_Mime_Headers_ContentTransferEncoding;
3840
use Horde_Mime_Part;
3941
use Html2Text\Html2Text;
4042
use OCA\Mail\Attachment;
@@ -943,6 +945,34 @@ public function getBodyStructureData(Horde_Imap_Client_Socket $client,
943945
return new MessageStructureData($hasAttachments, $text, $isImipMessage, $isEncrypted);
944946
}
945947

948+
// Convert a given binary body to utf-8 according to the transfer encoding and content
949+
// type headers of the underlying MIME part
950+
$convertBody = function (string $body, Horde_Mime_Headers $mimeHeaders) use ($structure): string {
951+
/** @var Horde_Mime_Headers_ContentParam_ContentType $contentType */
952+
$contentType = $mimeHeaders->getHeader('content-type');
953+
/** @var Horde_Mime_Headers_ContentTransferEncoding $transferEncoding */
954+
$transferEncoding = $mimeHeaders->getHeader('content-transfer-encoding');
955+
956+
if (!$contentType && !$transferEncoding) {
957+
// Nothing to convert here ...
958+
return $body;
959+
}
960+
961+
if ($transferEncoding) {
962+
$structure->setTransferEncoding($transferEncoding->value_single);
963+
}
964+
965+
if ($contentType) {
966+
$structure->setType($contentType->value_single);
967+
if (isset($contentType['charset'])) {
968+
$structure->setCharset($contentType['charset']);
969+
}
970+
}
971+
972+
$structure->setContents($body);
973+
return $this->converter->convert($structure);
974+
};
975+
946976

947977
$htmlBody = ($htmlBodyId !== null) ? $part->getBodyPart($htmlBodyId) : null;
948978
if (!empty($htmlBody)) {

0 commit comments

Comments
 (0)