From c50b0ec6bbc89b619e6ca028f341c26bbdbe1e70 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Sat, 13 Jun 2020 13:18:13 +0100 Subject: [PATCH] Fixed #45: File name too long when parsing attachments --- src/parser/parts/file_parser.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/parser/parts/file_parser.php b/src/parser/parts/file_parser.php index b6f80066..74188a32 100644 --- a/src/parser/parts/file_parser.php +++ b/src/parser/parts/file_parser.php @@ -9,9 +9,9 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -142,7 +142,12 @@ public function __construct( $mainType, $subType, ezcMailHeadersHolder $headers } // clean file name (replace unsafe characters with underscores) - $fileName = strtr( $fileName, "/\\\0\"|?*<:;>+[]", '______________' ); + $fileName = preg_replace( '/[^A-Za-z0-9-. ]/', '_', $fileName ); + + if ( strlen( $fileName ) > 200 ) + { + $fileName = substr( $fileName, 0, 200 ) . '.' . pathinfo( $fileName, PATHINFO_EXTENSION ); + } $this->fp = $this->openFile( $fileName ); // propagate exception }