Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable4.1] fix(imap): Consider charset for preview text decoding #10445

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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 @@
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
Loading