Last set of CW Pro 5 projects (probably)
[python/dscho.git] / Lib / dos-8x3 / test_rfc.py
blob0d4c66f88096a1e3e04f556e4ab71bc63a983f30
1 from test_support import verbose
2 import rfc822, sys
3 try:
4 from cStringIO import StringIO
5 except ImportError:
6 from StringIO import StringIO
8 def test(msg, results):
9 fp = StringIO()
10 fp.write(msg)
11 fp.seek(0)
12 m = rfc822.Message(fp)
13 i = 0
15 for n, a in m.getaddrlist('to') + m.getaddrlist('cc'):
16 if verbose:
17 print 'name:', repr(n), 'addr:', repr(a)
18 try:
19 mn, ma = results[i][0], results[i][1]
20 except IndexError:
21 print 'extra parsed address:', repr(n), repr(a)
22 continue
23 i = i + 1
24 if mn == n and ma == a:
25 if verbose:
26 print ' [matched]'
27 else:
28 if verbose:
29 print ' [no match]'
30 print 'not found:', repr(n), repr(a)
32 out = m.getdate('date')
33 if out:
34 if verbose:
35 print 'Date:', m.getheader('date')
36 if out == (1999, 1, 13, 23, 57, 35, 0, 0, 0):
37 if verbose:
38 print ' [matched]'
39 else:
40 if verbose:
41 print ' [no match]'
42 print 'Date conversion failed:', out
44 # Note: all test cases must have the same date (in various formats),
45 # or no date!
47 test('''Date: Wed, 13 Jan 1999 23:57:35 -0500
48 From: Guido van Rossum <guido@CNRI.Reston.VA.US>
49 To: "Guido van
50 : Rossum" <guido@python.org>
51 Subject: test2
53 test2
54 ''', [('Guido van\n : Rossum', 'guido@python.org')])
56 test('''From: Barry <bwarsaw@python.org
57 To: guido@python.org (Guido: the Barbarian)
58 Subject: nonsense
59 Date: Wednesday, January 13 1999 23:57:35 -0500
61 test''', [('Guido: the Barbarian', 'guido@python.org'),
64 test('''From: Barry <bwarsaw@python.org
65 To: guido@python.org (Guido: the Barbarian)
66 Cc: "Guido: the Madman" <guido@python.org>
67 Date: 13-Jan-1999 23:57:35 EST
69 test''', [('Guido: the Barbarian', 'guido@python.org'),
70 ('Guido: the Madman', 'guido@python.org')
73 test('''To: "The monster with
74 the very long name: Guido" <guido@python.org>
75 Date: Wed, 13 Jan 1999 23:57:35 -0500
77 test''', [('The monster with\n the very long name: Guido',
78 'guido@python.org')])
80 test('''To: "Amit J. Patel" <amitp@Theory.Stanford.EDU>
81 CC: Mike Fletcher <mfletch@vrtelecom.com>,
82 "'string-sig@python.org'" <string-sig@python.org>
83 Cc: fooz@bat.com, bart@toof.com
84 Cc: goit@lip.com
85 Date: Wed, 13 Jan 1999 23:57:35 -0500
87 test''', [('Amit J. Patel', 'amitp@Theory.Stanford.EDU'),
88 ('Mike Fletcher', 'mfletch@vrtelecom.com'),
89 ("'string-sig@python.org'", 'string-sig@python.org'),
90 ('', 'fooz@bat.com'),
91 ('', 'bart@toof.com'),
92 ('', 'goit@lip.com'),
95 # This one is just twisted. I don't know what the proper result should be,
96 # but it shouldn't be to infloop, which is what used to happen!
97 test('''To: <[smtp:dd47@mail.xxx.edu]_at_hmhq@hdq-mdm1-imgout.companay.com>
98 Date: Wed, 13 Jan 1999 23:57:35 -0500
100 test''', [('', ''),
101 ('', 'dd47@mail.xxx.edu'),
102 ('', '_at_hmhq@hdq-mdm1-imgout.companay.com')
105 # This exercises the old commas-in-a-full-name bug, which should be doing the
106 # right thing in recent versions of the module.
107 test('''To: "last, first" <userid@foo.net>
109 test''', [('last, first', 'userid@foo.net'),
112 test('''To: (Comment stuff) "Quoted name"@somewhere.com
114 test''', [('Comment stuff', '"Quoted name"@somewhere.com'),
117 test('''To: :
118 Cc: goit@lip.com
119 Date: Wed, 13 Jan 1999 23:57:35 -0500
121 test''', [('', 'goit@lip.com')])