From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id 8EVbFAABj2KXkwAAbAwnHQ (envelope-from ) for ; Thu, 26 May 2022 06:24:32 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id IC1PEwABj2JzVgEAG6o9tA (envelope-from ) for ; Thu, 26 May 2022 06:24:32 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 1C6BB24BC2 for ; Thu, 26 May 2022 06:24:31 +0200 (CEST) Received: from localhost ([::1]:57814 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nu52y-0006Zw-Il for larch@yhetil.org; Thu, 26 May 2022 00:24:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59410) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nu51n-0006Zo-QL for emacs-orgmode@gnu.org; Thu, 26 May 2022 00:23:16 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]:39674) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nu51l-0000Cg-9R for emacs-orgmode@gnu.org; Thu, 26 May 2022 00:23:15 -0400 Received: by mail-pf1-x42c.google.com with SMTP id y1so732101pfr.6 for ; Wed, 25 May 2022 21:23:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=YlOPKhwkT/YJqSA6KitgUssfzZzUyvx8Er5tNIWPQeE=; b=hhm58ECwPsbuSgo6mLkXeJmyPrJALkIeFInHoxwghF1aEY2oPRtPsC1FsGp15IHSGO j/vNQLMEEVHlif32f/4g8Dgq3cOG/4z74s8xKaMMRjcEL9p3LYkD7x2F9yYEq0BRyOcm XySZmJPQkKj8uxqNnCcirxzwsqH7DDYiP9T3s81IUpIwOMS5HkwJVeD458G/sAgabNep C7AV4KBSfy/niOIpQlaDlwdP4/A7mOyn9R7CcSVHFxzHoIE3QbV8ajm3NiTb1ighznwQ 8B7dQj0RBebfSZcIOnjVCiK7CVBKAbtML0oBOgi6OPjzL82OoyvwRg39WZm/DEHtypp5 GKkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=YlOPKhwkT/YJqSA6KitgUssfzZzUyvx8Er5tNIWPQeE=; b=kME5sCCXYeeu2jSWmW0TVeUk03P0nGnLlgQUshy/G+iWYz3RKsDHmtYjja2Xyb6BJC VqFQuQzebY2LmqgcSdUtNx+UDnwFwLJ2Hp+IQMBRMEja7u/JVmdmiUYKnQ378VID92GD gbVj1su/JmpO6KDBmLxd320NL3wg1KCelWllOUNsNakB9YjDzclFMqh9x8VCZ+pIXvh3 tc9qI/oCJfg1CCS+JWS1Q1fHv8EgwC7WTd9lu4zRX0YfEckXir4prQsu1J+cbdFWOmj4 fwNOMiYuDHPbsYi8jGpVgfZcm/YF9gZC2idO09lQswHmrbmKTRZM4XvIu0QXkaDQOvfn /CxQ== X-Gm-Message-State: AOAM533CD9Gskf5oPIoN2zH4/z2FPBOjAyL/zRs36K7KwZBgkkPTQYZP hW879xqA4T3ehi32GjQTejA= X-Google-Smtp-Source: ABdhPJyVrBRTTHWkgOe69cT/IRec+MCjHhm9kCLCjptvNul9TM3OTZp3qX80y0Y8Kzu5ly7snIJPRQ== X-Received: by 2002:a63:6a87:0:b0:3f9:c829:796d with SMTP id f129-20020a636a87000000b003f9c829796dmr24415031pgc.232.1653538990711; Wed, 25 May 2022 21:23:10 -0700 (PDT) Received: from localhost ([74.222.20.18]) by smtp.gmail.com with ESMTPSA id g187-20020a636bc4000000b003c14af505eesm394070pgc.6.2022.05.25.21.23.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 May 2022 21:23:09 -0700 (PDT) From: Ihor Radchenko To: Max Nikulin Cc: emacs-orgmode@gnu.org Subject: [PATCH v2] Re: Bug in 9.5.3 org--file-default-apps In-Reply-To: References: <963d5f94-3fdf-a01b-bc91-edc99222cb34@gmail.com> <87czgeaxir.fsf@localhost> <6615610d-93ae-171f-b554-3f4cc79354cc@gmail.com> <87a6bhc1w6.fsf@localhost> <86692975-4d5f-6933-3227-c6b208f76862@gmail.com> <877d6lbsg5.fsf@localhost> <7c75b724-1ea2-5e3e-cbe6-e1895fd35bd3@gmail.com> <877d6j2htv.fsf@localhost> <87ilq14p6p.fsf@localhost> <87v8u0396t.fsf@localhost> <87ilpz3bi0.fsf@localhost> <87h75ip5r6.fsf@localhost> Date: Thu, 26 May 2022 12:23:51 +0800 Message-ID: <87zgj46hwo.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=yantar92@gmail.com; helo=mail-pf1-x42c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1653539071; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=YlOPKhwkT/YJqSA6KitgUssfzZzUyvx8Er5tNIWPQeE=; b=EexbInz6F/E+Qps70ejFa0JfBov4hSpxWAYRFuqgyqHjuAMzEch4wdwghlO5Sy54nRZAid VzCT2+Dklwa6/JjnhMemVlNStIDhsYnIw7NxIMgac6Zlk9jWhJbqmsTymWgiBE0/Y7VEOo V39sp547MNs/19DnbpUngnCFSok+BLiDoNm61lIl1kWwk9ncLKtezpcEeDpnMnBNkTa8aC vQ3ZksUAvxzq5vK+hxIAQP/Ujlg22SYjtUr7cp1pCDUTvyiR/0zeZkjjcQxVv0XFBF7ixW INyS1ggr891Xr3sALUC2MPsxm5/ngGa1LZ8nZDDSDJYgkRUxt3c5IDpHkUaQ/g== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1653539071; a=rsa-sha256; cv=none; b=ndpTGdm1sz+hSPlrkDjZbl5UE4ICRgMx/+xmodGU7qBofMt8O/yxVpPG3kwOSVBrStJryM S/zoqGcIJmFazamo9EeGqiJYX1tY8foRnYG/1+Mz8xncCkpsibBHgbHhmoYJgUhfW1mISR 8BmQkMLqruWdQxOcWJGyZB6/iV2RTxeGI4AO0/YEBqGFEtVfTPgaDhq76UyIjwpHyNePvU VHvawXaTGKx0bxFX5Mb/mHbCK6Q9xP33UKb/1EpGNK1bXTHGapk2WNND6FTH5VsQ04u7mY rGJUggUem+gZMTOWDC9t9heg7f8Ov41feeGYPERyPYu6zb3aGrfWVZRNT0tqDg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=hhm58ECw; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -7.04 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=hhm58ECw; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 1C6BB24BC2 X-Spam-Score: -7.04 X-Migadu-Scanner: scn0.migadu.com X-TUID: R42fFCWRRlm5 --=-=-= Content-Type: text/plain Max Nikulin writes: > On 22/05/2022 11:10, Ihor Radchenko wrote: >> Max Nikulin writes: >> >>> The source of the problem is that Emacs-27 was released with the >>> following bug: >>> >>> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=40247 >>> mailcap-mime-data erased when parsing mime parts >>> >>> So `mailcap-parse-mailcaps' called from `mailcap-mime-info' erases >>> predefined associations in Emacs-27. >> >> If I understand correctly, this extra complication does not affect most >> of the systems. I am not sure if we need to work around it. > > I would say that view-mode is quite reasonable default to open a > "text/plain" file and this bug broke it. I agree. However, I am already a bit lost with all the complications. This particular one does not appear to be directly relevant to the initial problem with a file with no extension. I'd prefer if this Emacs-27 issue were reported in a separate thread. >> Also, I am attaching a patch to address the original issue. We can just >> use file command when available. WDYT? > > Ihor, have you manged to reproduce the original issue? Are links with > explicit .txt suffix [[file:file.txt]] affected by the same problem? My > environments sometimes behave in a way unexpected to you and I have not > setup any tool to quickly launch transient virtual machines with no fear > to "broke" current state, so I have not tried to debug the reported > issue in its original form. > > I may be excessively suspicious. Yes, I have managed to reproduce the original issue. Kind of. We have the following in org-open-file: (when (eq cmd 'mailcap) (require 'mailcap) (mailcap-parse-mailcaps) (let* ((mime-type (mailcap-extension-to-mime (or ext ""))) (command (mailcap-mime-info mime-type))) (if (stringp command) (setq cmd command) (setq cmd 'emacs)))) with EXT being bound to file extension. When file does not have an extension (the original issue), (mailcap-extension-to-mime) returns nil. Then, (mailcap-mime-info nil) returns the same result with (mailcap-mime-info "text/plain"). It is hard-coded inside mailcap-mime-info. So, with the current default value of org-file-apps-gnu, files with no extension always use mime handler assigned to "text/plain" mimetype. In a way, it is not wrong - mailcap spec only considers file extension and has undefined behavior for files with no extension. However, it does not make sense from the user perspective. Hence, I am suggesting this patch. =file= command (when available) is more powerful and looks at the file contents, not just into its extension. >> + (let* ((mime-type (if (executable-find "file") >> + (shell-command-to-string >> + (format "%s --brief --mime-type %s" >> + (executable-find "file") >> + file)) > > I hate elisp API related to executing of external processes because it > encourages proliferation of unsafe code. What if the linked file name > has some peculiarities and characters interpreted by shell? > > See [[file:/tmp/`touch /tmp/hacked`/test][here]] Thanks for the heads up! Updated version of the patch is attached. > I can not say that I fully understand `org-open-file' code, so I am > unsure if remote file name can appear here, e.g. /ssh:user@host:testfie > or a file form an archive due to a relative link [[file:testfile]] from > a remote .org file. When remote files are not an issue, it is safer to > use functions that takes command arguments as a list of string, not the > command as a ready to execute string. Unfortunately there is no helper > returning a string and accepting a command as a list. org-file-apps-gnu defaults to ((remote . emacs) (system . mailcap) (t . mailcap)) All the "remote" files (including /ssh) will be opened in emacs. We should have no issue in this area. >> + (mailcap-extension-to-mime (or ext "")))) >> (command (mailcap-mime-info mime-type))) >> (if (stringp command) >> (setq cmd command) > > P.S. `org-open-file' already has some problems with handling of some > file names: > > Maxim Nikulin to emacs-orgmode. greedy substitution in org-open-file. > Wed, 20 Jan 2021 23:08:35 +0700. > https://list.orgmode.org/ru9ki4$t5e$1@ciao.gmane.io Agree. Though it is not directly related. Maybe you can bump that thread and mark is as a bug report to be listed on https://updates.orgmode.org/? Best, Ihor --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=v2-0001-org-open-file-Use-file-command-to-determine-mime-.patch >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 --=-=-=--