From 49f48340ac074ee0c2f8f22affe2c7b3b3c2a5e5 Mon Sep 17 00:00:00 2001 From: SuchAFuriousDeath <48620541+SuchAFuriousDeath@users.noreply.github.com> Date: Mon, 9 Mar 2026 11:56:44 +0100 Subject: [PATCH] Fix attachment MIME type detection for non-image file types (#3604) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The mail parser's MIME type fallback map only contained image types (jpg, jpeg, png, gif, webp), causing attachments sent as application/octet-stream (common with Lotus Notes and other legacy clients) to be stored with a NULL type. This made PDFs and documents download instead of opening inline. Extended $extMimeTypeMap with common document, archive and media types. Also fixed getAttachmentFilenameExtension() which used explode('.')[1] to get the extension — this returns the part after the *first* dot rather than the last, breaking for filenames like "report.2024.pdf". Replaced with pathinfo() which correctly extracts the final extension. Co-authored-by: Claude Opus 4.6 --- .../Espo/Core/Mail/Parsers/MailMimeParser.php | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/application/Espo/Core/Mail/Parsers/MailMimeParser.php b/application/Espo/Core/Mail/Parsers/MailMimeParser.php index c14c2fde62..2ec7f40ecd 100644 --- a/application/Espo/Core/Mail/Parsers/MailMimeParser.php +++ b/application/Espo/Core/Mail/Parsers/MailMimeParser.php @@ -58,6 +58,27 @@ class MailMimeParser implements Parser 'png' => 'image/png', 'gif' => 'image/gif', 'webp' => 'image/webp', + 'pdf' => 'application/pdf', + 'doc' => 'application/msword', + 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + 'xls' => 'application/vnd.ms-excel', + 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + 'ppt' => 'application/vnd.ms-powerpoint', + 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', + 'odt' => 'application/vnd.oasis.opendocument.text', + 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', + 'csv' => 'text/csv', + 'txt' => 'text/plain', + 'html' => 'text/html', + 'htm' => 'text/html', + 'xml' => 'application/xml', + 'zip' => 'application/zip', + 'gz' => 'application/gzip', + 'eml' => 'message/rfc822', + 'svg' => 'image/svg+xml', + 'bmp' => 'image/bmp', + 'tif' => 'image/tiff', + 'tiff' => 'image/tiff', ]; private ?WrappeeParser $parser = null; @@ -434,9 +455,9 @@ class MailMimeParser implements Parser return null; } - $ext = explode('.', $filename)[1] ?? null; + $ext = pathinfo($filename, PATHINFO_EXTENSION); - if (!$ext) { + if ($ext === '') { return null; }