A tool for printing from notmuch

2011-01-29 Thread Sebastian Spaeth
On Sat, 29 Jan 2011 15:09:14 -0500, Jesse Rosenthal  
wrote:
> So BS is the best I could find for this job

No doubt. I once tried to scrape http://theeconomist.com. It has so
broken html that all parsers broke down. BeautifulSoup at least made it
through and didn't completely fail. so I agree it is the best thing for
surely broken html email

Sebastian
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: 



A tool for printing from notmuch

2011-01-29 Thread Sebastian Spaeth
On Fri, 28 Jan 2011 15:25:28 -0500, Jesse Rosenthal  
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
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: 



A tool for printing from notmuch

2011-01-29 Thread Jesse Rosenthal
Hi Sebastian,

On Sat, 29 Jan 2011 20:58:53 +0100, Sebastian Spaeth  
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



Re: A tool for printing from notmuch

2011-01-29 Thread Sebastian Spaeth
On Sat, 29 Jan 2011 15:09:14 -0500, Jesse Rosenthal  wrote:
> So BS is the best I could find for this job

No doubt. I once tried to scrape http://theeconomist.com. It has so
broken html that all parsers broke down. BeautifulSoup at least made it
through and didn't completely fail. so I agree it is the best thing for
surely broken html email

Sebastian


pgpBf3HpzeOcB.pgp
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: A tool for printing from notmuch

2011-01-29 Thread Jesse Rosenthal
Hi Sebastian,

On Sat, 29 Jan 2011 20:58:53 +0100, Sebastian Spaeth  
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

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: A tool for printing from notmuch

2011-01-29 Thread Sebastian Spaeth
On Fri, 28 Jan 2011 15:25:28 -0500, Jesse Rosenthal  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


pgp0Up1C9zTpp.pgp
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


A tool for printing from notmuch

2011-01-28 Thread Andreas Amann
On Fri, 28 Jan 2011 16:11:00 -0500, Jesse Rosenthal  
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



A tool for printing from notmuch

2011-01-28 Thread Andreas Amann
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 
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 
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


A tool for printing from notmuch

2011-01-28 Thread Jesse Rosenthal
On Fri, 28 Jan 2011 16:11:00 -0500, Jesse Rosenthal  
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


A tool for printing from notmuch

2011-01-28 Thread Jesse Rosenthal

Hi Andreas,

On Fri, 28 Jan 2011 20:59:06 +, Andreas Amann  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 
> 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



A tool for printing from notmuch

2011-01-28 Thread Jesse Rosenthal
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


Re: A tool for printing from notmuch

2011-01-28 Thread Andreas Amann
On Fri, 28 Jan 2011 16:11:00 -0500, Jesse Rosenthal  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

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: A tool for printing from notmuch

2011-01-28 Thread Jesse Rosenthal
On Fri, 28 Jan 2011 16:11:00 -0500, Jesse Rosenthal  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
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: A tool for printing from notmuch

2011-01-28 Thread Jesse Rosenthal

Hi Andreas,

On Fri, 28 Jan 2011 20:59:06 +, Andreas Amann  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 
> 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

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: A tool for printing from notmuch

2011-01-28 Thread Andreas Amann
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 
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 
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
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


A tool for printing from notmuch

2011-01-28 Thread Jesse Rosenthal
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
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch