# HG changeset patch # User Paul Boddie # Date 1389568720 -3600 # Node ID e8547266a21f08533bc71d33cd03a0b61f82c2bf # Parent e66d8246661a43c645c49840aadd8e1e02fad143 Added some support for importing keys along with a script for sending them. diff -r e66d8246661a -r e8547266a21f MoinMessage.py --- a/MoinMessage.py Sun Jan 12 19:39:47 2014 +0100 +++ b/MoinMessage.py Mon Jan 13 00:18:40 2014 +0100 @@ -115,7 +115,7 @@ part.attach(alternative) return part - def get_payload(self, timestamped=True): + def get_payload(self, subtype="mixed", timestamped=True): """ Get the multipart payload for the message. If the 'timestamped' @@ -128,7 +128,7 @@ if len(self.updates) == 1: message = self.updates[0] else: - message = MIMEMultipart() + message = MIMEMultipart(subtype) message.add_header("Update-Type", "collection") for update in self.updates: message.attach(update) @@ -328,6 +328,14 @@ return encrypted_message + def importKeys(self, text): + + """ + Import the keys provided by the given 'text'. + """ + + self.run(["--import"], text) + def exportKey(self, keyid): """ diff -r e66d8246661a -r e8547266a21f scripts/sendkey.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/sendkey.py Mon Jan 13 00:18:40 2014 +0100 @@ -0,0 +1,61 @@ +# -*- coding: iso-8859-1 -*- +""" + sendkey - Send key using MoinMessage + + @copyright: 2013, 2014 by Paul Boddie + @license: GNU GPL (v2 or later), see COPYING.txt for details. +""" + +from MoinMessage import Message, GPG, sendMessage +from email.mime.application import MIMEApplication +from email.mime.text import MIMEText +import sys + +def readkey(filename): + f = open(filename, "rb") + try: + return MIMEApplication(f.read(), "pgp-keys") + finally: + f.close() + +if __name__ == "__main__": + try: + recipient = sys.argv[1] + url = sys.argv[2] + filename = sys.argv[3] + secret = sys.argv[4] + except IndexError: + secret = None + + if not secret: + print >>sys.stderr, """\ +Need a recipient key identifier, the destination URL, a key filename, and a +secret as arguments to this program. +""" + sys.exit(1) + + # Bundle the key and secret into a message. + + message = Message() + + part = readkey(filename) + message.add_update(part) + + part = MIMEText(secret) + message.add_update(part) + + # Get the e-mail message itself. + + email_message = message.get_payload("x-moinmessage-keys") + + # Sign (for authorship), encrypt (for privacy), sign (for authentication), + # and send the message. + + gpg = GPG() + encrypted_message = gpg.encryptMessage(email_message, recipient) + + resp = sendMessage(encrypted_message, url) + + print resp + +# vim: tabstop=4 expandtab shiftwidth=4