2025-08-21
Tags: emacs
(IMG) image
I have a slight problem wherein every time I start up a game of
NetHack, I completely lose touch with my surroundings for hours on
end.
Thankfully The DevTeam Thinks Of Everything [1] and there's a
solution that allows communication with the outside world without
breaking immersion: the mail daemon!
If compiled with [40m`-DMAIL`[49m and [40m`OPTIONS=mail`[49m is
set in your runtime configuration (the default on Linux), NetHack
will periodically check a user specified mbox file
([40m`MAIL`[49m) for new mail, and upon receiving an email a mail
daemon will spawn in and deliver a scroll of mail to the player.
Upon reading this scroll a mail program ([40m`MAILREADER`[49m)
will be executed, which hopefully allows you to read your mail.
I use the Lisp window port [2] to play NetHack (the way God
intended), and I [3mreally[23m don't like leaving Emacs, so let's
figure out how to integrate this feature with mu4e.
[40m[35m`mu`[39m[49m uses maildir [3]), not mbox [4], so I
decided to write a cron job that periodically converts my maildir
to mbox format.
An important insight is that NetHack never checks the contents of
the mailbox file, just the [40m`mtime`[49m.
Therefore all our script needs to do is check if our maildir
contains any messages received within the last n minutes, and if so
[40m[35m`touch`[39m[49m the mbox file.
[33mimport[0m[1m[37m [0m[1m[37mos[0m[1m[37m[0m
[33mimport[0m[1m[37m [0m[1m[37mmailbox[0m[1m[37m[0m
[33mfrom[0m[1m[37m [0m[1m[37mdatetime[0m[1m[37m [0m[33mimport[0m[1m[37m [0m[1m[37mdatetime[0m[1m[37m,[0m[1m[37m [0m[1m[37mtimedelta[0m[1m[37m[0m
[33mimport[0m[1m[37m [0m[1m[37mpathlib[0m[1m[37m[0m
[1m[37m[0m
[1m[37mMAILDIR[0m[1m[37m [0m[1m[36m=[0m[1m[37m [0m[1m[37mos[0m[1m[36m.[0m[1m[37mpath[0m[1m[36m.[0m[1m[37mexpanduser[0m[1m[37m([0m[33m"~/Mail/personal/INBOX"[0m[1m[37m)[0m[1m[37m[0m
[1m[37mMBOX[0m[1m[37m [0m[1m[36m=[0m[1m[37m [0m[33m"/tmp/nh.mbox"[0m[1m[37m[0m
[1m[37m[0m
[1m[37mmaildir[0m[1m[37m [0m[1m[36m=[0m[1m[37m [0m[1m[37mmailbox[0m[1m[36m.[0m[1m[37mMaildir[0m[1m[37m([0m[1m[37mMAILDIR[0m[1m[37m)[0m[1m[37m[0m
[33mfor[0m[1m[37m [0m[1m[37mmsg[0m[1m[37m [0m[1m[36min[0m[1m[37m [0m[1m[37mmaildir[0m[1m[37m:[0m[1m[37m[0m
[1m[37m [0m[33mif[0m[1m[37m [0m[1m[37mdatetime[0m[1m[36m.[0m[1m[37mfromtimestamp[0m[1m[37m([0m[1m[37mmsg[0m[1m[36m.[0m[1m[37mget_date[0m[1m[37m())[0m[1m[37m [0m[1m[36m>[0m[1m[37m [0m[1m[37mdatetime[0m[1m[36m.[0m[1m[37mnow[0m[1m[37m()[0m[1m[37m [0m[1m[36m-[0m[1m[37m [0m[1m[37mtimedelta[0m[1m[37m([0m[1m[37mminutes[0m[1m[36m=[0m[1m[36m5[0m[1m[37m):[0m[1m[37m[0m
[1m[37m [0m[1m[37mpathlib[0m[1m[36m.[0m[1m[37mPath[0m[1m[37m([0m[1m[37mMBOX[0m[1m[37m)[0m[1m[36m.[0m[1m[37mtouch[0m[1m[37m()[0m[1m[37m[0m
[1m[37m [0m[33mbreak[0m[1m[37m[0m
[1m[37mmaildir[0m[1m[36m.[0m[1m[37mclose[0m[1m[37m()[0m[1m[37m[0m
Next, we need a script that will open up mu4e.
[1m[37memacsclient -n --eval [0m[33m"(progn (require 'mu4e) (mu4e-context-switch nil \"Personal\") (mu4e-search-bookmark \"maildir:/personal/INBOX AND flag:unread\"))"[0m[1m[37m[0m
I'm using [40m[35m`emacsclient`[39m[49m instead of plain old
[40m[35m`emacs`[39m[49m partly because only one process at a
time can hold the lock on [40m[35m`mu`[39m[49m's database, so I
don't want to spin up another Emacs process.
It's also worth mentioning that my
[40m[35m`emacsclient`[39m[49m is wrapped such that it opens a
new frame if invoked outside of Emacs and reuses the current frame
if invoked from within Emacs, so this behaves as you would expect,
even if I'm using e.g. the curses port in a separate terminal.
[37mexport[0m[1m[37m [0m[1m[36m_t[0m[1m[36m=[0m[33m'-c'[0m[1m[37m[0m
[37mexec[0m[1m[37m [0m[33m"/nix/store/...-emacs/bin/.emacsclient-wrapped"[0m[1m[37m [0m[33m"[0m[33m${[0m[1m[36m_t[0m[1m[37m/[0m[33m${[0m[1m[36mINSIDE_EMACS[0m[1m[37m:+*[0m[33m}[0m[1m[37m/-u[0m[33m}[0m[33m"[0m[1m[37m -a /nix/store/...-emacs/Applications/Emacs.app/Contents/MacOS/Emacs [0m[33m"[0m[1m[36m$@[0m[33m"[0m[1m[37m[0m
Here's some riveting gameplay footage of dungeon level 1:
(GIF) image
References:
(HTM) [1] The DevTeam Thinks Of Everything
(HTM) [2] Lisp window port
(HTM) [3] maildir
(HTM) [4] mbox
>=================================================================<
(DIR) Blog
(DIR) Writeups
(DIR) jp
copyright 2026 George Huebner
(HTM) email