"""Test the bounce detection modules."""
import sys
import os
import unittest
import email
class BounceTest(unittest.TestCase):
DATA = (
('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']),
('Exim', 'exim_01.txt', ['delangen@its.tudelft.nl']),
('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']),
('SimpleMatch', 'hotpop_01.txt', ['allensmithee@hotpop.com']),
('SimpleWarning', 'simple_03.txt', ['jacobus@geo.co.za']),
('GroupWise', 'groupwise_01.txt', ['thoff@MAINEX1.ASU.EDU']),
('GroupWise', 'groupwise_02.txt', []),
('Yale', 'yale_01.txt', ['thomas.dtankengine@cs.yale.edu',
'thomas.dtankengine@yale.edu']),
('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']),
('DSN', 'dsn_08.txt', ['news-list.zope@localhost.bln.innominate.de']),
('DSN', 'dsn_09.txt', ['pr@allen-heath.com']),
('DSN', 'dsn_10.txt', ['anne.person@dom.ain']),
('DSN', 'dsn_11.txt', ['joem@example.com']),
('Exchange', 'microsoft_01.txt', ['DJBENNETT@IKON.COM']),
('Exchange', 'microsoft_02.txt', ['MDMOORE@BALL.COM']),
('SMTP32', 'smtp32_01.txt', ['oliver@pcworld.com.ph']),
('SMTP32', 'smtp32_02.txt', ['lists@mail.spicynoodles.com']),
('SMTP32', 'smtp32_03.txt', ['borisk@gw.xraymedia.com']),
('Qmail', 'qmail_01.txt', ['psadisc@wwwmail.n-h.de']),
('LLNL', 'llnl_01.txt', ['trotts1@llnl.gov']),
('Netscape', 'netscape_01.txt', ['aaaaa@corel.com',
'bbbbb@corel.com']),
('Yahoo', 'yahoo_01.txt', ['subscribe.motorcycles@listsociety.com']),
('Yahoo', 'yahoo_02.txt', ['agarciamartiartu@yahoo.es']),
('Yahoo', 'yahoo_03.txt', ['cresus22@yahoo.com']),
('Yahoo', 'yahoo_04.txt', ['agarciamartiartu@yahoo.es',
'open00now@yahoo.co.uk']),
('Yahoo', 'yahoo_05.txt', ['cresus22@yahoo.com',
'jjb700@yahoo.com']),
('Yahoo', 'yahoo_06.txt', ['andrew_polevoy@yahoo.com',
'baruch_sterin@yahoo.com',
'rjhoeks@yahoo.com',
'tritonrugger91@yahoo.com']),
('Yahoo', 'yahoo_07.txt', ['mark1960_1998@yahoo.com',
'ovchenkov@yahoo.com',
'tsa412@yahoo.com',
'vaxheadroom@yahoo.com']),
('Yahoo', 'yahoo_08.txt', ['chatrathis@yahoo.com',
'crownjules01@yahoo.com',
'cwl_999@yahoo.com',
'eichaiwiu@yahoo.com',
'rjhoeks@yahoo.com',
'yuli_kolesnikov@yahoo.com']),
('Yahoo', 'yahoo_09.txt', ['hankel_o_fung@yahoo.com',
'ultravirus2001@yahoo.com']),
('Sina', 'sina_01.txt', ['boboman76@sina.com', 'alan_t18@sina.com']),
)
def test_bounce(self):
for modname, file, addrs in self.DATA:
module = 'Mailman.Bouncers.' + modname
__import__(module)
fp = open(os.path.join('tests', 'bounces', file))
try:
msg = email.message_from_file(fp)
finally:
fp.close()
foundaddrs = sys.modules[module].process(msg)
if foundaddrs is None:
foundaddrs = []
addrs.sort()
foundaddrs.sort()
self.assertEqual(addrs, foundaddrs)
def test_SMTP32_failure(self):
from Mailman.Bouncers import SMTP32
fp = open(os.path.join('tests', 'bounces', 'postfix_01.txt'))
try:
msg = email.message_from_file(fp)
finally:
fp.close()
self.failIf(msg['x-mailer'] is not None)
self.failIf(SMTP32.process(msg))
def test_caiwireless(self):
from Mailman.Bouncers import Caiwireless
msg = email.message_from_string("""\
Content-Type: multipart/report; boundary=BOUNDARY
--BOUNDARY
--BOUNDARY--
""")
self.assertEqual(None, Caiwireless.process(msg))
def test_microsoft(self):
from Mailman.Bouncers import Microsoft
msg = email.message_from_string("""\
Content-Type: multipart/report; boundary=BOUNDARY
--BOUNDARY
--BOUNDARY--
""")
self.assertEqual(None, Microsoft.process(msg))
def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(BounceTest))
return suite
if __name__ == '__main__':
unittest.main(defaultTest='suite')