|
35 | 35 | use Horde_Imap_Client_Socket;
|
36 | 36 | use Horde_Mime_Exception;
|
37 | 37 | use Horde_Mime_Headers;
|
| 38 | +use Horde_Mime_Headers_ContentParam_ContentType; |
| 39 | +use Horde_Mime_Headers_ContentTransferEncoding; |
38 | 40 | use Horde_Mime_Part;
|
39 | 41 | use Html2Text\Html2Text;
|
40 | 42 | use OCA\Mail\Attachment;
|
@@ -943,6 +945,34 @@ public function getBodyStructureData(Horde_Imap_Client_Socket $client,
|
943 | 945 | return new MessageStructureData($hasAttachments, $text, $isImipMessage, $isEncrypted);
|
944 | 946 | }
|
945 | 947 |
|
| 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 | + |
946 | 976 |
|
947 | 977 | $htmlBody = ($htmlBodyId !== null) ? $part->getBodyPart($htmlBodyId) : null;
|
948 | 978 | if (!empty($htmlBody)) {
|
|
0 commit comments