unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* A tool for printing from notmuch
@ 2011-01-28 20:25 Jesse Rosenthal
  2011-01-28 20:59 ` Andreas Amann
  2011-01-29 19:58 ` Sebastian Spaeth
  0 siblings, 2 replies; 8+ messages in thread
From: Jesse Rosenthal @ 2011-01-28 20:25 UTC (permalink / raw)
  To: notmuch

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-01-29 20:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-28 20:25 A tool for printing from notmuch Jesse Rosenthal
2011-01-28 20:59 ` Andreas Amann
2011-01-28 21:11   ` Jesse Rosenthal
2011-01-28 21:17     ` Jesse Rosenthal
2011-01-28 23:01     ` Andreas Amann
2011-01-29 19:58 ` Sebastian Spaeth
2011-01-29 20:09   ` Jesse Rosenthal
2011-01-29 20:20     ` Sebastian Spaeth

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).