Fix an amazing number of typos & malformed sentences reported by Detlef
[python/dscho.git] / Lib / dos-8x3 / test_rfc.py
blobb8ae8c70ad73fa9d5d7b9b8cbf824ba8784359a1
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
14 for n, a in m.getaddrlist('to') + m.getaddrlist('cc'):
15 if verbose:
16 print 'name:', repr(n), 'addr:', repr(a)
17 try:
18 mn, ma = results[i][0], results[i][1]
19 except IndexError:
20 print 'extra parsed address:', repr(n), repr(a)
21 continue
22 i = i + 1
23 if mn == n and ma == a:
24 if verbose:
25 print ' [matched]'
26 else:
27 if verbose:
28 print ' [no match]'
29 print 'not found:', repr(n), repr(a)
31 test('''Date: Wed, 13 Jan 1999 23:57:35 -0500
32 From: Guido van Rossum <guido@CNRI.Reston.VA.US>
33 To: "Guido van
34 : Rossum" <guido@python.org>
35 Subject: test2
37 test2
38 ''', [('Guido van\n : Rossum', 'guido@python.org')])
40 test('''From: Barry <bwarsaw@python.org
41 To: guido@python.org (Guido: the Barbarian)
42 Subject: nonsense
44 test''', [('Guido: the Barbarian', 'guido@python.org'),
47 test('''From: Barry <bwarsaw@python.org
48 To: guido@python.org (Guido: the Barbarian)
49 Cc: "Guido: the Madman" <guido@python.org>
51 test''', [('Guido: the Barbarian', 'guido@python.org'),
52 ('Guido: the Madman', 'guido@python.org')
55 test('''To: "The monster with
56 the very long name: Guido" <guido@python.org>
58 test''', [('The monster with\n the very long name: Guido',
59 'guido@python.org')])
61 test('''To: "Amit J. Patel" <amitp@Theory.Stanford.EDU>
62 CC: Mike Fletcher <mfletch@vrtelecom.com>,
63 "'string-sig@python.org'" <string-sig@python.org>
64 Cc: fooz@bat.com, bart@toof.com
65 Cc: goit@lip.com
67 test''', [('Amit J. Patel', 'amitp@Theory.Stanford.EDU'),
68 ('Mike Fletcher', 'mfletch@vrtelecom.com'),
69 ("'string-sig@python.org'", 'string-sig@python.org'),
70 ('', 'fooz@bat.com'),
71 ('', 'bart@toof.com'),
72 ('', 'goit@lip.com'),
75 # This one is just twisted. I don't know what the proper result should be,
76 # but it shouldn't be to infloop, which is what used to happen!
77 test('''To: <[smtp:dd47@mail.xxx.edu]_at_hmhq@hdq-mdm1-imgout.companay.com>
79 test''', [('', ''),
80 ('', 'dd47@mail.xxx.edu'),
81 ('', '_at_hmhq@hdq-mdm1-imgout.companay.com')