1.1 --- a/tests/test_send.py Sat Dec 21 01:48:54 2013 +0100
1.2 +++ b/tests/test_send.py Sun Dec 22 00:05:32 2013 +0100
1.3 @@ -1,9 +1,24 @@
1.4 #!/usr/bin/env python
1.5
1.6 from MoinMessage import *
1.7 +from email.mime.application import MIMEApplication
1.8 from email.mime.text import MIMEText
1.9 +from os.path import split
1.10 import sys
1.11
1.12 +def add_update(message, action, part):
1.13 + if action == "file":
1.14 + action = "store"
1.15 + part["Update-Action"] = action
1.16 + message.add_update(part)
1.17 +
1.18 +def readfile(filename):
1.19 + f = open(filename, "rb")
1.20 + try:
1.21 + return MIMEApplication(f.read())
1.22 + finally:
1.23 + f.close()
1.24 +
1.25 if __name__ == "__main__":
1.26 try:
1.27 signer = sys.argv[1]
1.28 @@ -27,28 +42,53 @@
1.29 args = None
1.30
1.31 if not args:
1.32 - print >>sys.stderr, "Need a signer, recipient, URL, update type, action and some updates as arguments to this program."
1.33 - print >>sys.stderr, "Syntax:"
1.34 - print >>sys.stderr, sys.argv[0], "<signing keyid> <recipient keyid> " \
1.35 - "[ --forward <signing keyid> ] <URL> " \
1.36 - "<update type> <action> <update>..."
1.37 + print >>sys.stderr, """\
1.38 +Need a signer, recipient, URL, update type, action and some updates as arguments to this program.
1.39 +
1.40 +Syntax:
1.41 +
1.42 +%s <signing keyid> <recipient keyid> [ --forward <signing keyid> ] <URL> \\
1.43 + <update type> <action> <update or part>...
1.44 +
1.45 +The update type is typically "collection" for a number of separate updates,
1.46 +or any other value for a single multipart update consisting of several parts.
1.47 +
1.48 +The action may be "update", "replace" or "store", with subsequent updates
1.49 +being text strings containing text for individual updates (or parts of a single
1.50 +update). If action is "file", however, subsequent updates must refer to files
1.51 +and communicated updates will be given a "store" update action.
1.52 +""" % sys.argv[0]
1.53 sys.exit(1)
1.54
1.55 message = Message()
1.56 parts = []
1.57
1.58 + # A collection of updates involves adding each update directly to the
1.59 + # message. A single update involves collecting the given parts, combining
1.60 + # them and putting the combined update in the message.
1.61 +
1.62 for arg in args:
1.63 - part = MIMEText(arg, "moin", sys.stdin.encoding)
1.64 +
1.65 + # Read files and assign filenames to them, or read argument strings, and
1.66 + # adopt them as parts.
1.67 +
1.68 + if action == "file":
1.69 + part = readfile(arg)
1.70 + part["Content-Disposition"] = split(arg)[-1]
1.71 + else:
1.72 + part = MIMEText(arg, "moin", sys.stdin.encoding)
1.73 +
1.74 if type == "collection":
1.75 - part["Update-Action"] = action
1.76 - message.add_update(part)
1.77 + add_update(message, action, part)
1.78 else:
1.79 parts.append(part)
1.80
1.81 + # Obtain the alternative representations as an update and add it to the
1.82 + # message.
1.83 +
1.84 if type != "collection":
1.85 multipart = message.get_update(parts)
1.86 - multipart["Update-Action"] = action
1.87 - message.add_update(multipart)
1.88 + add_update(message, action, multipart)
1.89
1.90 email_message = message.get_payload()
1.91 gpg = GPG()