Skip to content

Commit

Permalink
fix(imap): Consider charset for preview text decoding
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Wurst <[email protected]>
  • Loading branch information
ChristophWurst committed Dec 5, 2024
1 parent 188b041 commit 625c579
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/IMAP/MessageMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use OCA\Mail\Attachment;
use OCA\Mail\Db\Mailbox;
use OCA\Mail\Exception\ServiceException;
use OCA\Mail\IMAP\Charset\Converter;
use OCA\Mail\Model\IMAPMessage;
use OCA\Mail\Service\SmimeService;
use OCA\Mail\Support\PerformanceLoggerTask;
Expand All @@ -50,9 +51,12 @@ class MessageMapper {
private SMimeService $smimeService;
private ImapMessageFetcherFactory $imapMessageFactory;

public function __construct(LoggerInterface $logger,
public function __construct(
LoggerInterface $logger,
SmimeService $smimeService,
ImapMessageFetcherFactory $imapMessageFactory, ) {
ImapMessageFetcherFactory $imapMessageFactory,
private Converter $converter,
) {
$this->logger = $logger;
$this->smimeService = $smimeService;
$this->imapMessageFactory = $imapMessageFactory;
Expand Down Expand Up @@ -937,7 +941,7 @@ public function getBodyStructureData(Horde_Imap_Client_Socket $client,
if ($enc = $mimeHeaders->getValue('content-transfer-encoding')) {
$structure->setTransferEncoding($enc);
$structure->setContents($htmlBody);
$htmlBody = $structure->getContents();
$htmlBody = $this->converter->convert($structure);

Check warning on line 944 in lib/IMAP/MessageMapper.php

View check run for this annotation

Codecov / codecov/patch

lib/IMAP/MessageMapper.php#L944

Added line #L944 was not covered by tests
}
$mentionsUser = $this->checkLinks($htmlBody, $emailAddress);
$html = new Html2Text($htmlBody, ['do_links' => 'none','alt_image' => 'hide']);
Expand All @@ -956,7 +960,7 @@ public function getBodyStructureData(Horde_Imap_Client_Socket $client,
if ($enc = $mimeHeaders->getValue('content-transfer-encoding')) {
$structure->setTransferEncoding($enc);
$structure->setContents($textBody);
$textBody = $structure->getContents();
$textBody = $this->converter->convert($structure);

Check warning on line 963 in lib/IMAP/MessageMapper.php

View check run for this annotation

Codecov / codecov/patch

lib/IMAP/MessageMapper.php#L963

Added line #L963 was not covered by tests
}
return new MessageStructureData(
$hasAttachments,
Expand Down
5 changes: 5 additions & 0 deletions tests/Unit/IMAP/MessageMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Horde_Imap_Client_Ids;
use Horde_Imap_Client_Socket;
use OCA\Mail\Db\Mailbox;
use OCA\Mail\IMAP\Charset\Converter;
use OCA\Mail\IMAP\ImapMessageFetcher;
use OCA\Mail\IMAP\ImapMessageFetcherFactory;
use OCA\Mail\IMAP\MessageMapper;
Expand All @@ -40,17 +41,21 @@ class MessageMapperTest extends TestCase {
/** @var ImapMessageFetcherFactory|MockObject */
private $imapMessageFactory;

private Converter|MockObject $converter;

protected function setUp(): void {
parent::setUp();

$this->logger = $this->createMock(LoggerInterface::class);
$this->sMimeService = $this->createMock(SmimeService::class);
$this->imapMessageFactory = $this->createMock(ImapMessageFetcherFactory::class);
$this->converter = $this->createMock(Converter::class);

$this->mapper = new MessageMapper(
$this->logger,
$this->sMimeService,
$this->imapMessageFactory,
$this->converter,
);
}

Expand Down

0 comments on commit 625c579

Please sign in to comment.