Package: pgp-mime
Python module and tools for constructing and sending PGP/MIME email.Thepgp_mimemodule makes it easy to construct and dispatch signed
and/or encrypted email usingPGPandRFC 3156.  It usesGnuPG(viagpgme-tool) to perform the cryptography.InstallationPackagesGentooI’ve packagedpgp-mimeforGentoo.  You needlaymanand
mywtk overlay.  Install with:# emerge -av app-portage/layman
# layman --add wtk
# emerge -av dev-python/pgp-mimeDependenciespgp-mimeis a simple package with no external dependencies outside
the Python 3 standard library.  There are a number ofGnuPGwrappers
for pythonout there, but none of them seem mature/stable enough
to be worth installing.  Instead, we use thepyassuanmodule to
talk togpgme-toolover pipes or sockets.  If this isn’t working
for you, you need only replace thepgp_mime.cryptmodule to handle
the cryptography.Installing by handpgp-mimeis available as aGitrepository:$ git clone git://tremily.us/pgp-mime.gitSee thehomepagefor details.  To install the checkout, run the
standard:$ python setup.py installUsagePgp-mime has grown up as I’ve become more experienced with Python.
The current interface is much simpler, and there are lots of
docstrings showing you how to use each function.If you’re looking for a higher level example, pgp-mime includes a
command line scriptsend-pgp-mime.pythat allows you to send
signed and/or encrypted email from the command line.  I recommend you
usegpg2with mywrappers and pinentry programto allow easy
pinentry from the command line.  Here’s how you could mail signed
grades to your class:$ FROM="From: Rincewind <rincewind@uu.edu>"
$ head -n2 grades
Twoflower <tf@isa.ae.cw>|9
Eric Thursley <et@pseudopolis.net>|10
$ while read LINE; do
    STUDENT=$(echo "$LINE" | cut -d '|' -f 1)
    GRADE=$(echo "$LINE" | cut -d '|' -f 2)
    HEAD=$(echo -e "$FROM\nTo: $STUDENT\nSubject: Grades")
    BODY=$(echo -e "$STUDENT,\n\nYou got a $GRADE.\n\nGood job.")
    send-pgp-mime.py -H <(echo "$HEAD") -B <(echo "$BODY") --mode sign
  done < gradesIf you can convince your students to get PGP keys, you could also
encrypt their grades by changing--modesignto--modesign-encrypt.Of course, if you’re interested in working with students and grades,
you might also be interested in mypygraderpackage, which uses
pgp-mime under the hood.Configuring the SMTP connectionPgp-mime supports two methods for sending messages (viapgp_mime.mail).  It can either call your system’ssendmailequivalent, or connect directly to anSMTPserver usingsmtplib.
Since I imagine SMTP will be more common, you can easily configure
your SMTP connection via~/.config/smtplib.conf:[smtp]
host: smtp.mail.uu.edu
port: 587
starttls: yes
username: rincewind
password: 7ugg@g3All of these fields are optional.hostdefaults tolocalhostandportdefaults to 25.  Ifusernameis not given, we do not
attempt to login to the SMTP server after connecting.Ifstarttlsisnoor not given, the SMTP transaction occurs in
plain text (although the underlying emails will still be encrypted).
However, if you set ausername(to login), pgp-mime will require aSTARTTLSto protect your password from sniffing.TestingRun the internal unit tests usingnose:$ nosetests --with-doctest --doctest-tests pgp_mimeIf a Python-3-version ofnosetestsis not the default on your
system, you may need to try something like:$ nosetests-3.2 --with-doctest --doctest-tests pgp_mimeLicenceThis project is distributed under theGNU General Public License
Version 3or greater.AuthorW. Trevor Kingwking@tremily.us