[Portland] [PATCH 2/2] xdg-email: learn XDG_MAILER variable

Jonathan Nieder jrnieder at gmail.com
Thu Sep 30 17:18:17 PDT 2010


On systems with no desktop environment, there is currently no way to
configure the default mailer separately from the default browser.
This makes it difficult to set an appropriate handler for mailto:
links when the browser (like chromium) defers to xdg utils for the
mailer rather than providing its own configuration mechanism.

The configuration mechanism is simple: to launch the mail composer,
xdg-email will just run

	<mailer> <mailto-URL>

in the shell, where <mailer> is the value of the XDG_MAILER
environment variable and <mailto-URL> is a run-of-the-mill mailto: URL
of the sort that Mozilla would accept.

The envvar is named XDG_MAILER, not MAILER, to leave open the
possibility for some standardized MAILER variable in the future like
the current BROWSER.  This variable is not it, because:

 - many mail composers (e.g., mutt) do not currently accept mailto
   URLs and thus require a wrapper script

 - passing the body of a draft email on the command line is not
   a great idea, since one runs into command line length limits
   rather quickly

But for now, this convention is just the thing.

Examples:

 XDG_MAILER=/usr/lib/mutt/mailto-mutt
 XDG_MAILER=thunderbird
 XDG_MAILER=\
 'sh -c '\''emacsclient -a "" -n -c -e "(mailto-url-gnus \"$1\" t t)"'\'''
---
 scripts/desc/xdg-email.xml |   11 ++++++++---
 scripts/xdg-email.in       |    8 ++++++++
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/scripts/desc/xdg-email.xml b/scripts/desc/xdg-email.xml
index 9d848ff..a1ac3c2 100755
--- a/scripts/desc/xdg-email.xml
+++ b/scripts/desc/xdg-email.xml
@@ -251,9 +251,14 @@
     <refsect2 id="generic_config">
       <title>No desktop environment</title>
       <para>
-        If no desktop environment is in use, xdg-email will use
-        the browser set through the BROWSER environment variable
-        as an e-mail composer (with syntax the same as in xdg-open).
+        Set the XDG_MAILER variable in ~/.profile or ~/.pam_environment
+        to an email composer taking a mailto: URL as an argument.
+      </para>
+      <para>
+        If no desktop environment is in use and XDG_MAILER is not set,
+        xdg-email will use the browser set through the BROWSER
+        environment variable as an e-mail composer (with syntax
+        the same as in xdg-open).
       </para>
     </refsect2>
     <refsect2 id="config_see_also">
diff --git a/scripts/xdg-email.in b/scripts/xdg-email.in
index 4dbc26c..33bee0b 100755
--- a/scripts/xdg-email.in
+++ b/scripts/xdg-email.in
@@ -158,6 +158,14 @@ open_xfce()
 
 open_generic()
 {
+    if [ "${XDG_MAILER:+set}" ]; then
+        if eval "$XDG_MAILER" '"$@"'; then
+            exit_success
+        else
+            exit_failure_operation_failed
+        fi
+    fi
+
     IFS=":"
     for browser in $BROWSER; do
         if [ x"$browser" != x"" ]; then
-- 
1.7.2.3



More information about the Portland mailing list