Skip to content

Commit

Permalink
fixup! fix(encoding): better character encoding
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Wurst <[email protected]>
  • Loading branch information
ChristophWurst committed Dec 7, 2023
1 parent 8a96ebd commit 0cbdb53
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/IMAP/Charset/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Converter {
* @throws ServiceException
*/
public function convert(Horde_Mime_Part $p): string {
/** @var null|string $data */
$data = $p->getContents();
if ($data === null) {
return '';
Expand Down
7 changes: 6 additions & 1 deletion lib/IMAP/ImapMessageFetcherFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,21 @@
namespace OCA\Mail\IMAP;

use Horde_Imap_Client_Base;
use OCA\Mail\IMAP\Charset\Converter;
use OCA\Mail\Service\Html;
use OCA\Mail\Service\SmimeService;

class ImapMessageFetcherFactory {
private Html $htmlService;
private SmimeService $smimeService;
private Converter $charsetConverter;

public function __construct(Html $htmlService,
SmimeService $smimeService) {
SmimeService $smimeService,
Converter $charsetConverter) {
$this->htmlService = $htmlService;
$this->smimeService = $smimeService;
$this->charsetConverter = $charsetConverter;
}

public function build(int $uid,
Expand All @@ -51,6 +55,7 @@ public function build(int $uid,
$userId,
$this->htmlService,
$this->smimeService,
$this->charsetConverter,
);
}
}
10 changes: 10 additions & 0 deletions tests/Unit/IMAP/Charset/ConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
use ChristophWurst\Nextcloud\Testing\TestCase;
use Horde_Mime_Part;
use OCA\Mail\IMAP\Charset\Converter;
use function fopen;
use function fwrite;
use function mb_convert_encoding;

class ConverterTest extends TestCase {
Expand Down Expand Up @@ -54,6 +56,13 @@ public function dataProviderMimeParts(): array {
$utfMimePart->setType('text/plain');
$utfMimePart->setCharset('UTF-8');
$utfMimePart->setContents('๐Ÿ˜Š');
// UTF8 stream
$utfMimeStreamPart = new Horde_Mime_Part();
$utfMimeStreamPart->setType('text/plain');
$utfMimeStreamPart->setCharset('UTF-8');
$fh = fopen("php://temp", 'r+');
fwrite($fh, '๐Ÿ’ฆ');
$utfMimeStreamPart->setContents($fh, [ 'usestream' => true, ]);
// Hebrew
$iso88591MimePart = new Horde_Mime_Part();
$iso88591MimePart->setType('text/plain');
Expand Down Expand Up @@ -81,6 +90,7 @@ public function dataProviderMimeParts(): array {

return[
[$utfMimePart, '๐Ÿ˜Š'],
[$utfMimeStreamPart, '๐Ÿ’ฆ'],
[$iso88591MimePart, 'รœmlaut'],
[$iso2022jpMimePart, 'ๅค–ใ›ๅœ’ๆŸปใƒชใƒ„ใƒใƒฏ้กŒ'],
[$iso88591MimePart_noCharset, 'ื‘ื” ื‘ื“ืฃ ืœื—ื‘ืจ ืžืžื•ื ืจื›ื™ื”, ื‘ืงืจ ื‘ื’ืจืกื” ื•ืืžื ื•ืช ื“ืช'],
Expand Down

0 comments on commit 0cbdb53

Please sign in to comment.