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