From e3ad2ebdf0a2dd232bdc592e3b0e992584bb9bdc Mon Sep 17 00:00:00 2001 From: nathangray Date: Mon, 22 Jan 2018 09:13:01 -0700 Subject: [PATCH] Mail - Reorganize and use same cleaning function when saving mail as infolog as for saving to VFS --- api/src/Mail.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/api/src/Mail.php b/api/src/Mail.php index 6943b0e372..11f3a4512c 100644 --- a/api/src/Mail.php +++ b/api/src/Mail.php @@ -6394,6 +6394,25 @@ class Mail return $headdata; } + /** + * Make the provided filename safe to store in the VFS + * + * Some characters found in subjects that cause problems if we try to put + * them as filenames (Windows) so we remove any characters that might result + * in additional directories, or issues on Windows. + * + * Under Windows the characters < > ? " : | \ / * are not allowed. + * % causes problems with VFS UI + * + * @param string $filename + * @return Cleaned filename, with problematic characters replaced with '_'. + */ + protected static function clean_subject_for_filename($filename) + { + static $filter_pattern = '$[\f\n\t\v\\:*#?<>%"\|/\\\?]$'; + return preg_replace($filter_pattern, "_", trim($filename)); + } + /** * adaptSubjectForImport - strips subject from unwanted Characters, and does some normalization * to meet expectations