From f04ada1e90aaff9da1af46455a0ead597fc4deba 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. --- interfaces/email/interactive/be-handle-mail | 9 ++++---- .../{send_pgp_mime => send_pgp_mime.py} | 22 ++++++++++++++----- 2 files changed, 21 insertions(+), 10 deletions(-) rename interfaces/email/interactive/{send_pgp_mime => send_pgp_mime.py} (97%) diff --git a/interfaces/email/interactive/be-handle-mail b/interfaces/email/interactive/be-handle-mail index 7b62129..a608074 100755 --- a/interfaces/email/interactive/be-handle-mail +++ b/interfaces/email/interactive/be-handle-mail @@ -28,8 +28,9 @@ single argument. Eventually we'll commit after every message. """ -import libbe.cmdutil, libbe.utility +import cStringIO as StringIO import email +import libbe.cmdutil, libbe.utility import send_pgp_mime import sys import time @@ -111,11 +112,11 @@ def run_message(msg_text): response_header = [u"From: %s" % HANDLER_ADDRESS, u"To: %s" % author, - u"Date: %s" % , libbe.utility.time_to_str(time.time()), + u"Date: %s" % libbe.utility.time_to_str(time.time()), u"Content-Type: text/plain; charset=%s" % encoding, u"Content-Transfer-Encoding: 8bit", u"In-reply-to: %s" % (id), - u"Subject: %s Re: %s" % (SUBJECT_COMMENT, command), + u"Subject: Re: %s %s" % (SUBJECT_COMMENT, command), ] response_body = [u"Results of running: (exit code %d)" % ret, u" %s %s" % (command, " ".join(command_args)),] @@ -130,7 +131,7 @@ def run_message(msg_text): def main(): msg_text = sys.stdin.read() - response_email = handle_message(msg_text) + response_email = run_message(msg_text) send_pgp_mime.mail(response_email, send_pgp_mime.sendmail) if __name__ == "__main__": diff --git a/interfaces/email/interactive/send_pgp_mime b/interfaces/email/interactive/send_pgp_mime.py similarity index 97% rename from interfaces/email/interactive/send_pgp_mime rename to interfaces/email/interactive/send_pgp_mime.py index 8aa86fa..d5a6497 100644 --- a/interfaces/email/interactive/send_pgp_mime +++ b/interfaces/email/interactive/send_pgp_mime.py @@ -18,10 +18,10 @@ """ 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 @@ -112,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,)): """ @@ -339,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 @@ -496,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', @@ -554,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