Skip to content

Fix MIME detection fallback when puremagic returns empty string#1353

Open
tgies wants to merge 1 commit intosimonw:mainfrom
tgies:fix-1340-mimetype-fallback
Open

Fix MIME detection fallback when puremagic returns empty string#1353
tgies wants to merge 1 commit intosimonw:mainfrom
tgies:fix-1340-mimetype-fallback

Conversation

@tgies
Copy link

@tgies tgies commented Feb 7, 2026

Summary

  • Fixes MIME type detection fails when puremagic returns empty string #1340puremagic.from_file() can return an empty string "" instead of raising PureError, which passed through as an invalid MIME type causing attachment validation errors.
  • Adds mimetypes.guess_type() as a fallback when puremagic returns empty string or raises an exception.
  • Adds "audio/x-wav": "audio/wav" to MIME_TYPE_FIXES since mimetypes returns audio/x-wav for .wav files.
  • Applies MIME_TYPE_FIXES normalization regardless of which detection method succeeded.

Test plan

  • test_mimetype_from_path_fallback_on_empty_string — puremagic returns "", falls back to extension
  • test_mimetype_from_path_fallback_on_puremagic_error — puremagic raises, falls back to extension
  • test_mimetype_from_path_fallback_normalizes_wav — fallback result goes through MIME_TYPE_FIXES
  • test_mimetype_from_path_returns_none_if_no_detection — both methods fail → None

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MIME type detection fails when puremagic returns empty string

1 participant