Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 0B995431FB6 for ; Fri, 28 Jan 2011 12:25:35 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -2.3 X-Spam-Level: X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3ZZTxGc8hlIW for ; Fri, 28 Jan 2011 12:25:34 -0800 (PST) Received: from ipex1.johnshopkins.edu (ipex1.johnshopkins.edu [162.129.8.141]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 4D20F431FB5 for ; Fri, 28 Jan 2011 12:25:34 -0800 (PST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvQEAJ+1Qk0KoSAO/2dsb2JhbACWZI8SsgyIaYVPBIUYhw8 X-IronPort-AV: E=Sophos;i="4.60,394,1291611600"; d="scan'208";a="43230333" Received: from watt.hwcampus.jhu.edu ([10.161.32.14]) by ipex1.johnshopkins.edu with ESMTP/TLS/ADH-AES256-SHA; 28 Jan 2011 15:25:28 -0500 Received: by watt.hwcampus.jhu.edu (Postfix, from userid 502) id 6711F789974; Fri, 28 Jan 2011 15:25:28 -0500 (EST) From: Jesse Rosenthal To: notmuch@notmuchmail.org Subject: A tool for printing from notmuch User-Agent: Notmuch/0.5-56-g74cb76a (http://notmuchmail.org) Emacs/23.2.1 (x86_64-apple-darwin) Date: Fri, 28 Jan 2011 15:25:28 -0500 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Jan 2011 20:25:35 -0000 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
 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