* [sup-talk] printing emails (but not attachments)
@ 2010-03-11 21:11 John Bent
2010-03-17 19:25 ` John Bent
0 siblings, 1 reply; 5+ messages in thread
From: John Bent @ 2010-03-11 21:11 UTC (permalink / raw)
To: sup-talk
I've been piping emails into muttprint which works well unless there's a
binary attachment. When there's a binary attachment, muttprint prints
it and it usually takes tens and tens of pages. Whoops.
Anyone else figure out how to print emails but not attachments?
Thanks,
John
_______________________________________________
sup-talk mailing list
sup-talk@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-talk
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [sup-talk] printing emails (but not attachments)
2010-03-11 21:11 [sup-talk] printing emails (but not attachments) John Bent
@ 2010-03-17 19:25 ` John Bent
2010-03-17 19:47 ` Michael McDermott
2010-03-17 20:31 ` John Bent
0 siblings, 2 replies; 5+ messages in thread
From: John Bent @ 2010-03-17 19:25 UTC (permalink / raw)
To: sup-talk
[-- Attachment #1: Type: text/plain, Size: 1254 bytes --]
Excerpts from John Bent's message of Thu Mar 11 14:11:21 -0700 2010:
> I've been piping emails into muttprint which works well unless there's
> a binary attachment. When there's a binary attachment, muttprint
> prints it and it usually takes tens and tens of pages. Whoops.
>
> Anyone else figure out how to print emails but not attachments?
>
Well, I'm sure I've once again reinvented the wheel but I wrote my own
script to print emails without printing binary attachments. It reads an
email, pipes the headers to muttprint, then pipes text/plain and
text/html through w3m into muttprint, for everything else it pipes "#
Attachment: filename (type)." It requires w3m and muttprint to be in
the user's path.
I'm sorry that it's horribly in violation of sup philosophy but I wrote
it in python. :( Sorry but my ruby is just barely good enough to do
'if' statements in my hooks.
It's attached in case anyone else wants it. I'm scared I really did
just reinvent the wheel, otherwise I'd add it to the wiki. To print an
email from sup using this, hit '|' in thread-view-mode to open a pipe
and then just type sup-print (assuming you've put this attachment in
your path). I believe all the python imports it uses come standard.
--
Thanks,
John
[-- Attachment #2: sup-print --]
[-- Type: application/octet-stream, Size: 1963 bytes --]
#! /usr/bin/env python
import email
import sys
from subprocess import Popen,PIPE
# read in the email message from an arg or stdin
def get_message():
try:
fp = open(sys.argv[1])
except IndexError:
fp = sys.stdin
return email.message_from_file(fp)
# open a pipe to muttprint
def open_muttprint():
try:
mutt = Popen("muttprint",shell=True,stdin=PIPE)
except OSError, e:
print "popen muttprint failed:", e
sys.exit()
return mutt
# write all the headers to muttprint
def write_header( msg, mutt ):
for key in msg.keys( ):
val = msg.__getitem__(key)
pipe_mutt( "%s: %s\n" % ( key, val ), mutt )
pipe_mutt( "\n", mutt ) # one extra newline in case text abuts headers
# utility for piping text to mutt
# useful for debugging, just select which one
def pipe_mutt( text, mutt ):
mutt.stdin.write(text)
#sys.stdout.write(text)
# write all the text or html parts to muttprint
# otherwise write an attachment notation
def write_part( part, mutt ):
type = part.get_content_type()
if type == "text/plain" or type == "text/html":
command = "w3m -dump -T %s" % type
try:
ch = Popen(command,shell=True,stdin=PIPE,stdout=PIPE,stderr=PIPE)
except OSError, e:
print >>sys.stderr, "Execution failed:", e
sys.exit()
ch.stdin.write(str(part.get_payload()))
ch.stdin.close()
out = ch.stdout.read().strip()
err = ch.stderr.read()
ch.wait()
if len(err):
print "Error with w3m: %s" % err
sys.exit()
pipe_mutt( out + "\n", mutt )
elif part.get_filename() is not None:
pipe_mutt("# Attachment: %s (%s)\n" % (part.get_filename(),type),mutt)
if __name__ == '__main__':
msg = get_message( )
mutt = open_muttprint()
write_header( msg, mutt )
for part in msg.walk(): write_part( part, mutt )
mutt.stdin.close()
[-- Attachment #3: Type: text/plain, Size: 140 bytes --]
_______________________________________________
sup-talk mailing list
sup-talk@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-talk
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [sup-talk] printing emails (but not attachments)
2010-03-17 19:25 ` John Bent
@ 2010-03-17 19:47 ` Michael McDermott
2010-03-18 0:28 ` John Bent
2010-03-17 20:31 ` John Bent
1 sibling, 1 reply; 5+ messages in thread
From: Michael McDermott @ 2010-03-17 19:47 UTC (permalink / raw)
To: sup-talk
Well, I'm not a dev, but this little wrapper + muttprint is exactly the
kind of thing I've been looking for, from the time I was using pine
until now.
Thanks for posting it.
Excerpts from John Bent's message of Wed Mar 17 14:25:02 -0500 2010:
> Excerpts from John Bent's message of Thu Mar 11 14:11:21 -0700 2010:
> > I've been piping emails into muttprint which works well unless there's
> > a binary attachment. When there's a binary attachment, muttprint
> > prints it and it usually takes tens and tens of pages. Whoops.
> >
> > Anyone else figure out how to print emails but not attachments?
> >
> Well, I'm sure I've once again reinvented the wheel but I wrote my own
> script to print emails without printing binary attachments. It reads an
> email, pipes the headers to muttprint, then pipes text/plain and
> text/html through w3m into muttprint, for everything else it pipes "#
> Attachment: filename (type)." It requires w3m and muttprint to be in
> the user's path.
>
> I'm sorry that it's horribly in violation of sup philosophy but I wrote
> it in python. :( Sorry but my ruby is just barely good enough to do
> 'if' statements in my hooks.
>
> It's attached in case anyone else wants it. I'm scared I really did
> just reinvent the wheel, otherwise I'd add it to the wiki. To print an
> email from sup using this, hit '|' in thread-view-mode to open a pipe
> and then just type sup-print (assuming you've put this attachment in
> your path). I believe all the python imports it uses come standard.
--
Michael McDermott
www.mad-computer-scientist.com
_______________________________________________
sup-talk mailing list
sup-talk@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-talk
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [sup-talk] printing emails (but not attachments)
2010-03-17 19:25 ` John Bent
2010-03-17 19:47 ` Michael McDermott
@ 2010-03-17 20:31 ` John Bent
1 sibling, 0 replies; 5+ messages in thread
From: John Bent @ 2010-03-17 20:31 UTC (permalink / raw)
To: sup-talk
[-- Attachment #1: Type: text/plain, Size: 1452 bytes --]
Excerpts from John Bent's message of Wed Mar 17 13:25:02 -0600 2010:
> Excerpts from John Bent's message of Thu Mar 11 14:11:21 -0700 2010:
> > I've been piping emails into muttprint which works well unless there's
> > a binary attachment. When there's a binary attachment, muttprint
> > prints it and it usually takes tens and tens of pages. Whoops.
> >
> > Anyone else figure out how to print emails but not attachments?
> >
> Well, I'm sure I've once again reinvented the wheel but I wrote my own
> script to print emails without printing binary attachments. It reads an
> email, pipes the headers to muttprint, then pipes text/plain and
> text/html through w3m into muttprint, for everything else it pipes "#
> Attachment: filename (type)." It requires w3m and muttprint to be in
> the user's path.
>
> I'm sorry that it's horribly in violation of sup philosophy but I wrote
> it in python. :( Sorry but my ruby is just barely good enough to do
> 'if' statements in my hooks.
>
> It's attached in case anyone else wants it. I'm scared I really did
> just reinvent the wheel, otherwise I'd add it to the wiki. To print an
> email from sup using this, hit '|' in thread-view-mode to open a pipe
> and then just type sup-print (assuming you've put this attachment in
> your path). I believe all the python imports it uses come standard.
>
Sorry, it wasn't handling quoted-printable encodings. Patched version
attached.
--
Thanks,
John
[-- Attachment #2: sup-print --]
[-- Type: application/octet-stream, Size: 1974 bytes --]
#! /usr/bin/env python
import email
import sys
from subprocess import Popen,PIPE
# read in the email message from an arg or stdin
def get_message():
try:
fp = open(sys.argv[1])
except IndexError:
fp = sys.stdin
return email.message_from_file(fp)
# open a pipe to muttprint
def open_muttprint():
try:
mutt = Popen("muttprint",shell=True,stdin=PIPE)
except OSError, e:
print "popen muttprint failed:", e
sys.exit()
return mutt
# write all the headers to muttprint
def write_header( msg, mutt ):
for key in msg.keys( ):
val = msg.__getitem__(key)
pipe_mutt( "%s: %s\n" % ( key, val ), mutt )
pipe_mutt( "\n", mutt ) # one extra newline in case text abuts headers
# utility for piping text to mutt
# useful for debugging, just select which one
def pipe_mutt( text, mutt ):
mutt.stdin.write(text)
#sys.stdout.write(text)
# write all the text or html parts to muttprint
# otherwise write an attachment notation
def write_part( part, mutt ):
type = part.get_content_type()
if type == "text/plain" or type == "text/html":
command = "w3m -dump -T %s" % type
try:
ch = Popen(command,shell=True,stdin=PIPE,stdout=PIPE,stderr=PIPE)
except OSError, e:
print >>sys.stderr, "Execution failed:", e
sys.exit()
ch.stdin.write(str(part.get_payload(decode=True)))
ch.stdin.close()
out = ch.stdout.read().strip()
err = ch.stderr.read()
ch.wait()
if len(err):
print "Error with w3m: %s" % err
sys.exit()
pipe_mutt( out + "\n", mutt )
elif part.get_filename() is not None:
pipe_mutt("# Attachment: %s (%s)\n" % (part.get_filename(),type),mutt)
if __name__ == '__main__':
msg = get_message( )
mutt = open_muttprint()
write_header( msg, mutt )
for part in msg.walk(): write_part( part, mutt )
mutt.stdin.close()
[-- Attachment #3: Type: text/plain, Size: 140 bytes --]
_______________________________________________
sup-talk mailing list
sup-talk@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-talk
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [sup-talk] printing emails (but not attachments)
2010-03-17 19:47 ` Michael McDermott
@ 2010-03-18 0:28 ` John Bent
0 siblings, 0 replies; 5+ messages in thread
From: John Bent @ 2010-03-18 0:28 UTC (permalink / raw)
To: sup-talk
Excerpts from Michael McDermott's message of Wed Mar 17 13:47:16 -0600 2010:
> Well, I'm not a dev, but this little wrapper + muttprint is exactly the
> kind of thing I've been looking for, from the time I was using pine
> until now.
>
Glad you like it. Added it to the wiki. Although it seems to make much
more sense to have this functionality inside sup itself. sup already
knows how to decode and display many of the content-types, it already
hides attachments it can't display, and it formats the headers as well.
I tried writing a patch to add a config line for printer command,
add a keystroke for printing, and then have sup pipe the modified email
into the defined printer command, but it's beyond my ruby skills and
beyond the time I spent trying to grok sup.
John
--
Thanks,
John
_______________________________________________
sup-talk mailing list
sup-talk@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-talk
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-03-18 0:28 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-11 21:11 [sup-talk] printing emails (but not attachments) John Bent
2010-03-17 19:25 ` John Bent
2010-03-17 19:47 ` Michael McDermott
2010-03-18 0:28 ` John Bent
2010-03-17 20:31 ` John Bent
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox