1.1 --- a/tests/test_message.py Sat Dec 21 01:48:54 2013 +0100
1.2 +++ b/tests/test_message.py Sun Dec 22 00:05:32 2013 +0100
1.3 @@ -1,10 +1,24 @@
1.4 #!/usr/bin/env python
1.5
1.6 from MoinMessage import Message
1.7 -from email.mime.multipart import MIMEMultipart
1.8 +from email.mime.application import MIMEApplication
1.9 from email.mime.text import MIMEText
1.10 +from os.path import split
1.11 import sys
1.12
1.13 +def add_update(message, action, part):
1.14 + if action == "file":
1.15 + action = "store"
1.16 + part["Update-Action"] = action
1.17 + message.add_update(part)
1.18 +
1.19 +def readfile(filename):
1.20 + f = open(filename, "rb")
1.21 + try:
1.22 + return MIMEApplication(f.read())
1.23 + finally:
1.24 + f.close()
1.25 +
1.26 if __name__ == "__main__":
1.27 try:
1.28 type = sys.argv[1]
1.29 @@ -24,17 +38,27 @@
1.30 # updates or as an alternative part to a single update.
1.31
1.32 for arg in args:
1.33 - part = MIMEText(arg, "moin", sys.stdin.encoding)
1.34 +
1.35 + # Read files and assign filenames to them, or read argument strings, and
1.36 + # adopt them as parts.
1.37 +
1.38 + if action == "file":
1.39 + part = readfile(arg)
1.40 + part["Content-Disposition"] = split(arg)[-1]
1.41 + else:
1.42 + part = MIMEText(arg, "moin", sys.stdin.encoding)
1.43 +
1.44 if type == "collection":
1.45 - part["Update-Action"] = action
1.46 - message.add_update(part)
1.47 + add_update(message, action, part)
1.48 else:
1.49 parts.append(part)
1.50
1.51 + # Obtain the alternative representations as an update and add it to the
1.52 + # message.
1.53 +
1.54 if type != "collection":
1.55 multipart = message.get_update(parts)
1.56 - multipart["Update-Action"] = action
1.57 - message.add_update(multipart)
1.58 + add_update(message, action, multipart)
1.59
1.60 text = message.get_payload()
1.61 print text
2.1 --- a/tests/test_send.py Sat Dec 21 01:48:54 2013 +0100
2.2 +++ b/tests/test_send.py Sun Dec 22 00:05:32 2013 +0100
2.3 @@ -1,9 +1,24 @@
2.4 #!/usr/bin/env python
2.5
2.6 from MoinMessage import *
2.7 +from email.mime.application import MIMEApplication
2.8 from email.mime.text import MIMEText
2.9 +from os.path import split
2.10 import sys
2.11
2.12 +def add_update(message, action, part):
2.13 + if action == "file":
2.14 + action = "store"
2.15 + part["Update-Action"] = action
2.16 + message.add_update(part)
2.17 +
2.18 +def readfile(filename):
2.19 + f = open(filename, "rb")
2.20 + try:
2.21 + return MIMEApplication(f.read())
2.22 + finally:
2.23 + f.close()
2.24 +
2.25 if __name__ == "__main__":
2.26 try:
2.27 signer = sys.argv[1]
2.28 @@ -27,28 +42,53 @@
2.29 args = None
2.30
2.31 if not args:
2.32 - print >>sys.stderr, "Need a signer, recipient, URL, update type, action and some updates as arguments to this program."
2.33 - print >>sys.stderr, "Syntax:"
2.34 - print >>sys.stderr, sys.argv[0], "<signing keyid> <recipient keyid> " \
2.35 - "[ --forward <signing keyid> ] <URL> " \
2.36 - "<update type> <action> <update>..."
2.37 + print >>sys.stderr, """\
2.38 +Need a signer, recipient, URL, update type, action and some updates as arguments to this program.
2.39 +
2.40 +Syntax:
2.41 +
2.42 +%s <signing keyid> <recipient keyid> [ --forward <signing keyid> ] <URL> \\
2.43 + <update type> <action> <update or part>...
2.44 +
2.45 +The update type is typically "collection" for a number of separate updates,
2.46 +or any other value for a single multipart update consisting of several parts.
2.47 +
2.48 +The action may be "update", "replace" or "store", with subsequent updates
2.49 +being text strings containing text for individual updates (or parts of a single
2.50 +update). If action is "file", however, subsequent updates must refer to files
2.51 +and communicated updates will be given a "store" update action.
2.52 +""" % sys.argv[0]
2.53 sys.exit(1)
2.54
2.55 message = Message()
2.56 parts = []
2.57
2.58 + # A collection of updates involves adding each update directly to the
2.59 + # message. A single update involves collecting the given parts, combining
2.60 + # them and putting the combined update in the message.
2.61 +
2.62 for arg in args:
2.63 - part = MIMEText(arg, "moin", sys.stdin.encoding)
2.64 +
2.65 + # Read files and assign filenames to them, or read argument strings, and
2.66 + # adopt them as parts.
2.67 +
2.68 + if action == "file":
2.69 + part = readfile(arg)
2.70 + part["Content-Disposition"] = split(arg)[-1]
2.71 + else:
2.72 + part = MIMEText(arg, "moin", sys.stdin.encoding)
2.73 +
2.74 if type == "collection":
2.75 - part["Update-Action"] = action
2.76 - message.add_update(part)
2.77 + add_update(message, action, part)
2.78 else:
2.79 parts.append(part)
2.80
2.81 + # Obtain the alternative representations as an update and add it to the
2.82 + # message.
2.83 +
2.84 if type != "collection":
2.85 multipart = message.get_update(parts)
2.86 - multipart["Update-Action"] = action
2.87 - message.add_update(multipart)
2.88 + add_update(message, action, multipart)
2.89
2.90 email_message = message.get_payload()
2.91 gpg = GPG()