Skip to content

Commit

Permalink
Fixed #45: File name too long when parsing attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
derickr committed Jun 13, 2020
1 parent c06d70c commit c50b0ec
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/parser/parts/file_parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit c50b0ec

Please sign in to comment.