From f69824559d62cb6963ff30f11ceb46303bf1b3d4 Mon Sep 17 00:00:00 2001 Message-Id: From: Ihor Radchenko Date: Sun, 22 May 2022 12:04:35 +0800 Subject: [PATCH] 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..3102fe611 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") + file)) + (mailcap-extension-to-mime (or ext "")))) (command (mailcap-mime-info mime-type))) (if (stringp command) (setq cmd command) -- 2.35.1