something like perl's Mail::GPG ?

Piet van Oostrum piet at
Fri Aug 14 23:30:45 CEST 2009

>>>>> akonsu <akonsu at> (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 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, 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.

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"
    print "Signature incorrect"

Piet van Oostrum <piet at>
URL: [PGP 8DAE142BE17999C4]
Private email: piet at

More information about the Python-list mailing list