Repository navigation
fix(message-view): infer MIME type from file name when saving octet-stream attachments - #11829
Conversation
…tream attachments Document providers only treat the part after the last dot as a file extension when it matches the MIME type passed to ACTION_CREATE_DOCUMENT. Attachments sent as application/octet-stream were therefore saved as "file.pdf (1)" instead of "file (1).pdf" when a file with the same name already existed. When the attachment uses the generic MIME type, pass the type inferred from the file name (as ViewIntentFinder already does for viewing). The file name and content are unchanged. Closes thunderbird#9141 Signed-off-by: Sanilas-ai <konstantinsanilas@gmail.com>
|
✅ Validation Passed: All report and feature-flag labels are correctly set. |
|
Hi! As an outside contributor I can't set labels, so the The other workflows (Build - Android, Quality - Checks, etc.) are waiting for approval because this is my first PR here. Could someone approve them? I don't have an Android SDK in my local setup, so I'm relying on CI for the Robolectric test ( |
|
Update: local unit tests now pass in our Docker sandbox with Android SDK. Result: 7 tests, 0 failures (compileSdk 37 / Robolectric). Marked ready for review. Still need a maintainer to add a |
wmontwe
left a comment
There was a problem hiding this comment.
Thank your for the contribution!
|
Thanks for your contribution! Your pull request has been merged and will be part of Thunderbird 27. We appreciate the time and effort you put into improving Thunderbird. If you haven’t already, you’re welcome to join our Matrix chat for contributors. It’s where we discuss development and help each other out. https://matrix.to/#/#tb-android-dev:mozilla.org |
Contribution Summary
Linked Issue/Ticket: Closes #9141
Description
When an attachment is sent as
application/octet-stream(e.g. the REWE receipts from the issue), saving a duplicate offile.pdfproducedfile.pdf (1)instead offile (1).pdf.Cause: the save flow passes the attachment's MIME type to
ACTION_CREATE_DOCUMENT. Document providers (e.g. the Downloads provider) only split the display name into name and extension when the extension matches that MIME type. Withapplication/octet-stream, the wholefile.pdfis treated as the base name, and the counter gets added after it.Fix: in
MessageViewFragment.onSaveAttachment(), if the attachment uses the genericapplication/octet-streamtype, the MIME type sent to the create-document dialog is inferred from the file name withMimeTypeUtil.getMimeTypeByExtension().ViewIntentFinderalready does the same thing when viewing attachments. Non-generic MIME types are kept as is, and unknown or missing extensions still fall back toapplication/octet-stream. The change is in a small helper (getSaveAttachmentMimeType) so it can be unit tested.On the concern raised in the earlier PR (#9187) about trusting file extensions: this only changes the type hint given to the document picker, which it uses for naming. The saved file name and its bytes stay exactly as received, and the file already has that extension today. Nothing is opened or interpreted based on the inferred type.
Testing
SaveAttachmentMimeTypeTest(Robolectric): non-generic types are kept (even when they don't match the extension), octet-stream plus.pdfgivesapplication/pdf(case-insensitive), and unknown, missing, or absent extensions keepapplication/octet-stream.gradlew :legacy:ui:legacy:testDebugUnitTestorspotlessCheck. I'm relying on CI and will fix anything it reports. That's why this is opened as a draft.application/octet-streamattachment namedfile.pdfto Downloads twice. Expected:file (1).pdf.AI Disclosure
Contribution Checklist
gradlew spotlessChecknot run locally, pending CI)gradlew testDebugUnitTestnot run locally, pending CI)