Skip to content

fix(attachments): preview PDFs with generic MIME type - #14042

Draft
PsyCrow-code wants to merge 6 commits into
nextcloud:mainfrom
PsyCrow-code:feature/pdf-preview-upstream-main
Draft

PsyCrow-code wants to merge 6 commits into
nextcloud:mainfrom
PsyCrow-code:feature/pdf-preview-upstream-main

Conversation

@PsyCrow-code

Copy link
Copy Markdown

Summary

Fixes #12934.

Some mail senders label PDF attachments as application/octet-stream, even though their filenames end in .pdf or .PDF. Nextcloud Mail then displays a generic attachment icon and does not offer the PDF viewer.

This change enables previews for these specific attachments without changing their declared MIME type or normal download behavior.

Changes

  • Use the files_pdfviewer handler for application/octet-stream attachments with a case-insensitive .pdf filename extension.
  • Display the PDF icon in both message view and message-list attachment tags, including results already stored in the attachment metadata cache.
  • When a preview is requested, check the %PDF- signature server-side. Reject invalid candidates with HTTP 415 and show a native Nextcloud error notification instead of opening the viewer.
  • Preserve the original MIME type, regular attachment download URL, and downloads of other file types.
  • Add frontend and backend regression coverage for valid and invalid PDF candidates, explicit non-PDF MIME types, and cached metadata.

Performance and limitations

  • Attachment bodies are not fetched to determine icons or while displaying the mailbox.
  • Server-side signature checking happens only on a preview request.
  • A manual Chrome test of an 87,917-byte PDF showed a single network transfer, followed by a viewer request served from the browser disk cache. HTTP cache reuse is not guaranteed in every browser or configuration.
  • The %PDF- check confirms only the file signature, not that the complete file is a structurally valid or safe PDF. Parsing and rendering remain the viewer's responsibility.
  • Preview still requires files_pdfviewer; normal downloads are unaffected.

Testing

  • Eight Vitest tests passed against current upstream/main (6.0.0-alpha.1).
  • ESLint passed for both changed frontend files.
  • Production Webpack build succeeded against current upstream/main.
  • php -l passed for the four changed PHP source/test files.
  • git diff --check upstream/main...HEAD passed.
  • Manually tested on Nextcloud 35.0.2 with Mail 5.12.6: valid PDF preview, invalid PDF rejection (HTTP 415), nonblocking native notification, normal downloads, icons in message view and message list, and cached attachment metadata.
  • PHP unit tests require a suitable Nextcloud core test environment / CI.

The separately developed local multiline message-list customization is not included.

AI assistance

  • This contribution was partly developed with assistance from ChatGPT and manually reviewed and functionally tested.

@welcome

welcome Bot commented Nov 4, 2026

Copy link
Copy Markdown

Thanks for opening your first pull request in this repository! ✌️

Signed-off-by: PsyCrow <ing.josegonzalez@gmail.com>
Signed-off-by: PsyCrow <ing.josegonzalez@gmail.com>
Signed-off-by: PsyCrow <ing.josegonzalez@gmail.com>
Signed-off-by: PsyCrow <ing.josegonzalez@gmail.com>
Signed-off-by: PsyCrow <ing.josegonzalez@gmail.com>
Signed-off-by: PsyCrow <ing.josegonzalez@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PDF attachments cannot be displayed if MIME is application/octet-stream

2 participants