Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect MimeType application/excel #83

Open
programmiererei opened this issue Sep 24, 2024 · 5 comments
Open

Incorrect MimeType application/excel #83

programmiererei opened this issue Sep 24, 2024 · 5 comments

Comments

@programmiererei
Copy link

programmiererei commented Sep 24, 2024

If an e-mail contains an XLSX Excel file as an attachment, this is returned with the mimetype “application/excel”.
However, the correct mimetype would be “application/vnd.openxmlformats-officedocument.spreadsheetml.sheet”.
“application/excel” is also not a valid mimetype: see
https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types

I use omsg.fetchTrueAttachments(), and the attachment object contains:
image

It is strange that the longFilename is correct, but the filename has the wrong extension 'xls'.

@bbottema
Copy link
Owner

Hhm, I'll have to dive into this. There is a mimetype mapping in the project, so it's probably mapped wrong.

@programmiererei
Copy link
Author

programmiererei commented Sep 24, 2024 via email

@programmiererei
Copy link
Author

I think the problem is the old 8.3 filename in the filename. property, because xlsx is abbreviated to xls. And in OutlookFileAttachment.java, procedure checkMimeTag is checked first filename and then longFilename.

@bbottema
Copy link
Owner

bbottema commented Sep 25, 2024

I'm not sure why xlsx would be abbreviated to xls (I don't think this library itself does that), but the extension is mapped to a mimetype as follows:

application/x-msexcel xlw xla xls
application/x-excel xld xlt xlw xlv xlk xlm xll xla xlc xls xlb
application/vnd.ms-excel xlsx xlw xlsm xlm xll xlc xls XLS xlb
application/excel xld xlt xlw xlv xl xlk xlm xll xla xlc xls xlb

Looking deeper into Angus' Activation package and seeing the mapping to be based on a hashtable, I can only assume the above key value combinations are inverted (extensions as keys) in top down order, meaning the last mimetype to declare the same extension wins. This would explain the mimetype you saw for the extension "xls". Why this doesn't include extensions longer than 3 characters I have no idea, but apparently that's not an issue seeing you mentioning the abbreviation to make a mapping happening somehow.

I suggest we examine the order of mimetypes, deduplicate extensions and apply the correct mimetypes. Care to propose one?

Here's my proposal:

application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx
application/vnd.ms-excel xls xlk xl
application/vnd.ms-excel.sheet.macroenabled.12 xlsm
application/vnd.ms-excel.template.macroenabled.12 xltm
application/vnd.ms-excel.addin.macroenabled.12 xlam

@bbottema
Copy link
Owner

Also, it would be helpful if you can provide a .msg file with a problematic excel sheet, so I can include it in my junit testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants