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 IOa2FTzpiWKS8gAAbAwnHQ (envelope-from ) for ; Sun, 22 May 2022 09:41:48 +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 QG/IFDzpiWKwZAEAG6o9tA (envelope-from ) for ; Sun, 22 May 2022 09:41:48 +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 DECF328425 for ; Sun, 22 May 2022 09:41:47 +0200 (CEST) Received: from localhost ([::1]:50182 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsgDi-0000dK-H7 for larch@yhetil.org; Sun, 22 May 2022 03:41:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56550) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsgCk-0000d6-9z for emacs-orgmode@gnu.org; Sun, 22 May 2022 03:40:46 -0400 Received: from ciao.gmane.io ([116.202.254.214]:44634) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsgCa-0004Mq-Rv for emacs-orgmode@gnu.org; Sun, 22 May 2022 03:40:38 -0400 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1nsgCY-00051i-0j for emacs-orgmode@gnu.org; Sun, 22 May 2022 09:40:34 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: emacs-orgmode@gnu.org From: Max Nikulin Subject: Re: [PATCH] Re: Bug in 9.5.3 org--file-default-apps Date: Sun, 22 May 2022 14:40:25 +0700 Message-ID: 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> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Content-Language: en-US In-Reply-To: <87h75ip5r6.fsf@localhost> Received-SPF: pass client-ip=116.202.254.214; envelope-from=geo-emacs-orgmode@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: 28 X-Spam_score: 2.8 X-Spam_bar: ++ X-Spam_report: (2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1, FORGED_MUA_MOZILLA=2.309, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, NICE_REPLY_A=-0.001, NML_ADSP_CUSTOM_MED=0.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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=1653205307; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=rlwUS7POEvxFjUsJcLJDSyOWs8VjClhOKW+9v4tdg30=; b=sJ+XRhqDjQjzQOcm7yV4969dVSUc2ZgB+t9f/P6EDKLEnQGz/RkWBstkjT4fh8Wx1DbVvc nRKMICuno6Bo0OsFVef+HPAVpyKtf1G+mb+iU0vLROuh607WNGJwTCpV/Jks7Wwpn/DH10 8Kt51ZAi15OEtjDxfl6/OqmcP4qH6Z1vbXyeer88fsYKsjd0q25VwkkLsNXJkEl9QeiuxK 8lq5F/8AYs/ruWf1aOEoIMiWvgb2kp0nIPGih2BuvgZqeA0+znpuCC5FMAWixBKJz7NBys haMDKSe3tJBUXZcCLEb5TyQ5rmoZ4iqgAnaLGuDtjRWM4QNzyMdlJuSjEWYiKw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1653205307; a=rsa-sha256; cv=none; b=cSaN3r9O6P1FF+LBErqgUbwbYdpUPuq3Ov9lG01ZmE7BGUAtxVHKA2nFpHMNuhT/7sVfTm vDmNBd+S/EhuY1cox4zo7snh/n/KWPtfI/J6vA1H12zcehngyWmBwrc2vomESKjHb1IP/z udB99+emxN2nJNB+Psy8hmaNpnIgScOq8V9q684B9gtS6VLXJ0qJjjlYQwf5j+fqWzQu6L Pc+1hZXWggPdtBLX9SEbyOy4Y5z1eZHzIWHnuwfb+pVzFYEwGO+pfY00QsY2dUpWDzMrfR miTCQKwH9QWb8BlPgePhTRQgl6TXzOSEaGd3mOX/DD/aGGAO5zkEY8Lfw+s6iw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); 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: 2.65 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); 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: DECF328425 X-Spam-Score: 2.65 X-Migadu-Scanner: scn0.migadu.com X-TUID: J8qQOH5r2PhC 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 do not think that Craig really wants a new emacs session for every followed link: application/x-shellscript; emacs27 %s; test=test -n "$DISPLAY" > 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. > 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)) 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]] 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. > + (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