#!/usr/bin/python
#
-# Copyright
+# Copyright (C) 2009 W. Trevor King <wking@drexel.edu>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""
Python module and command line tool for sending pgp/mime email.
-Mostly uses subprocess to call gpg and a sendmail-compatible mailer
-(defaults to msmtp). If you lack gpg, either don't use the encryption
-functions or adjust the pgp_* commands. If you don't use msmtp,
-adjust the sendmail command.
+Mostly uses subprocess to call gpg and a sendmail-compatible mailer.
+If you lack gpg, either don't use the encryption functions or adjust
+the pgp_* commands. You may need to adjust the sendmail command to
+point to whichever sendmail-compatible mailer you have on your system.
"""
from cStringIO import StringIO
pgp_sign_command='/usr/bin/gpg --no-verbose --quiet --batch %p --output - --detach-sign --armor --textmode %?a?-u "%a"? %f'
pgp_encrypt_only_command='/usr/bin/gpg --no-verbose --quiet --batch --output - --encrypt --armor --textmode --always-trust --encrypt-to "%a" %R -- %f'
pgp_encrypt_sign_command='/usr/bin/gpg --no-verbose --quiet --batch %p --output - --encrypt --sign %?a?-u "%a"? --armor --textmode --always-trust --encrypt-to "%a" %R -- %f'
-sendmail='/usr/bin/msmtp -t'
+sendmail='/usr/sbin/sendmail -t'
def execute(args, stdin=None, expect=(0,)):
"""
if passphrase == None:
return (None,'')
return (passphrase, pgp_stdin_passphrase_arg)
+ def plain(self):
+ """
+ text/plain
+ """
+ msg = MIMEText(self.body)
+ for k,v in self.headermsg.items():
+ msg[k] = v
+ return msg
def sign(self, passphrase=None):
"""
multipart/signed
type="int", metavar='DESCRIPTOR')
parser.add_option('--mode', dest='mode', default='sign',
- help="One of 'sign', 'encrypt', or 'sign-encrypt'. Defaults to %default.",
+ help="One of 'sign', 'encrypt', 'sign-encrypt', or 'plain'. Defaults to %default.",
metavar='MODE')
parser.add_option('-a', '--sign-as', dest='sign_as',
message = m.encrypt()
elif options.mode == "sign-encrypt":
message = m.signAndEncrypt()
+ elif options.mode == "plain":
+ message = m.plain()
else:
print "Unrecognized mode '%s'" % options.mode