Skip to content

Commit

Permalink
Attachment Name Encoding Fix
Browse files Browse the repository at this point in the history
Some Filenames are not beeing decoded correctly
  • Loading branch information
thin-k-design authored Aug 16, 2024
1 parent 0966e53 commit 6dfb1ec
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand All @@ -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
Expand Down

0 comments on commit 6dfb1ec

Please sign in to comment.