1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# Copyright (C) 2001 by the Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""Test the bounce detection modules."""
import sys
import os
import unittest
from mimelib.Parser import Parser
class BounceTest(unittest.TestCase):
DATA = (
# Postfix bounces
('Postfix', 'postfix_01.txt', ['xxxxx@local.ie']),
('Postfix', 'postfix_02.txt', ['yyyyy@digicool.com']),
('Postfix', 'postfix_03.txt', ['ttttt@ggggg.com']),
('Postfix', 'postfix_04.txt', ['davidlowie@mail1.keftamail.com']),
('Postfix', 'postfix_05.txt', ['bjelf@detectit.net']),
# SimpleMatch bounces
('SimpleMatch', 'sendmail_01.txt', ['zzzzz@nfg.nl']),
('SimpleMatch', 'simple_01.txt', ['bbbsss@turbosport.com']),
('SimpleMatch', 'simple_02.txt', ['chris.ggggmmmm@usa.net']),
('SimpleMatch', 'simple_04.txt', ['claird@starbase.neosoft.com']),
('SimpleMatch', 'newmailru_01.txt', ['zzzzz@newmail.ru']),
# SimpleWarning
('SimpleWarning', 'simple_03.txt', ['jacobus@geo.co.za']),
# GroupWise
('GroupWise', 'groupwise_01.txt', ['thoff@MAINEX1.ASU.EDU']),
# Yale's own
('Yale', 'yale_01.txt', ['thomas.dtankengine@cs.yale.edu',
'thomas.dtankengine@yale.edu']),
# DSN, i.e. RFC 1894
('DSN', 'dsn_01.txt', ['JimmyMcEgypt@go.com']),
('DSN', 'dsn_02.txt', ['zzzzz@zeus.hud.ac.uk']),
('DSN', 'dsn_03.txt', ['ddd.kkk@advalvas.be']),
('DSN', 'dsn_04.txt', ['max.haas@unibas.ch']),
('DSN', 'dsn_05.txt', ['pkocmid@atlas.cz']),
('DSN', 'dsn_06.txt', ['hao-nghi.au@fr.thalesgroup.com']),
('DSN', 'dsn_07.txt', ['david.farrar@parliament.govt.nz']),
# SMTP32
('SMTP32', 'smtp32_01.txt', ['oliver@pcworld.com.ph']),
('SMTP32', 'smtp32_02.txt', ['lists@mail.spicynoodles.com']),
('SMTP32', 'smtp32_03.txt', ['borisk@gw.xraymedia.com']),
# LLNL's custom Sendmail
('LLNL', 'llnl_01.txt', ['trotts1@llnl.gov']),
# No address can be detected in these...
# dumbass_01.txt - We love Microsoft. :(
# Done
)
def checkBounce(self):
for modname, file, addrs in self.DATA:
module = 'Mailman.Bouncers.' + modname
__import__(module)
fp = open(os.path.join('tests', 'bounces', file))
try:
msg = Parser().parse(fp)
finally:
fp.close()
foundaddrs = sys.modules[module].process(msg)
addrs.sort()
foundaddrs.sort()
self.assertEqual(addrs, foundaddrs)
def checkSMTP32Failure(self):
from Mailman.Bouncers import SMTP32
# This file has no X-Mailer: header
fp = open(os.path.join('tests', 'bounces', 'postfix_01.txt'))
try:
msg = Parser().parse(fp)
finally:
fp.close()
self.failIf(msg['x-mailer'] is not None)
self.failIf(SMTP32.process(msg))
def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(BounceTest, 'check'))
return suite
if __name__ == '__main__':
unittest.main(defaultTest='suite')
|