blob: 6cb946f89926f2f118f5877198fad079f8e125d6 [file] [log] [blame]
Martin v. Löwisa6026c62002-09-22 09:01:08 +00001import mimetools
2import multifile
3import cStringIO
4
5msg = """Mime-Version: 1.0
6Content-Type: multipart/mixed;
Guido van Rossumbffa52f2002-09-29 00:25:51 +00007 boundary="=====================_590453667==_"
Martin v. Löwisa6026c62002-09-22 09:01:08 +00008X-OriginalArrivalTime: 05 Feb 2002 03:43:23.0310 (UTC) FILETIME=[42D88CE0:01C1ADF7]
9
10--=====================_590453667==_
11Content-Type: multipart/alternative;
Guido van Rossumbffa52f2002-09-29 00:25:51 +000012 boundary="=====================_590453677==_.ALT"
Martin v. Löwisa6026c62002-09-22 09:01:08 +000013
14--=====================_590453677==_.ALT
15Content-Type: text/plain; charset="us-ascii"; format=flowed
16
17test A
18--=====================_590453677==_.ALT
19Content-Type: text/html; charset="us-ascii"
20
21<html>
22<b>test B</font></b></html>
23
24--=====================_590453677==_.ALT--
25
26--=====================_590453667==_
27Content-Type: text/plain; charset="us-ascii"
28Content-Disposition: attachment; filename="att.txt"
29
30Attached Content.
31Attached Content.
32Attached Content.
33Attached Content.
34
35--=====================_590453667==_--
36
37"""
38
39boundaries = 0
40linecount = 0
41
42def getMIMEMsg(mf):
43 global boundaries, linecount
44 msg = mimetools.Message(mf)
45
46 #print "TYPE: %s" % msg.gettype()
47 if msg.getmaintype() == 'multipart':
48 boundary = msg.getparam("boundary")
49 boundaries += 1
50
51 mf.push(boundary)
Guido van Rossumbffa52f2002-09-29 00:25:51 +000052 while mf.next():
53 getMIMEMsg(mf)
Martin v. Löwisa6026c62002-09-22 09:01:08 +000054 mf.pop()
55 else:
56 lines = mf.readlines()
57 linecount += len(lines)
58
59def main():
60 f = cStringIO.StringIO(msg)
61 getMIMEMsg(multifile.MultiFile(f))
62 assert boundaries == 2
63 assert linecount == 9
64
65if __name__ == '__main__':
66 main()