1.1 --- a/MoinMessage.py Sun Jan 12 19:39:47 2014 +0100
1.2 +++ b/MoinMessage.py Mon Jan 13 00:18:40 2014 +0100
1.3 @@ -115,7 +115,7 @@
1.4 part.attach(alternative)
1.5 return part
1.6
1.7 - def get_payload(self, timestamped=True):
1.8 + def get_payload(self, subtype="mixed", timestamped=True):
1.9
1.10 """
1.11 Get the multipart payload for the message. If the 'timestamped'
1.12 @@ -128,7 +128,7 @@
1.13 if len(self.updates) == 1:
1.14 message = self.updates[0]
1.15 else:
1.16 - message = MIMEMultipart()
1.17 + message = MIMEMultipart(subtype)
1.18 message.add_header("Update-Type", "collection")
1.19 for update in self.updates:
1.20 message.attach(update)
1.21 @@ -328,6 +328,14 @@
1.22
1.23 return encrypted_message
1.24
1.25 + def importKeys(self, text):
1.26 +
1.27 + """
1.28 + Import the keys provided by the given 'text'.
1.29 + """
1.30 +
1.31 + self.run(["--import"], text)
1.32 +
1.33 def exportKey(self, keyid):
1.34
1.35 """
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/scripts/sendkey.py Mon Jan 13 00:18:40 2014 +0100
2.3 @@ -0,0 +1,61 @@
2.4 +# -*- coding: iso-8859-1 -*-
2.5 +"""
2.6 + sendkey - Send key using MoinMessage
2.7 +
2.8 + @copyright: 2013, 2014 by Paul Boddie <paul@boddie.org.uk>
2.9 + @license: GNU GPL (v2 or later), see COPYING.txt for details.
2.10 +"""
2.11 +
2.12 +from MoinMessage import Message, GPG, sendMessage
2.13 +from email.mime.application import MIMEApplication
2.14 +from email.mime.text import MIMEText
2.15 +import sys
2.16 +
2.17 +def readkey(filename):
2.18 + f = open(filename, "rb")
2.19 + try:
2.20 + return MIMEApplication(f.read(), "pgp-keys")
2.21 + finally:
2.22 + f.close()
2.23 +
2.24 +if __name__ == "__main__":
2.25 + try:
2.26 + recipient = sys.argv[1]
2.27 + url = sys.argv[2]
2.28 + filename = sys.argv[3]
2.29 + secret = sys.argv[4]
2.30 + except IndexError:
2.31 + secret = None
2.32 +
2.33 + if not secret:
2.34 + print >>sys.stderr, """\
2.35 +Need a recipient key identifier, the destination URL, a key filename, and a
2.36 +secret as arguments to this program.
2.37 +"""
2.38 + sys.exit(1)
2.39 +
2.40 + # Bundle the key and secret into a message.
2.41 +
2.42 + message = Message()
2.43 +
2.44 + part = readkey(filename)
2.45 + message.add_update(part)
2.46 +
2.47 + part = MIMEText(secret)
2.48 + message.add_update(part)
2.49 +
2.50 + # Get the e-mail message itself.
2.51 +
2.52 + email_message = message.get_payload("x-moinmessage-keys")
2.53 +
2.54 + # Sign (for authorship), encrypt (for privacy), sign (for authentication),
2.55 + # and send the message.
2.56 +
2.57 + gpg = GPG()
2.58 + encrypted_message = gpg.encryptMessage(email_message, recipient)
2.59 +
2.60 + resp = sendMessage(encrypted_message, url)
2.61 +
2.62 + print resp
2.63 +
2.64 +# vim: tabstop=4 expandtab shiftwidth=4