[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: The Debian vote taking machinery (Very Long)



>>>>> "Manoj" == Manoj Srivastava <srivasta@debian.org> writes:

    Manoj> 	Unfortunately, I am not python literate. How hard
    Manoj> would it be to create a script that takes a email message
    Manoj> in a file by itself as a parameter, and creates 

    Manoj> a) the message body, unless it was PGP/MIME 

    Manoj> b) The message body and the detatched signature, in case it
    Manoj> is PGP/MIME

    Manoj> 	in separate files? Suppose the stem of the output
    Manoj> files is given as a second parameter? (this is one of the
    Manoj> benefits of a modular design, we can patch in an
    Manoj> intermediate step that handles MIME messages).

It's really easy.  Here's an example that just prints to stdout.  If
you haven't already, spend an hour or two and peek at the Python
tutorial at:

http://www.python.org/doc/current/tut/tut.html

It's really easy to pick up; took me a day or two.

Anyway, I'm not sure if PGP/MIME uses application/pkcs7-mime or
multipart/signed in real life; this example deals with both.

#!/usr/bin/env python

import email
import sys

if len(sys.argv) != 2:
    print "Usage: %s filename" % sys.argv[0]
    sys.exit(1)

fd = open(sys.argv[1])
msg = email.message_from_file(fd)

if msg.get_type() in ['multipart/signed', 'application/pkcs7-mime']:
    body = msg.get_payload(0)
    sig = msg.get_payload(1)
    print "===body===\n" + body.get_payload() + "\n"
    print "===sig===\n" + sig.get_payload() + "\n"
else:
    print msg.get_payload()
    

-- 
Brought to you by the letters A and G and the number 18.
"Wuzzle means to mix."
Debian GNU/Linux maintainer of Gimp and Nethack -- http://www.debian.org/



Reply to: