Brett Cannon | 43e5ef4 | 2008-05-12 03:19:20 +0000 | [diff] [blame] | 1 | from test import test_support |
Ezio Melotti | a2d4653 | 2010-01-30 07:22:54 +0000 | [diff] [blame] | 2 | mimetools = test_support.import_module('mimetools', deprecated=True) |
Brett Cannon | 43e5ef4 | 2008-05-12 03:19:20 +0000 | [diff] [blame] | 3 | multifile = test_support.import_module('multifile', deprecated=True) |
Martin v. Löwis | a6026c6 | 2002-09-22 09:01:08 +0000 | [diff] [blame] | 4 | import cStringIO |
| 5 | |
| 6 | msg = """Mime-Version: 1.0 |
| 7 | Content-Type: multipart/mixed; |
Guido van Rossum | bffa52f | 2002-09-29 00:25:51 +0000 | [diff] [blame] | 8 | boundary="=====================_590453667==_" |
Martin v. Löwis | a6026c6 | 2002-09-22 09:01:08 +0000 | [diff] [blame] | 9 | X-OriginalArrivalTime: 05 Feb 2002 03:43:23.0310 (UTC) FILETIME=[42D88CE0:01C1ADF7] |
| 10 | |
| 11 | --=====================_590453667==_ |
| 12 | Content-Type: multipart/alternative; |
Guido van Rossum | bffa52f | 2002-09-29 00:25:51 +0000 | [diff] [blame] | 13 | boundary="=====================_590453677==_.ALT" |
Martin v. Löwis | a6026c6 | 2002-09-22 09:01:08 +0000 | [diff] [blame] | 14 | |
| 15 | --=====================_590453677==_.ALT |
| 16 | Content-Type: text/plain; charset="us-ascii"; format=flowed |
| 17 | |
| 18 | test A |
| 19 | --=====================_590453677==_.ALT |
| 20 | Content-Type: text/html; charset="us-ascii" |
| 21 | |
| 22 | <html> |
| 23 | <b>test B</font></b></html> |
| 24 | |
| 25 | --=====================_590453677==_.ALT-- |
| 26 | |
| 27 | --=====================_590453667==_ |
| 28 | Content-Type: text/plain; charset="us-ascii" |
| 29 | Content-Disposition: attachment; filename="att.txt" |
| 30 | |
| 31 | Attached Content. |
| 32 | Attached Content. |
| 33 | Attached Content. |
| 34 | Attached Content. |
| 35 | |
| 36 | --=====================_590453667==_-- |
| 37 | |
| 38 | """ |
| 39 | |
Martin v. Löwis | a6026c6 | 2002-09-22 09:01:08 +0000 | [diff] [blame] | 40 | def getMIMEMsg(mf): |
| 41 | global boundaries, linecount |
| 42 | msg = mimetools.Message(mf) |
| 43 | |
| 44 | #print "TYPE: %s" % msg.gettype() |
| 45 | if msg.getmaintype() == 'multipart': |
| 46 | boundary = msg.getparam("boundary") |
| 47 | boundaries += 1 |
| 48 | |
| 49 | mf.push(boundary) |
Guido van Rossum | bffa52f | 2002-09-29 00:25:51 +0000 | [diff] [blame] | 50 | while mf.next(): |
| 51 | getMIMEMsg(mf) |
Martin v. Löwis | a6026c6 | 2002-09-22 09:01:08 +0000 | [diff] [blame] | 52 | mf.pop() |
| 53 | else: |
| 54 | lines = mf.readlines() |
| 55 | linecount += len(lines) |
| 56 | |
Neal Norwitz | 996acf1 | 2003-02-17 14:51:41 +0000 | [diff] [blame] | 57 | def test_main(): |
Michael W. Hudson | 5bf2516 | 2004-08-03 11:14:09 +0000 | [diff] [blame] | 58 | global boundaries, linecount |
| 59 | boundaries = 0 |
| 60 | linecount = 0 |
Martin v. Löwis | a6026c6 | 2002-09-22 09:01:08 +0000 | [diff] [blame] | 61 | f = cStringIO.StringIO(msg) |
| 62 | getMIMEMsg(multifile.MultiFile(f)) |
| 63 | assert boundaries == 2 |
| 64 | assert linecount == 9 |
| 65 | |
| 66 | if __name__ == '__main__': |
Neal Norwitz | 996acf1 | 2003-02-17 14:51:41 +0000 | [diff] [blame] | 67 | test_main() |