]> git.eshelyaron.com Git - emacs.git/commitdiff
Add new function mailcap-mime-type-to-extension
authorLars Ingebrigtsen <larsi@gnus.org>
Sat, 6 Nov 2021 20:14:54 +0000 (21:14 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Sat, 6 Nov 2021 20:59:27 +0000 (21:59 +0100)
* lisp/net/mailcap.el (mailcap-mime-type-to-extension): Add a new
helper function to do the reverse of `mailcap-file-name-to-mime-type'.

lisp/net/mailcap.el

index df6bdd1aba550053b4acb9ebeaf2ad6469e4a6a6..0ad1a53e846fd669832bd155a2fde35e3352f24d 100644 (file)
@@ -1068,6 +1068,14 @@ For instance, \"foo.png\" will result in \"image/png\"."
        (match-string 1 file-name)
      "")))
 
+(defun mailcap-mime-type-to-extension (mime-type)
+  "Return a file name extension based on a mime type.
+For instance, `image/png' will result in `png'."
+  (intern (cadr (split-string (if (symbolp mime-type)
+                                  (symbol-name mime-type)
+                                mime-type)
+                              "/"))))
+
 (defun mailcap-mime-types ()
   "Return a list of MIME media types."
   (mailcap-parse-mimetypes)