A tool for printing from notmuch

Jesse Rosenthal jrosenthal at jhu.edu
Fri Jan 28 12:25:28 PST 2011


Dear all,

Printing from notmuch is a bit of a pain. Muttprint doesn't really help
much, because it can't handle multiparts well, doesn't know what to do
with html, and will print out pages of base64 if you have
attachments. And more often than not, what I need to print is an HTML
email (a bus ticket or something).

A solution I've been working on for my own use is here:

http://commonmeasure.org/~jkr/notmuchprint

It's a python script that takes a message-id and sends printable html to
your browser or stdout. Plain text is put in <pre> tags, html mails are,
as much as possible, left alone, except for the headers at the top. You
can configure (in ~/.notmuchprintrc) the font for plain text emails,
what browser to use, whether to view automatically or output html, and
whether or not to prefer plain text if both are available. (Since it's
mainly html emails I need to print or view, I set the last one to no.)
It also has a few command line options. Type "--help" to get the scoop.

The only requirement outside of the stdlib is BeautifulSoup, to deal
with email html.

It's been working well for me. I have the following in my .emacs so I
can use it from show mode by pressing "z":

(define-key notmuch-show-mode-map "z" 
  '(lambda () (interactive)
     (shell-command (concat "notmuchprint '"
			    (notmuch-show-get-message-id) 
			    "'"))))

The single-quotes are necessary for msg-ids with dollar-signs and
whatnot in them.

A couple of points:

1. The HTML generation is intentionally pretty primitive. First, I
didn't want to spend too much time on what is just a header box. Second,
I didn't want to introduce any CSS that might screw with whatever
godawful styles the email has. I'd welcome someone fixing this part up,
but I still think a goal should be to make sure html emails remain
unchanged.

2. It uses json instead of the python bindings for two reasons. First,
for my own personal use-case (remote) the bindings wouldn't have
helped. Second, I'm guessing that the slowdown from getting json output
is more than compensated for by having gmime do the parsing instead of
python.

Anyway, if people find this useful, or want to make changes, I'll make a
git repo. For now, though, I just wanted to share it, since it's been
making my life a bit easier.

Best,
Jesse


More information about the notmuch mailing list