Translate

Sunday 29 January 2017

Getting mailto links to work with Google Chrome and DWM

The issue here is that mailto links in Web pages should run up client email software (where installed) when clicked in Google Chrome  under Linux. However this doesn't work unless a desktop environment (like Gnome) is installed.

This blog post provides a workaround for dwm users and was tested under Ubuntu Xenial (6.04.1 LTS). It might cause mailto links to fail under other desktop environments so take a backup of your work as recommended below.

When a mailto link such as nonesuchperson@nonesuchaddress.com is selected, Google Chrome calls a program called xdg-email located in /usr/bin.

xdg-email is a script which checks to see which desktop environment (DE) is being used and then, if possible, runs up a mail compose Window in email client software like Thunderbird. It is called by Google Chrome (but not apparently by Firefox) when a mailto link is clicked. However,  if you are not using a desktop environment, Chrome just runs up an empty browser window.  

The solution I identified was to force xdg-email to think I am using the LXDE environment in which case it correctly runs my email client software (Claws Mail).

First, check to see which email client is associated on your system with a mailto link by running:

xdg-mime query default "x-scheme-handler/mailto" 

By default (and I am not sure why) this command returns the following on my system: 

thunderbird.desktop 

By adding the line

x-scheme-handler/mailto=claws-mail.desktop; 
#or thunderbird.desktop etc

to the file

 ~/.local/share/applications/mimeapps.list 

the xdg-mime command shown above now returns

claws-mail.desktop;

Next, it is necessary to force the /usr/bin/xdg-email script to think we are using the LXDE DE (you have to do this as superuser and it is wise to make a backup copy of the script). The script will then check mimeapps.list to see which email client is being used.

Within the  detect_DE()  function (line 412 in my version) replace all of the following code with just DE=lxde;

    if [ -n "${XDG_CURRENT_DESKTOP}" ]; then
      case "${XDG_CURRENT_DESKTOP}" in
         # only recently added to menu-spec, pre-spec X- still in use
         Cinnamon|X-Cinnamon)
           DE=cinnamon;
           ;;
         ENLIGHTENMENT)
           DE=enlightenment;
           ;;
         # GNOME, GNOME-Classic:GNOME, or GNOME-Flashback:GNOME
         GNOME*)
           DE=gnome;
           ;;
         KDE)
           DE=kde;
           ;;
         LXDE)
           DE=lxde;
           ;;
         MATE)
           DE=mate;
           ;;
         XFCE)
           DE=xfce
           ;;
         X-Generic)
           DE=generic
           ;;
      esac

    fi

Now run xdg-mail in a terminal window which should run up your email client software instead of an empty browser window. 

In my case the revised xdg-mail script also works under the desktop environments such as KDE and LXDE.  However, to note this is a workaround for dwm users so it might cause the script to fail in another DE.