How can I set mutt as the default mail client when I click on a 'mailto' in a webpage?

Solution 1:

First you need to ensure that there's a .desktop file which is required by the XDG specification. For GUI programs the chance is good that there already is a suitable .desktop file, for terminal applications usually you have to create your own one. Check out the directory /usr/share/applications for existing files. Maybe there is already a mutt.desktop file. If there isn't, create one.

Then edit the file ~/.local/share/applications/mimeapps.list and add the following line

[Default Applications]
x-scheme-handler/mailto=mutt.desktop;

This registers mutt with the mailto handler. You can confirm a successful registration with

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

which should output mutt.desktop. Now you can click on “mailto” in chromium and a terminal should pop up with a mutt instance. No need to even restart the desktop session or the browser.

Solution 2:

You need to write a script that's specifies the terminal that you want mutt to open in. Then, in Firefox, you can associate this script with mailto links. For example, if you are using terminator, you can create the following script.

#!/usr/bin/env bash
terminator -x "mutt '$@'"

In my case, I have a persistent drop-down terminator, so I want it in a new tab. I also need a 256 colour palette, so I use

#!/usr/bin/env bash
terminator --new-tab -x "TERM=xterm-256color; mutt '$@'"

FWIW this is my full script, which also unhides terminator (if hidden), using the shortcut Ctrl+Space, and brings it to the front.

#!/usr/bin/env bash

terminator --new-tab -x "TERM=xterm-256color; mutt '$@'"

# If necessary, unhide and focus terminator window.
windowlist=$(xprop -root | sed -rn 's/_NET_CLIENT_LIST_STACKING\(WINDOW\): window id # (.*)/\1/p' | tr -d ',')
terminator_visible=false
for i in $windowlist; do
  [[ $(xprop -id $i | grep WM_CLASS\(STRING\)) == 'WM_CLASS(STRING) = "terminator", "Terminator"' ]] && terminator_visible=true && term_id=$i
done

if [[ $terminator_visible == false ]]; then # it's hidden
  xdotool key --clearmodifiers ctrl+space
elif [[ $(xprop -id $(xdotool getactivewindow) | grep WM_CLASS\(STRING\)) != 'WM_CLASS(STRING) = "terminator", "Terminator"' ]]; then # it's visible, but not active
  xdotool windowactivate $term_id 2> /dev/null # Gives error; not sure why. XGetWindowProperty[_NET_WM_DESKTOP] failed (code=1)
fi