From 6dfb1ecb5546694ab10a52a74e92673748685d77 Mon Sep 17 00:00:00 2001 From: Daniel Castilla Date: Fri, 16 Aug 2024 21:02:49 +0200 Subject: [PATCH] Attachment Name Encoding Fix Some Filenames are not beeing decoded correctly --- src/Attachment.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Attachment.php b/src/Attachment.php index 15b83f6..1cfc8d6 100755 --- a/src/Attachment.php +++ b/src/Attachment.php @@ -285,11 +285,9 @@ public function save(string $path, ?string $filename = null): bool { */ public function decodeName(?string $name): string { if ($name !== null) { - if (str_contains($name, "''")) { - $parts = explode("''", $name); - if (EncodingAliases::has($parts[0])) { - $name = implode("''", array_slice($parts, 1)); - } + $parts = explode("'", $name, 3); + if (EncodingAliases::has($parts[0])) { + list($charset, $language, $name) = $parts; } $decoder = $this->config['decoder']['message']; @@ -302,6 +300,9 @@ public function decodeName(?string $name): string { // check if $name is url encoded if (preg_match('/%[0-9A-F]{2}/i', $name)) { $name = urldecode($name); + if ($decoder === 'utf-8' && isset($charset)) { + $name = mb_convert_encoding($name, 'UTF-8', $charset); + } } // sanitize $name