From 4aeff613c07d9025c5fc1f0b3851870a42d36869 Mon Sep 17 00:00:00 2001 Message-Id: <4aeff613c07d9025c5fc1f0b3851870a42d36869.1653538199.git.yantar92@gmail.com> From: Ihor Radchenko Date: Sun, 22 May 2022 12:04:35 +0800 Subject: [PATCH v2] org-open-file: Use file command to determine mime type, when available * lisp/org.el (org-open-file): Prefer file command to determine file type instead of relying on `mailcap-extension-to-mime'. Only fallback to the latter when file command is not available on the system. Fixes https://list.orgmode.org/874k1n2hpv.fsf@localhost/T/#mcc10df4ea7937360671e6dea8061153dee518807 --- lisp/org.el | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lisp/org.el b/lisp/org.el index d7da8efc4..45a179a8a 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -7975,7 +7975,12 @@ (defun org-open-file (path &optional in-emacs line search) (when (eq cmd 'mailcap) (require 'mailcap) (mailcap-parse-mailcaps) - (let* ((mime-type (mailcap-extension-to-mime (or ext ""))) + (let* ((mime-type (if (executable-find "file") + (shell-command-to-string + (format "%s --brief --mime-type %s" + (executable-find "file") + (shell-quote-argument (convert-standard-filename file)))) + (mailcap-extension-to-mime (or ext "")))) (command (mailcap-mime-info mime-type))) (if (stringp command) (setq cmd command) -- 2.35.1