blob: a2b51513e44938563182cc01421a305c33f63457 [file] [log] [blame]
Barry Warsawe75888e1999-01-14 20:00:58 +00001from test_support import verbose
2import rfc822, sys
3try:
4 from cStringIO import StringIO
5except ImportError:
6 from StringIO import StringIO
7
8def 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)
30
31test('''Date: Wed, 13 Jan 1999 23:57:35 -0500
32From: Guido van Rossum <guido@CNRI.Reston.VA.US>
33To: "Guido van
34 : Rossum" <guido@python.org>
35Subject: test2
36
37test2
38''', [('Guido van\n : Rossum', 'guido@python.org')])
39
40test('''From: Barry <bwarsaw@python.org
41To: guido@python.org (Guido: the Barbarian)
42Subject: nonsense
43
44test''', [('Guido: the Barbarian', 'guido@python.org'),
45 ])
46
47test('''From: Barry <bwarsaw@python.org
48To: guido@python.org (Guido: the Barbarian)
49Cc: "Guido: the Madman" <guido@python.org>
50
51test''', [('Guido: the Barbarian', 'guido@python.org'),
52 ('Guido: the Madman', 'guido@python.org')
53 ])
54
55test('''To: "The monster with
56 the very long name: Guido" <guido@python.org>
57
58test''', [('The monster with\n the very long name: Guido',
59 'guido@python.org')])
60
61test('''To: "Amit J. Patel" <amitp@Theory.Stanford.EDU>
62CC: Mike Fletcher <mfletch@vrtelecom.com>,
63 "'string-sig@python.org'" <string-sig@python.org>
64Cc: fooz@bat.com, bart@toof.com
65Cc: goit@lip.com
66
67test''', [('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'),
73 ])
74
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!
77test('''To: <[smtp:dd47@mail.xxx.edu]_at_hmhq@hdq-mdm1-imgout.companay.com>
78
79test''', [('', ''),
80 ('', 'dd47@mail.xxx.edu'),
81 ('', '_at_hmhq@hdq-mdm1-imgout.companay.com')
82 ])
Fred Drake5712fa91999-04-28 17:38:31 +000083
84# This exercises the old commas-in-a-full-name bug, which should be doing the
85# right thing in recent versions of the module.
86test('''To: "last, first" <userid@foo.net>
87
88test''', [('last, first', 'userid@foo.net'),
89 ])