[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 4ddf0b8: lisp/net/mailcap.el (mailcap-file-name-to-
From: |
Lars Ingebrigtsen |
Subject: |
[Emacs-diffs] master 4ddf0b8: lisp/net/mailcap.el (mailcap-file-name-to-mime-type): New function. |
Date: |
Mon, 25 Dec 2017 10:05:28 -0500 (EST) |
branch: master
commit 4ddf0b8e43537626aa5aa49122b1fe7a9ad3adc3
Author: Lars Ingebrigtsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>
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 1f8fe67..64c74c0 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 be1a171..197d233 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)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master 4ddf0b8: lisp/net/mailcap.el (mailcap-file-name-to-mime-type): New function.,
Lars Ingebrigtsen <=