Skip to content

Commit

Permalink
Fix IMAP folders names decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-anne authored and trasher committed Dec 9, 2024
1 parent 3ebae3b commit 34c3318
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
25 changes: 24 additions & 1 deletion src/MailCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand All @@ -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 = [];
Expand Down
6 changes: 2 additions & 4 deletions templates/pages/setup/mailcollector/folder_list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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') %}
<li class="cursor-pointer" data-input-id="{{ input_id }}">
<i class="ti ti-folder"></i>
<span class="folder-name" data-globalname="{{ global_name }}">{{ name }}</span>
<span class="folder-name" data-globalname="{{ folder['global_name'] }}">{{ folder['local_name'] }}</span>
<ul>
{% for subfolder in folder %}
{% for subfolder in folder['children'] %}
{{ _self.display_folder(subfolder, input_id) }}
{% endfor %}
</ul>
Expand Down

0 comments on commit 34c3318

Please sign in to comment.