Package: mailcap
Version: 3.70+nmu1
During processing media type handlers from .desktop files, the
update-mime tool does not escapes ";" in Exec entries when it creates
mailcap entries. As a result, tools reading mailcap files treat command
part after first semicolon as flags.
See
https://lists.debian.org/msgid-search/6328be76-2961-49f9-abd4-9e79ba26c...@dybdal.dk
Bookworm's /etc/mailcap seems to break s-nail.
debian-user, Mon, 6 May 2024 14:53:10 +0200
For example, Emacs uses rather complex commands to explicitly pass
DISPLAY value to emacs server and to escape arguments of --eval commands:
grep Exec /usr/share/applications/emacsclient*
/usr/share/applications/emacsclient.desktop:Exec=sh -c "if [ -n
\\"\\$*\\" ]; then exec emacsclient --alternate-editor=
--display=\\"\\$DISPLAY\\" \\"\\$@\\"; else exec emacsclient
--alternate-editor= --create-frame; fi" sh %F
/usr/share/applications/emacsclient-mail.desktop:Exec=bash -c
"u=\\${1//\\\\\\\\/\\\\\\\\\\\\\\\\}; u=\\${u//\\\\\\"/\\\\\\\\\\\\\\"};
exec emacsclient --alternate-editor= --display=\\"\\$DISPLAY\\" --eval
\\"(message-mailto \\\\\\"\\$u\\\\\\")\\"" bash %u
/usr/share/applications/emacsclient-mail.desktop:Exec=bash -c
"u=\\${1//\\\\\\\\/\\\\\\\\\\\\\\\\}; u=\\${u//\\\\\\"/\\\\\\\\\\\\\\"};
exec emacsclient --alternate-editor= --create-frame --eval
\\"(message-mailto \\\\\\"\\$u\\\\\\")\\"" bash %u
To reproduce the issue you may use the following file (replace emacs
with xterm, xmessage, etc., name is chosen to get high priority).
---- 8< ---- /usr/share/applications/a-bug-mailcap.desktop
[Desktop Entry]
Name=A Bug Mailcap
Type=Application
Icon=emacs
Comment=Semicolon escaping in mailcap entries
Exec=sh -c "if ! emacs -Q --title IF \\"\\$1\\"; then emacs -Q --title
ELSE; fi" sh-c %f
MimeType=text/x-java;
---- >8 ----
run update-mime
run-mailcap --debug --norun "test.java"
# ...
Processing file "test.java" of type "text/x-java" (encoding=none)...
- checking mailcap entry "text/x-java; sh -c "if ! emacs -Q --title IF
\\"\\$1\\"; then emacs -Q --title ELSE; fi" sh-c %s; test=test -n
"$DISPLAY""
- program to execute: sh -c "if ! emacs -Q --title IF \\"\\$1\\"
- running test: test -n "$DISPLAY" (result=0=true)
- filename contains shell meta-characters; aliased to
'/tmp/tmp.YK5LRgdFPM'
- executing: sh -c "if ! emacs -Q --title IF \"\$1\" </tmp/tmp.YK5LRgdFPM
sh -c "if ! emacs -Q --title IF \"\$1\" </tmp/tmp.YK5LRgdFPM
If backslash added before 2 semicolons in the command in /etc/mailcap
then run-mailcap pass proper command (quoted semicolons are logged as
invalid UTF-8 characters):
- program to execute: sh -c "if ! emacs -Q --title IF \\"\\$1\\"� then
emacs -Q --title ELSE� fi" sh-c %s
- running test: test -n "$DISPLAY" (result=0=true)
- filename contains shell meta-characters; aliased to
'/tmp/tmp.SrojfTimdb'
- executing: sh -c "if ! emacs -Q --title IF \"\$1\"; then emacs -Q
--title ELSE; fi" sh-c /tmp/tmp.SrojfTimdbsh -c "if ! emacs -Q --title
IF \"\$1\"; then emacs -Q --title ELSE; fi" sh-c /tmp/tmp.SrojfTimdb
Not being a perl programmer, I expect in ReadDesktopEntries in
update-mime something like
# Ensure odd number of backslashes before semicolons.
exec =~ s/((?:\\\\)*)\\?(;)/\1\\\2/g;
However I expect more issues since I have not noticed code converting
\s, \n, \r, \t escapes, see
https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s04.html
"Possible value types" in Desktop Entry Specification
Likely a more complex function is necessary to unquote Exec value from
.desktop files and to properly escape the result for shell and mailcap.
Please, either fix quoting of semicolons or ignore complex commands.
P.S. BASH fallback code in xdg-open has even more severe issues with
parsing of complex Exec entries. Fortunately, for most of users it
delegates handling of URIs to desktop environments.