1 from test_support
import verbose
4 from cStringIO
import StringIO
6 from StringIO
import StringIO
8 def test(msg
, results
):
12 m
= rfc822
.Message(fp
)
15 for n
, a
in m
.getaddrlist('to') + m
.getaddrlist('cc'):
17 print 'name:', repr(n
), 'addr:', repr(a
)
19 mn
, ma
= results
[i
][0], results
[i
][1]
21 print 'extra parsed address:', repr(n
), repr(a
)
24 if mn
== n
and ma
== a
:
30 print 'not found:', repr(n
), repr(a
)
32 out
= m
.getdate('date')
35 print 'Date:', m
.getheader('date')
36 if out
== (1999, 1, 13, 23, 57, 35, 0, 0, 0):
42 print 'Date conversion failed:', out
44 # Note: all test cases must have the same date (in various formats),
47 test('''Date: Wed, 13 Jan 1999 23:57:35 -0500
48 From: Guido van Rossum <guido@CNRI.Reston.VA.US>
50 : Rossum" <guido@python.org>
54 ''', [('Guido van\n : Rossum', 'guido@python.org')])
56 test('''From: Barry <bwarsaw@python.org
57 To: guido@python.org (Guido: the Barbarian)
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',
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
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'),
91 ('', 'bart@toof.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
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'),
119 Date: Wed, 13 Jan 1999 23:57:35 -0500
121 test''', [('', 'goit@lip.com')])