* 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
* Re: A tool for printing from notmuch
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-29 19:58 ` Sebastian Spaeth
1 sibling, 1 reply; 8+ messages in thread
From: Andreas Amann @ 2011-01-28 20:59 UTC (permalink / raw)
To: Jesse Rosenthal, notmuch
Dear Jesse,
> 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
Thanks, that sounds great! I have been waiting for something like this
...
Unfortunately I could not get it to work with python2.7:
Traceback (most recent call last):
File "/home/amann/local/bin/notmuchprint", line 284, in <module>
main(config)
File "/home/amann/local/bin/notmuchprint", line 238, in main
VIEW_IN_BROWSER = config.getboolean('DEFAULT', 'view_in_browser')
File "/usr/lib/python2.7/ConfigParser.py", line 360, in getboolean
v = self.get(section, option)
File "/usr/lib/python2.7/ConfigParser.py", line 581, in get
return self._interpolate(section, option, value, d)
File "/usr/lib/python2.7/ConfigParser.py", line 621, in _interpolate
if value and "%(" in value:
TypeError: argument of type 'bool' is not iterable
is this a known problem, or am I missing something obvious?
Next I commented out the offending line via
VIEW_IN_BROWSER = False
however still no luck:
Traceback (most recent call last):
File "/home/amann/local/bin/notmuchprint", line 284, in <module>
main(config)
File "/home/amann/local/bin/notmuchprint", line 263, in main
nm_msg = NotmuchMsg(msgid, config)
File "/home/amann/local/bin/notmuchprint", line 58, in __init__
self.json_thread = json.loads(json_string)
File "/usr/lib/python2.7/json/__init__.py", line 326, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 360, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 378, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
Any hints?
Andreas
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: A tool for printing from notmuch
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
0 siblings, 2 replies; 8+ messages in thread
From: Jesse Rosenthal @ 2011-01-28 21:11 UTC (permalink / raw)
To: Andreas Amann, notmuch
Hi Andreas,
On Fri, 28 Jan 2011 20:59:06 +0000, Andreas Amann <a.amann@ucc.ie> wrote:
> Unfortunately I could not get it to work with python2.7:
>
> Traceback (most recent call last):
> File "/home/amann/local/bin/notmuchprint", line 284, in <module>
> main(config)
> File "/home/amann/local/bin/notmuchprint", line 238, in main
> VIEW_IN_BROWSER = config.getboolean('DEFAULT', 'view_in_browser')
> File "/usr/lib/python2.7/ConfigParser.py", line 360, in getboolean
> v = self.get(section, option)
> File "/usr/lib/python2.7/ConfigParser.py", line 581, in get
> return self._interpolate(section, option, value, d)
> File "/usr/lib/python2.7/ConfigParser.py", line 621, in _interpolate
> if value and "%(" in value:
> TypeError: argument of type 'bool' is not iterable
...
Hmm... looks like a problem with ConfigParser. Maybe the default values
aren't working well?
Try setting up a ~/.notmuchprintrc:
notmuch_command: "/usr/local/bin/notmuch"
browser_command: "/usr/bin/firefox"
plain_text_font: "sans-serif"
always_prefer_plaintext: no
view_in_browser: yes
If that works, I need to futz with its defaults a bit. (Also, I just
noticed that I named a config boolean with the same name as a function:
view_in_browser. That shouldn't be the problem here, but I should fix it
all the same.)
Best,
Jesse
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: A tool for printing from notmuch
2011-01-28 21:11 ` Jesse Rosenthal
@ 2011-01-28 21:17 ` Jesse Rosenthal
2011-01-28 23:01 ` Andreas Amann
1 sibling, 0 replies; 8+ messages in thread
From: Jesse Rosenthal @ 2011-01-28 21:17 UTC (permalink / raw)
To: Andreas Amann, notmuch
On Fri, 28 Jan 2011 16:11:00 -0500, Jesse Rosenthal <jrosenthal@jhu.edu> wrote:
> Hmm... looks like a problem with ConfigParser. Maybe the default values
> aren't working well?
Yep, that was the problem. It turns out it doesn't take True and False
as defaults -- needs strings ("yes", "no", "true", "false) or 1 or
0. Anyway, I fixed that. Thanks, Andreas!
Best,
Jesse
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: A tool for printing from notmuch
2011-01-28 21:11 ` Jesse Rosenthal
2011-01-28 21:17 ` Jesse Rosenthal
@ 2011-01-28 23:01 ` Andreas Amann
1 sibling, 0 replies; 8+ messages in thread
From: Andreas Amann @ 2011-01-28 23:01 UTC (permalink / raw)
To: Jesse Rosenthal, notmuch
On Fri, 28 Jan 2011 16:11:00 -0500, Jesse Rosenthal <jrosenthal@jhu.edu> wrote:
>
> Hmm... looks like a problem with ConfigParser. Maybe the default values
> aren't working well?
>
> Try setting up a ~/.notmuchprintrc:
>
> notmuch_command: "/usr/local/bin/notmuch"
> browser_command: "/usr/bin/firefox"
> plain_text_font: "sans-serif"
> always_prefer_plaintext: no
> view_in_browser: yes
It works! Very nice and thanks a lot!
>
> If that works, I need to futz with its defaults a bit. (Also, I just
> noticed that I named a config boolean with the same name as a function:
> view_in_browser. That shouldn't be the problem here, but I should fix it
> all the same.)
I was confused by that coincidence as well ...
Best,
Andreas
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: A tool for printing from notmuch
2011-01-28 20:25 A tool for printing from notmuch Jesse Rosenthal
2011-01-28 20:59 ` Andreas Amann
@ 2011-01-29 19:58 ` Sebastian Spaeth
2011-01-29 20:09 ` Jesse Rosenthal
1 sibling, 1 reply; 8+ messages in thread
From: Sebastian Spaeth @ 2011-01-29 19:58 UTC (permalink / raw)
To: Jesse Rosenthal, notmuch
[-- Attachment #1: Type: text/plain, Size: 472 bytes --]
On Fri, 28 Jan 2011 15:25:28 -0500, Jesse Rosenthal <jrosenthal@jhu.edu> wrote:
> Dear all,
>
> Printing from notmuch is a bit of a pain.
Hi Jesse,
that sounds like a fantastic solution and I will look into it, so far I
have been printing the buffers which does not include attachments at
all.
I prefer to not have dependencies outside the std lib in python, but for
xml/html parsing, there is really nothing appropriate, it seems.
Thanks
Sebastian
[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: A tool for printing from notmuch
2011-01-29 19:58 ` Sebastian Spaeth
@ 2011-01-29 20:09 ` Jesse Rosenthal
2011-01-29 20:20 ` Sebastian Spaeth
0 siblings, 1 reply; 8+ messages in thread
From: Jesse Rosenthal @ 2011-01-29 20:09 UTC (permalink / raw)
To: Sebastian Spaeth, notmuch
Hi Sebastian,
On Sat, 29 Jan 2011 20:58:53 +0100, Sebastian Spaeth <Sebastian@SSpaeth.de> wrote:
> I prefer to not have dependencies outside the std lib in python, but for
> xml/html parsing, there is really nothing appropriate, it seems.
I agree. And I'll admit I mainly chose BeautifulSoup out of
familiarity. But you really can't count on email html being well-formed
-- just vaguely renderable. And you certainly can't count on it being
xhtml. So the built-in parsers wouldn't be of much help. And, in fact,
if someone pastes a Word doc into Outlook, then the MS-specific tags and
styles will even choke libtidy.
So BS is the best I could find for this job (putting a title into the
header and a table into the top of the body or html that might or might
not even have a header or a body tag). And it's always available in
Debian/Arch/Fedora/ports/MacPorts.
The alternative, since we're trying leaving the email's html alone, is
to do our business with splits and regexes. But that seems like a bad
road to head down.
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).