/**
* Check and if necessary fix the file name of an attachment so that the attached file
* has the same extension as the source file, and not a different file extension
*
* @param string $file Path to the file to be attached
* @param string $name The file name to be used for the attachment
*
* @return string The corrected file name for the attachment
*
* @since 4.0.0
*/
protected function getAttachmentName(string $file, string $name) : string
{
// If no name is given, do not process it further
if (!trim($name)) {
return '';
}
// Replace any placeholders.
$name = $this->replaceTags($name, $this->data);
// Get the file extension.
$ext = File::getExt($file);
// Strip off extension from $name and append extension of $file, if any
return File::stripExt($name) . ($ext ? '.' . $ext : '');
}