From 0f29d9f2912573e696b9cb6019cb036246d7d21e Mon Sep 17 00:00:00 2001 From: Ulrich Müller Date: Tue, 7 Mar 2023 18:26:48 +0100 Subject: x11-misc/emacs-desktop-mail: Backslash-escape '\' and '"' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Escape any backslash and double quote characters, before passing the URI to emacsclient. Signed-off-by: Ulrich Müller --- .../emacs-desktop-mail-1.1.ebuild | 54 ------------------- .../emacs-desktop-mail-1.2.ebuild | 61 ++++++++++++++++++++++ 2 files changed, 61 insertions(+), 54 deletions(-) delete mode 100644 x11-misc/emacs-desktop-mail/emacs-desktop-mail-1.1.ebuild create mode 100644 x11-misc/emacs-desktop-mail/emacs-desktop-mail-1.2.ebuild diff --git a/x11-misc/emacs-desktop-mail/emacs-desktop-mail-1.1.ebuild b/x11-misc/emacs-desktop-mail/emacs-desktop-mail-1.1.ebuild deleted file mode 100644 index 92d93860fb2f..000000000000 --- a/x11-misc/emacs-desktop-mail/emacs-desktop-mail-1.1.ebuild +++ /dev/null @@ -1,54 +0,0 @@ -# Copyright 1999-2022 Gentoo Authors -# Distributed under the terms of the GNU General Public License v2 - -EAPI=8 -NEED_EMACS=28 - -inherit elisp desktop xdg-utils - -DESCRIPTION="Desktop entries for handling mailto URIs with GNU Emacs" -HOMEPAGE="https://wiki.gentoo.org/wiki/Project:Emacs" -S="${WORKDIR}" - -LICENSE="GPL-2+" -SLOT="0" -KEYWORDS="~amd64 ~x86" - -src_compile() { :; } - -src_install() { - newmenu - emacs-mail.desktop <<-EOF - [Desktop Entry] - Type=Application - Name=GNU Emacs (mail) - NoDisplay=true - Exec=${EPREXIX}/usr/bin/emacs -f message-mailto %u - Terminal=false - MimeType=x-scheme-handler/mailto; - EOF - - # The Desktop Entry Specification does not allow field codes like %u - # inside a quoted argument, therefore we need a shell wrapper. - # We want to pass a literal '"(message-mailto \"$1\")"' in the -c - # command, but in the desktop entry '"', '\', and '$' must be escaped - # as '\\"', '\\\\', and '\\$', respectively. Yet another level of - # backslash escapes is needed for '\' and '$' in the here-document. - newmenu - emacsclient-mail.desktop <<-EOF - [Desktop Entry] - Type=Application - Name=Emacsclient (mail) - NoDisplay=true - Exec=${EPREFIX}/bin/bash -c "exec ${EPREFIX}/usr/bin/emacsclient \ ---eval \\\\"(message-mailto \\\\\\\\\\\\"\\\\\$1\\\\\\\\\\\\")\\\\"" bash %u - Terminal=false - MimeType=x-scheme-handler/mailto; - EOF -} - -pkg_postinst() { - xdg_desktop_database_update -} - -pkg_postrm() { - xdg_desktop_database_update -} diff --git a/x11-misc/emacs-desktop-mail/emacs-desktop-mail-1.2.ebuild b/x11-misc/emacs-desktop-mail/emacs-desktop-mail-1.2.ebuild new file mode 100644 index 000000000000..aa83394f2032 --- /dev/null +++ b/x11-misc/emacs-desktop-mail/emacs-desktop-mail-1.2.ebuild @@ -0,0 +1,61 @@ +# Copyright 1999-2023 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=8 +NEED_EMACS=28 + +inherit elisp desktop xdg-utils + +DESCRIPTION="Desktop entries for handling mailto URIs with GNU Emacs" +HOMEPAGE="https://wiki.gentoo.org/wiki/Project:Emacs" +S="${WORKDIR}" + +LICENSE="GPL-2+" +SLOT="0" +KEYWORDS="~amd64 ~x86" + +src_compile() { :; } + +src_install() { + newmenu - emacs-mail.desktop <<-EOF + [Desktop Entry] + Type=Application + Name=GNU Emacs (mail) + NoDisplay=true + Exec=${EPREXIX}/usr/bin/emacs -f message-mailto %u + Terminal=false + MimeType=x-scheme-handler/mailto; + EOF + + # The Desktop Entry Specification does not allow field codes like %u + # inside a quoted argument, therefore we need a shell wrapper. + # We pass the following commands to it, in order to backslash-escape + # any special characters '\' and '"' that occur in %u: + # u=${1//\\/\\\\} + # u=${u//\"/\\\"} + # exec emacsclient --eval "(message-mailto \"$u\")" + # However, in the desktop entry '"', '\', and '$' must be escaped + # as '\\"', '\\\\', and '\\$', respectively. Yet another level of + # backslash escapes is needed for '\' and '$' in the here-document. + newmenu - emacsclient-mail.desktop <<-EOF + [Desktop Entry] + Type=Application + Name=Emacsclient (mail) + NoDisplay=true + Exec=${EPREFIX}/bin/bash -c \ +"u=\\\\\${1//\\\\\\\\\\\\\\\\/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\}; \ +u=\\\\\${u//\\\\\\\\\\\\"/\\\\\\\\\\\\\\\\\\\\\\\\\\\\"}; \ +exec ${EPREFIX}/usr/bin/emacsclient \ +--eval \\\\"(message-mailto \\\\\\\\\\\\"\\\\\$u\\\\\\\\\\\\")\\\\"" bash %u + Terminal=false + MimeType=x-scheme-handler/mailto; + EOF +} + +pkg_postinst() { + xdg_desktop_database_update +} + +pkg_postrm() { + xdg_desktop_database_update +} -- cgit v1.2.3-18-g5258