lisp/net/mailcap.el (mailcap-file-name-to-mime-type): New function.

* lisp/net/mailcap.el (mailcap-file-name-to-mime-type): New function.
This commit is contained in:
Lars Ingebrigtsen 2017-12-25 11:29:41 +01:00
parent 53a32e6636
commit 4ddf0b8e43
2 changed files with 13 additions and 0 deletions

View file

@ -210,6 +210,11 @@ a multibyte string even if its second argument is an ASCII character.
'json-insert', 'json-parse-string', and 'json-parse-buffer'. These
are implemented in C using the Jansson library.
---
** The new function `mailcap-file-name-to-mime-type' has been added.
It's a simple convenience function for looking up MIME types based on
file name extensions.
* Changes in Emacs 27.1 on Non-Free Operating Systems

View file

@ -1006,6 +1006,14 @@ If FORCE, re-parse even if already parsed."
(setq extn (concat "." extn)))
(cdr (assoc (downcase extn) mailcap-mime-extensions)))
(defun mailcap-file-name-to-mime-type (file-name)
"Return the MIME content type based on the FILE-NAME's extension.
For instance, \"foo.png\" will result in \"image/png\"."
(mailcap-extension-to-mime
(if (string-match "\\(\\.[^.]+\\)\\'" file-name)
(match-string 1 file-name)
"")))
(defun mailcap-mime-types ()
"Return a list of MIME media types."
(mailcap-parse-mimetypes)