Standardize BROWSER and MAILER environment variables.

Slatian baschdel at disroot.org
Tue Nov 28 18:32:19 UTC 2023


Hello again,

> There's also sensible-browser from the sensible-utils project.
> 
>    https://salsa.debian.org/debian/sensible-utils

Thanks for the pointer to the sensible-utils which point to the 
[environ(7) manpage]:

 > The user's preferred utility to {do something}. Any string acceptable 
 > as a command_string operand to the `sh -c` command shall be valid.

This already describes pretty well the correct way to use EDITOR and 
PAGER variables which seems to be compatible with how sensible-utils 
(and many others) interpret the BROWSER variable.

```
sh -c "$BROWSER \"\$@\"" BROWSER "$@"
```

For trying other openers the sensible-utils solution is to only do that 
on a 127 or 126 exit code meaning that the command was not found or not 
executable.

For more complex use-cases previously covered by %s or `:`-fallback a 
specification should recommend wrapper scripts as naive implementations 
may not even interpret the shell syntax correctly.

---

As for the MAILER … E-Mail is a mess on this level too.

The most though probably went into the [LibreOffice senddoc.sh script].

All of them have in common, that they either directly or some
`--compose` (or similar) option accept a mailto: URI and are probably 
well off by being treated like described for the BROWSER variable.

Which illustrates that most mailers do one of the following:

* Accept an `attach[ment]=` option for the `mailto:` URI
   (Which is a security problem)
* Have an `--attach` option for their cli (kmail,sylpheed,claws)
* Have a `-a` option for their cli (dtmail, mutt)
* Have a proprietary interface for doing attachments (thunderbird)
* Don't have an interface for attachments at all

My favorite here is the `--attach` option as it seems to be one of the 
more common options while not being very ambiguous (opposed to `-a`).
It is also used by the LibreOffice wrapper itself and
xdg-email (though xdg-email isn't very smart about using it).
It is unfortunately not supported by any implementation of
`/usr/bin/mail` I could find.

---

[environ(7) manpage]:
	https://manpages.debian.org/bookworm/manpages/environ.7.en.html

[libreoffice senddoc script]:
	https://sources.debian.org/src/libreoffice/4:7.6.3-2/shell/source/unix/misc/senddoc.sh

---

To summarize:

Both BROWSER and MAILER should follow the definition from the environ(7) 
manpage:
 > The user's preferred utility to {do something}. Any string acceptable 
 > as a command_string operand to the `sh -c` command shall be valid.

The MAILER in addition SHOULD support an `--attach` option that is 
followed by one file path or `file:` URI, multiple instances should be 
possible after the `mailto:` URI.

```
$MAILER mailto:… [--attach …]...
```

---

Looking forward to feedback on this take.

Greetings!

- Slatian


More information about the xdg mailing list