From e14835a5a0fbd498985f9d30d00a30f949a99b15 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 15 Jul 2009 13:18:19 -0400 Subject: [PATCH] Added --mode=plain option to send_pgp_mime. Also a few more tweaks to get things working. I think be-handle-mail is parsing the incoming messages correctly now, but I'm not getting replies back for some reason. Some of the adjustments: * Moved send_pgp_mime -> send_pgp_mime.py, otherwise Python doesn't recognize it as an importable module. * I use postfix now instead of msmtp, so send_pgp_mime.sendmail now points to postfix's sendmail-compatable frontend. * Added "--mode=plain" option to send_pgp_mime.py, so I can test my procmail rules and send_pgp_mime itself without worrying about be-handle-mail. * Fixed some typos in be-handle-mail. --- .../{send_pgp_mime => send_pgp_mime.py} | 38 +++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) rename interfaces/email/interactive/{send_pgp_mime => send_pgp_mime.py} (93%) diff --git a/interfaces/email/interactive/send_pgp_mime b/interfaces/email/interactive/send_pgp_mime.py similarity index 93% rename from interfaces/email/interactive/send_pgp_mime rename to interfaces/email/interactive/send_pgp_mime.py index 6b25ba7..d5a6497 100644 --- a/interfaces/email/interactive/send_pgp_mime +++ b/interfaces/email/interactive/send_pgp_mime.py @@ -1,13 +1,27 @@ #!/usr/bin/python # -# Copyright +# Copyright (C) 2009 W. Trevor King +# +# 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 @@ -98,7 +112,7 @@ pgp_stdin_passphrase_arg='--passphrase-fd 0' 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,)): """ @@ -325,6 +339,14 @@ class Mail (object): 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 @@ -482,7 +504,7 @@ if __name__ == '__main__': 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', @@ -540,6 +562,8 @@ if __name__ == '__main__': 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 -- 2.26.2