Improve image detection

Created on 27 June 2020, about 4 years ago
Updated 7 March 2023, over 1 year ago

In several places, Mime Mail needs to determine if a URL or a file attachment is an image. Currently, a regular expression is used to do this. This is a problem for several reasons:

  • Regular expressions are hard to maintain because they are prone to being inaccurate, especially in the absence of good testing (and these aren't tested at all in the current version of Mime Mail ...)
  • The regular expression currently only recognizes four image file extensions: .png, .gif, .jpg, and .jpeg, so it is incomplete. It is in practice impossible to keep this list up-to-date and complete, so we will always be behind the curve if we continue to use this.

Drupal 8 has a perfectly good service 'file.mime_type.guesser' which is an implementation of the Symfony MimeTypeGuesserInterface. This service provides a way to determine the MIME type of a file that is way more capable than our simple regular expression, and since it is core Drupal / Symfony it is being used and updated and supported by way more people. (Mime Mail's regular expression hasn't changed in 10 years).

A future problem is that Mime Mail is currently trying to determine the MIME type in four distinct places - we should eventually refactor this code so that doesn't have to happen, but the first step is to do the type determination the same way in all four places so that at least we always get the same answer.

✨ Feature request
Status

Needs work

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States TR Cascadia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024