Spaceship Exim
Detecting unsent email.
This is a quick little hack, probably only useful to me, but perhaps it’ll inspire you to do something useful for you.
I use Exim to send email. (My email configuration is…complicated.) By “use exim”, I mean that I’ve configured Emacs to use Exim.
(setq sendmail-program "/usr/local/bin/exim")
It’s not really integrated into whatever MacOS does to track successfully or unsuccessfully sent messages.
Here’s what I’m looking at today:
$ exim -bp
54h 1.5K Q1QJV5-00207L-QY <ndw@nwalsh.com>
D someuser@example.org
someotheruser@example.org
My attempt to send email to someotheruser@example.org
failed
54 hours ago. On closer inspection, this message was supposed to go to
three addresses and I mangled some punctuation in the headers.
I simply don’t remember to check the queue very often so I’ve sometimes found messages days or weeks old in there. Embarrassing. I could make it visible when I reboot or when I start a new shell, but those things don’t necessarily happen often either. (New shells probably do, in fact, but nevermind.)
I’ve got one of those fancy prompt configurations installed, so my shell prompt provides a bunch of useful information. Here’s a slightly silly example:
ndw on master [⇡!?] via ⬢ v8.15.1 on 🐳 v19.03.5 via 🐍 3.7.4
$
That’s my prompt when I’m in my home directory (ndw
), which is checked
out of git ( master
),The character in front of “master” is 
. It displays as the
“code-fork” icon for me. I’m not sure what font it’s coming from; it’s
rendered in Font Awesome slightly differently, but that link will give you a
sense of the icon. Unfortunately, U+E0A0 is in the Unicode private use area and
unlikely to be displayed correctly in your browser. It looks fine for
me in Emacs and the shell. is ahead of the remote branch (⇡
), and has both
changed (!
) and untracked files (?
). I created a package.json
file, so
it’s telling me that will use Node v8.15.1; there’s a docker-compose.yml
file, so it’s telling me that will use Docker v19.03.5; and I
created foo.py
, so it’s telling me that will use Python version 3.7.4.
Obviously the thing to do is add an annotation to the prompt if there are unsent messages in the Exim queue!
Luckily, it was straightforward to hack together from the Spaceship API example:
#
# Exim
#
# Exim will display 📫 in the prompt if exim reports
# that there is unsent mail.
# ------------------------------------------------------------------------------
# Configuration
# ------------------------------------------------------------------------------
SPACESHIP_EXIM_SHOW="${SPACESHIP_EXIM_SHOW=true}"
SPACESHIP_EXIM_PREFIX=""
SPACESHIP_EXIM_SUFFIX=" "
SPACESHIP_EXIM_COLOR="${SPACESHIP_EXIM_COLOR="white"}"
SPACESHIP_EXIM_CHAR="📫"
# ------------------------------------------------------------------------------
# Section
# ------------------------------------------------------------------------------
# Show exim status
spaceship_exim() {
# If SPACESHIP_EXIM_SHOW is false, don't show exim section
[[ $SPACESHIP_EXIM_SHOW == false ]] && return
# Check if exim command is available for execution
spaceship::exists exim || return
# Show exim section only when there is unsent mail
[[ `exim -bp | wc -l` -gt 0 ]] || return
# Display exim section
spaceship::section \
"$SPACESHIP_EXIM_COLOR" \
"$SPACESHIP_EXIM_PREFIX" \
"$SPACESHIP_EXIM_CHAR" \
"$SPACESHIP_EXIM_SUFFIX"
}
I source that at the end of my ~/.zshrc
file and add exim
to
SPACESHIP_PROMPT_ORDER
just before the line separator
and now my prompt is:
ndw on master [⇡?] on 🐳 v19.03.5 📫
$
(It’s slightly more reasonable because I deleted the package.json
and foo.py
files.)
Sweet. Well, except for the busted message I have to resend. But at least I know there is a busted message now!
Share and enjoy!