test_multifile.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. from test import test_support
  2. mimetools = test_support.import_module('mimetools', deprecated=True)
  3. multifile = test_support.import_module('multifile', deprecated=True)
  4. import cStringIO
  5. msg = """Mime-Version: 1.0
  6. Content-Type: multipart/mixed;
  7. boundary="=====================_590453667==_"
  8. X-OriginalArrivalTime: 05 Feb 2002 03:43:23.0310 (UTC) FILETIME=[42D88CE0:01C1ADF7]
  9. --=====================_590453667==_
  10. Content-Type: multipart/alternative;
  11. boundary="=====================_590453677==_.ALT"
  12. --=====================_590453677==_.ALT
  13. Content-Type: text/plain; charset="us-ascii"; format=flowed
  14. test A
  15. --=====================_590453677==_.ALT
  16. Content-Type: text/html; charset="us-ascii"
  17. <html>
  18. <b>test B</font></b></html>
  19. --=====================_590453677==_.ALT--
  20. --=====================_590453667==_
  21. Content-Type: text/plain; charset="us-ascii"
  22. Content-Disposition: attachment; filename="att.txt"
  23. Attached Content.
  24. Attached Content.
  25. Attached Content.
  26. Attached Content.
  27. --=====================_590453667==_--
  28. """
  29. def getMIMEMsg(mf):
  30. global boundaries, linecount
  31. msg = mimetools.Message(mf)
  32. #print "TYPE: %s" % msg.gettype()
  33. if msg.getmaintype() == 'multipart':
  34. boundary = msg.getparam("boundary")
  35. boundaries += 1
  36. mf.push(boundary)
  37. while mf.next():
  38. getMIMEMsg(mf)
  39. mf.pop()
  40. else:
  41. lines = mf.readlines()
  42. linecount += len(lines)
  43. def test_main():
  44. global boundaries, linecount
  45. boundaries = 0
  46. linecount = 0
  47. f = cStringIO.StringIO(msg)
  48. getMIMEMsg(multifile.MultiFile(f))
  49. assert boundaries == 2
  50. assert linecount == 9
  51. if __name__ == '__main__':
  52. test_main()