From 3dac7d62b7c85bde31d27ef48569df9d07ae6eec Mon Sep 17 00:00:00 2001 Message-Id: <3dac7d62b7c85bde31d27ef48569df9d07ae6eec.1653918246.git.yantar92@gmail.com> From: Ihor Radchenko Date: Sun, 22 May 2022 12:04:35 +0800 Subject: [PATCH v3] 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 95dff27ad..b9a7b4b2e 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -7981,7 +7981,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 --dereference %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