From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id QGX0Bqb6/2G0ugAAgWs5BA (envelope-from ) for ; Sun, 06 Feb 2022 17:43:18 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id EHOIA6b6/2G1cQAAauVa8A (envelope-from ) for ; Sun, 06 Feb 2022 17:43:18 +0100 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 D43E129ACE for ; Sun, 6 Feb 2022 17:43:17 +0100 (CET) Received: from localhost ([::1]:41814 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nGkdA-0000Jn-Se for larch@yhetil.org; Sun, 06 Feb 2022 11:43:16 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55614) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nGkcT-0000JP-GN for emacs-orgmode@gnu.org; Sun, 06 Feb 2022 11:42:33 -0500 Received: from ciao.gmane.io ([116.202.254.214]:49916) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nGkcR-0007QG-HB for emacs-orgmode@gnu.org; Sun, 06 Feb 2022 11:42:33 -0500 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1nGkcG-0005td-58 for emacs-orgmode@gnu.org; Sun, 06 Feb 2022 17:42:20 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: emacs-orgmode@gnu.org From: Max Nikulin Subject: Re: Lazy load of org-protocol Date: Sun, 6 Feb 2022 23:42:11 +0700 Message-ID: References: <9b140f0a-c75e-cf00-0f83-67e5a660935c@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Content-Language: en-US In-Reply-To: <9b140f0a-c75e-cf00-0f83-67e5a660935c@gmail.com> 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.25, 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-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1644165797; 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=PmUTkiRqT6cNFLAMl1iRki0Mi9UOzUuYCLvFtfzxCG4=; b=ukUBkysMwwdeseffCrXFrEHTQBwLlXehkyzQqjjMEgmTKb3mQO6yFrRZg2bf+9hueZzLtV Uvafp/g5jDWi9WyWWdLZOd7v0+A3f5n1Ekn8oLir12Pr+YxfoYn3QNrfPkfhZ+UUQXqWAG MPnk/iGhEMbsSPsGzekEGKtiJtJPyLzr+JKu8DyMdGx/MaLIkSJzAv3TwhA3oEHQ4V4sdU bT1z55rNQ6FhbMjwforVGJzHBONazSotz9J9WIWse8FMeJDeHIHB5Mf/aM0OMhTCR0oowR MKBp8LpdGW2TdI3Psfjbroj6dM+4DjPV5fbiGpeD3okzjNL2mmpmco+o3J03KQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1644165797; a=rsa-sha256; cv=none; b=TRpSIu1s1enWtJVgLEjrsf6GoTN/WxMOgV0HcBynhlWJwu0sZwfNNB1bTQRlmo/3tMUio1 lNveOgebeixUlXOCGPz5WNk1Bk5JRDlOz5GnK/7WDDrUu3uq3OepIf5GXkZ0c6M/ZkO+gT nO5u3RdTsrVGXDjoc3vSI4FEaxrRIMVb8lLwF20DMHub84NVgDvP9UHjSiC5Rqeu2ySsh1 vQcQQK/0nP29Ko4xumPwt66VimL9eL5x7av+lBNYR8DN9EDmObfb2DKLj/zk3J/5wz828S FkXkeM9sFlJn+Y7H+7/TRGakye25tE1m69nNGSgRWTH3vpNNuZhV0bIVhlQ5Fw== 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.53 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: D43E129ACE X-Spam-Score: -2.53 X-Migadu-Scanner: scn1.migadu.com X-TUID: MTt+xkev/oFx On 06/02/2022 01:27, Jim Porter wrote: > On 2/5/2022 3:54 AM, Max Nikulin wrote: > etc/emacsclient-mail.desktop in the Emacs repo does this.) The command > to use for a new Emacs instance is simple: > >   emacs -f message-mailto %u > > However, doing this for emacsclient is harder: > >   emacsclient --alternate-editor= --create-frame --eval > "(message-mailto \\"%u\\")" > > There's no problem with "--alternate-editor=" and "--create-frame", but > the fact that emacsclient requires evaling the function call that way > is: if %u holds a string with quotation marks, this will break, and > worse, could even result in arbitrary code being executed. (In practice, > this is probably rare, since URLs are generally URL-encoded, and so > don't have literal quotes in them.) Thank you for suggesting another use case. Quoting issues was the reason why I started to search a better way. There should be an easy and safe means to pass argument from command line to evaluated expressions similar to shell sh -c 'echo "$1"' example 'Hello, World!' Some people could not even choose proper quotes for shell command: https://www.reddit.com/r/emacs/comments/hhbcg7/emacsclient_eval_with_command_line_arguments/ https://stackoverflow.com/questions/8848819/emacs-eval-ediff-1-2-how-to-put-this-line-in-to-shell-script First recipe and the accepted answer in second source solves the obvious problem but they miss escaping for elisp expression. Another answer on stackoverflow is more accurate, it suggests quoted1=${1//\\/\\\\}; quoted1=${quoted1//\"/\\\"} I suppose, these links is a good illustration that substitution of arbitrary argument into lisp expression is harder than it should be to help users to avoid security issues. > As a result, I think a good first step might be to add support for > "--funcall" to emacsclient, just like the regular emacs binary. (The > "-f" shorthand won't work though, since emacsclient already uses that > for "--server-file"). This would simplify the `message-mailto' case > above and would also allow org-protocol to do something similar: > >   emacsclient --funcall org-protocol-capture %u No, --funcall is just a sugar for --eval '(func)' that does not contain arbitrary input, but func has no access to other arguments and it is the real problem. I think, the solution is to add -arg command to emacs server protocol that pushes its argument to a list and extend -exec command that would make such list available as argv or as `command-line-args-left' for evaluated expression. Of course, emacsclient option parser should be modified as well to support --arg option emacsclient --eval '(func)' --arg 1 2 3 emacsclient --eval '(func)' --arg -- 1 2 3 and maybe even for multiple eval+arg pairs emacsclient --eval '(f1)' --arg 'a1' --eval '(f2)' --arg 'a2' 'a3' The proper place to discuss idea is emacs-devel list, but I am afraid that without a patch it will be just buried. >   emacsclient --eval "(org-protocol-capture \\"%u\\")" Due to quoting issues a small wrapper may be safer (modulo -a, -c) emacsclient --eval "(require 'org-protocol)" emacsclient -- "$@"