Skip to content

Commit

Permalink
Merge pull request #10442 from nextcloud/fix/imap/preview-text-charset
Browse files Browse the repository at this point in the history
fix(imap): Consider charset for preview text decoding
  • Loading branch information
ChristophWurst authored Dec 5, 2024
2 parents 188b041 + 625c579 commit 4dbc57e
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);
}
$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);
}
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 4dbc57e

Please sign in to comment.