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