Fix attachment MIME type detection for non-image file types (#3604)

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 <noreply@anthropic.com>
This commit is contained in:
SuchAFuriousDeath
2026-03-09 11:56:44 +01:00
committed by GitHub
parent 1877aeecb0
commit 49f48340ac

View File

@@ -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;
}