From 34c33188e9095bcbd756e0a81945dbad73a515b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Anne?= Date: Mon, 9 Dec 2024 16:17:04 +0100 Subject: [PATCH] Fix IMAP folders names decoding --- src/MailCollector.php | 25 ++++++++++++++++++- .../setup/mailcollector/folder_list.html.twig | 6 ++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/MailCollector.php b/src/MailCollector.php index 234af344372..9722c98aeae 100644 --- a/src/MailCollector.php +++ b/src/MailCollector.php @@ -40,6 +40,7 @@ use Laminas\Mail\Header\ContentDisposition; use Laminas\Mail\Header\ContentType; use Laminas\Mail\Storage; +use Laminas\Mail\Storage\Folder; use Laminas\Mail\Storage\Message; use LitEmoji\LitEmoji; @@ -246,7 +247,9 @@ public function displayFoldersList($input_id = "") try { $this->connect(); $connected = true; - $folders = $this->storage->getFolders(); + foreach ($this->storage->getFolders() as $folder) { + $folders[] = $this->extractFolderData($folder); + } } catch (\Throwable $e) { ErrorHandler::getInstance()->handleException($e, false); } @@ -258,6 +261,26 @@ public function displayFoldersList($input_id = "") ]); } + /** + * Extract an IMAP folder data to be used in Twig context. + * @param Folder $folder + * @return array + */ + private function extractFolderData(Folder $folder): array + { + $data = [ + 'global_name' => mb_convert_encoding($folder->getGlobalName(), 'UTF-8', 'UTF7-IMAP'), + 'local_name' => mb_convert_encoding($folder->getLocalName(), 'UTF-8', 'UTF7-IMAP'), + 'children' => [], + ]; + + foreach ($folder as $child) { + $data['children'][] = $this->extractFolderData($child); + } + + return $data; + } + public function rawSearchOptions() { $tab = []; diff --git a/templates/pages/setup/mailcollector/folder_list.html.twig b/templates/pages/setup/mailcollector/folder_list.html.twig index 381bc5c1ad2..20682a02a87 100644 --- a/templates/pages/setup/mailcollector/folder_list.html.twig +++ b/templates/pages/setup/mailcollector/folder_list.html.twig @@ -32,13 +32,11 @@ #} {% macro display_folder(folder, input_id) %} - {% set name = folder.getLocalName|convert_encoding('UTF-8', 'UTF7-IMAP') %} - {% set global_name = folder.getGlobalName|convert_encoding('UTF-8', 'UTF7-IMAP') %}
  • - {{ name }} + {{ folder['local_name'] }}