something like perl's Mail::GPG ?

Piet van Oostrum piet at cs.uu.nl
Fri Aug 14 17:30:45 EDT 2009


>>>>> akonsu <akonsu at gmail.com> (a) wrote:

>a> hello,
>a> i am looking for a module with functionality similar to that of the
>a> Perl's Mail::GPG package. I need to verify multipart emails that are
>a> PGP-signed.

I don't know Perl's GPG package, but to verify PGP-signed stuff you can
use gnupg. It doesn't have special code for mail messages, however. It
is just a Pythonic wrapper facade around the gpg program.

However, it doesn't do the PGP/MIME stuff, so you will have to transform
the MIME messages into something that GPG understands. This isn't hard
and you can find a short python script that does it on
http://domnit.org/2008/03/clearmime. It describes how you can use it as
a program and pipe the message through it into gpg --verify. You can
also use it as a module if you rename it to clearmime.py, and use it
with the recently released gnupg module. It is released under GPL.
However it wouldn't be hard to write something similar yourself, for
example if you want to feed it existing Message objects rather than strings.
Example:

import os
from gnupg import GPG
from clearmime import clarify

msgtxt = open('testgpg.msg').read()
cl = clarify(msgtxt)
gpg=GPG(gnupghome = os.path.join(os.environ['HOME'], '.gnupg'))

if gpg.verify(cl):
    print "Signature correct"
else:
    print "Signature incorrect"

-- 
Piet van Oostrum <piet at cs.uu.nl>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: piet at vanoostrum.org



More information about the Python-list mailing list