From 4ddf0b8e43537626aa5aa49122b1fe7a9ad3adc3 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Mon, 25 Dec 2017 11:29:41 +0100 Subject: [PATCH] lisp/net/mailcap.el (mailcap-file-name-to-mime-type): New function. * lisp/net/mailcap.el (mailcap-file-name-to-mime-type): New function. --- etc/NEWS | 5 +++++ lisp/net/mailcap.el | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/etc/NEWS b/etc/NEWS index 1f8fe67152f..64c74c0d56e 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -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 diff --git a/lisp/net/mailcap.el b/lisp/net/mailcap.el index be1a171cd48..197d233ddad 100644 --- a/lisp/net/mailcap.el +++ b/lisp/net/mailcap.el @@ -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) -- 2.39.2