From 943c2a2edf720007bd7857466886fa032eec6c13 Mon Sep 17 00:00:00 2001
From: Hadi Nategh <hnategh@gmail.com>
Date: Mon, 18 Dec 2017 11:27:23 +0100
Subject: [PATCH] * Mail: fix rename of an attachment and saving it into
 Filemanager always keep the original name of attachment with no respect to
 the given new name.

---
 mail/inc/class.mail_ui.inc.php | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/mail/inc/class.mail_ui.inc.php b/mail/inc/class.mail_ui.inc.php
index ae372a4738..63f5bd2efc 100644
--- a/mail/inc/class.mail_ui.inc.php
+++ b/mail/inc/class.mail_ui.inc.php
@@ -2909,7 +2909,15 @@ $filter['before']= date("d-M-Y", $cutoffdate2);
 			'success' => true
 		);
 
-		$dir = Vfs::is_dir($path) ? $path : Vfs::dirname($path);
+		if (Vfs::is_dir($path))
+		{
+			$dir = $path;
+		}
+		else
+		{
+			$dir = Vfs::dirname($path);
+			$filename = Vfs::basename($path);
+		}
 
 		if (!Vfs::is_writable($dir))
 		{
@@ -2989,7 +2997,7 @@ $filter['before']= date("d-M-Y", $cutoffdate2);
 				$attachment = $this->mail_bo->getAttachment($params['uid'],$params['part'],$params['is_winmail'],false);
 			}
 
-			$file = $dir. '/' . preg_replace('$[\f\n\t\v\\:*#?<>\|/]$',"_",$attachment['filename']);
+			$file = $dir. '/' . ($filename ? $filename : preg_replace('$[\f\n\t\v\\:*#?<>\|/]$',"_",$attachment['filename']));
 
 			$counter = 1;
 			$tmp_file = $file;