PyXR

c:\python24\lib \ test \ test_multifile.py



0001 import mimetools
0002 import multifile
0003 import cStringIO
0004 
0005 msg = """Mime-Version: 1.0
0006 Content-Type: multipart/mixed;
0007         boundary="=====================_590453667==_"
0008 X-OriginalArrivalTime: 05 Feb 2002 03:43:23.0310 (UTC) FILETIME=[42D88CE0:01C1ADF7]
0009 
0010 --=====================_590453667==_
0011 Content-Type: multipart/alternative;
0012         boundary="=====================_590453677==_.ALT"
0013 
0014 --=====================_590453677==_.ALT
0015 Content-Type: text/plain; charset="us-ascii"; format=flowed
0016 
0017 test A
0018 --=====================_590453677==_.ALT
0019 Content-Type: text/html; charset="us-ascii"
0020 
0021 <html>
0022 <b>test B</font></b></html>
0023 
0024 --=====================_590453677==_.ALT--
0025 
0026 --=====================_590453667==_
0027 Content-Type: text/plain; charset="us-ascii"
0028 Content-Disposition: attachment; filename="att.txt"
0029 
0030 Attached Content.
0031 Attached Content.
0032 Attached Content.
0033 Attached Content.
0034 
0035 --=====================_590453667==_--
0036 
0037 """
0038 
0039 def getMIMEMsg(mf):
0040     global boundaries, linecount
0041     msg = mimetools.Message(mf)
0042 
0043     #print "TYPE: %s" % msg.gettype()
0044     if msg.getmaintype() == 'multipart':
0045         boundary = msg.getparam("boundary")
0046         boundaries += 1
0047 
0048         mf.push(boundary)
0049         while mf.next():
0050             getMIMEMsg(mf)
0051         mf.pop()
0052     else:
0053         lines = mf.readlines()
0054         linecount += len(lines)
0055 
0056 def test_main():
0057     global boundaries, linecount
0058     boundaries = 0
0059     linecount = 0
0060     f = cStringIO.StringIO(msg)
0061     getMIMEMsg(multifile.MultiFile(f))
0062     assert boundaries == 2
0063     assert linecount == 9
0064 
0065 if __name__ == '__main__':
0066     test_main()
0067 

Generated by PyXR 0.9.4
SourceForge.net Logo