Barry Warsaw | e75888e | 1999-01-14 20:00:58 +0000 | [diff] [blame] | 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 |
| 7 | |
| 8 | def test(msg, results): |
| 9 | fp = StringIO() |
| 10 | fp.write(msg) |
| 11 | fp.seek(0) |
| 12 | m = rfc822.Message(fp) |
| 13 | i = 0 |
Guido van Rossum | 3ed1be9 | 1999-05-03 19:57:01 +0000 | [diff] [blame] | 14 | |
Barry Warsaw | e75888e | 1999-01-14 20:00:58 +0000 | [diff] [blame] | 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) |
| 31 | |
Guido van Rossum | 3ed1be9 | 1999-05-03 19:57:01 +0000 | [diff] [blame] | 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 |
| 43 | |
| 44 | # Note: all test cases must have the same date (in various formats), |
| 45 | # or no date! |
| 46 | |
Barry Warsaw | e75888e | 1999-01-14 20:00:58 +0000 | [diff] [blame] | 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 |
| 52 | |
| 53 | test2 |
| 54 | ''', [('Guido van\n : Rossum', 'guido@python.org')]) |
| 55 | |
| 56 | test('''From: Barry <bwarsaw@python.org |
| 57 | To: guido@python.org (Guido: the Barbarian) |
| 58 | Subject: nonsense |
Guido van Rossum | 3ed1be9 | 1999-05-03 19:57:01 +0000 | [diff] [blame] | 59 | Date: Wednesday, January 13 1999 23:57:35 -0500 |
Barry Warsaw | e75888e | 1999-01-14 20:00:58 +0000 | [diff] [blame] | 60 | |
| 61 | test''', [('Guido: the Barbarian', 'guido@python.org'), |
| 62 | ]) |
| 63 | |
| 64 | test('''From: Barry <bwarsaw@python.org |
| 65 | To: guido@python.org (Guido: the Barbarian) |
| 66 | Cc: "Guido: the Madman" <guido@python.org> |
Guido van Rossum | 3ed1be9 | 1999-05-03 19:57:01 +0000 | [diff] [blame] | 67 | Date: 13-Jan-1999 23:57:35 EST |
Barry Warsaw | e75888e | 1999-01-14 20:00:58 +0000 | [diff] [blame] | 68 | |
| 69 | test''', [('Guido: the Barbarian', 'guido@python.org'), |
| 70 | ('Guido: the Madman', 'guido@python.org') |
| 71 | ]) |
| 72 | |
| 73 | test('''To: "The monster with |
| 74 | the very long name: Guido" <guido@python.org> |
Guido van Rossum | 3ed1be9 | 1999-05-03 19:57:01 +0000 | [diff] [blame] | 75 | Date: Wed, 13 Jan 1999 23:57:35 -0500 |
Barry Warsaw | e75888e | 1999-01-14 20:00:58 +0000 | [diff] [blame] | 76 | |
| 77 | test''', [('The monster with\n the very long name: Guido', |
| 78 | 'guido@python.org')]) |
| 79 | |
| 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 |
Guido van Rossum | 3ed1be9 | 1999-05-03 19:57:01 +0000 | [diff] [blame] | 85 | Date: Wed, 13 Jan 1999 23:57:35 -0500 |
Barry Warsaw | e75888e | 1999-01-14 20:00:58 +0000 | [diff] [blame] | 86 | |
| 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'), |
| 93 | ]) |
| 94 | |
| 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> |
Guido van Rossum | 3ed1be9 | 1999-05-03 19:57:01 +0000 | [diff] [blame] | 98 | Date: Wed, 13 Jan 1999 23:57:35 -0500 |
Barry Warsaw | e75888e | 1999-01-14 20:00:58 +0000 | [diff] [blame] | 99 | |
| 100 | test''', [('', ''), |
| 101 | ('', 'dd47@mail.xxx.edu'), |
| 102 | ('', '_at_hmhq@hdq-mdm1-imgout.companay.com') |
| 103 | ]) |
Fred Drake | 5712fa9 | 1999-04-28 17:38:31 +0000 | [diff] [blame] | 104 | |
| 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> |
| 108 | |
| 109 | test''', [('last, first', 'userid@foo.net'), |
| 110 | ]) |
Guido van Rossum | 47ac4e6 | 1999-06-15 18:56:46 +0000 | [diff] [blame] | 111 | |
| 112 | test('''To: (Comment stuff) "Quoted name"@somewhere.com |
| 113 | |
| 114 | test''', [('Comment stuff', '"Quoted name"@somewhere.com'), |
| 115 | ]) |
Barry Warsaw | 7c5b9d1 | 1999-07-12 18:47:00 +0000 | [diff] [blame] | 116 | |
| 117 | test('''To: : |
| 118 | Cc: goit@lip.com |
| 119 | Date: Wed, 13 Jan 1999 23:57:35 -0500 |
| 120 | |
| 121 | test''', [('', 'goit@lip.com')]) |
| 122 | |