------------------------------------------------------------ revno: 6523 committer: Barry Warsaw <[EMAIL PROTECTED]> branch nick: 3.0 timestamp: Thu 2007-07-05 10:29:40 -0400 message: Convert the SpamDetect handler tests (what there was of them anyway) to a doctest, but don't otherwise clean up the handler module. added: Mailman/docs/antispam.txt modified: Mailman/testing/test_handlers.py
=== added file 'Mailman/docs/antispam.txt' --- a/Mailman/docs/antispam.txt 1970-01-01 00:00:00 +0000 +++ b/Mailman/docs/antispam.txt 2007-07-05 14:29:40 +0000 @@ -0,0 +1,75 @@ +Anti-spam defences +================== + +By design, Mailman does not have very sophisticated anti-spam measures because +this type of filtering is done much more efficiently at the MTA level. For +example, if Mailman were to do spam detection, it could not reject the message +at SMTP time. + +Still, Mailman does employ a small number of rather ham-handed anti-spam +measures. + + >>> from Mailman.Handlers.SpamDetect import process + >>> from Mailman.Message import Message + >>> from Mailman.Queue.Switchboard import Switchboard + >>> from Mailman.configuration import config + >>> from Mailman.database import flush + >>> from email import message_from_string + >>> mlist = config.list_manager.create('[EMAIL PROTECTED]') + >>> flush() + + +Short circuiting +---------------- + +If a message is pre-approved, this handler does nothing. + + >>> msg = message_from_string("""\ + ... From: [EMAIL PROTECTED] + ... + ... An important message. + ... """, Message) + >>> msgdata = {'approved': True} + >>> process(mlist, msg, msgdata) + >>> print msg.as_string() + From: [EMAIL PROTECTED] + <BLANKLINE> + An important message. + <BLANKLINE> + >>> msgdata + {'approved': True} + + +Header matching +--------------- + +There is a global configuration variable that can be set to a list of header +matches. Each item in that list is a 2-tuple of the header to match and a +regular expression. For example, if we wanted to block all message that come +from 'aperson' regardless of the domain, we'd do something like the following +in our mailman.cfg file: + + >>> config.KNOWN_SPAMMERS.append(('from', 'aperson')) + +Now if the same message is posted to the mailing list, and that message is not +pre-approved. The handler will throw an exception that signals the message is +spam. + + >>> msgdata = {} + >>> process(mlist, msg, msgdata) + Traceback (most recent call last): + ... + SpamDetected + >>> print msg.as_string() + From: [EMAIL PROTECTED] + <BLANKLINE> + An important message. + <BLANKLINE> + >>> msgdata + {} + + +Header filter rules +------------------- + +XXX Need tests. === modified file 'Mailman/testing/test_handlers.py' --- a/Mailman/testing/test_handlers.py 2007-07-04 04:16:48 +0000 +++ b/Mailman/testing/test_handlers.py 2007-07-05 14:29:40 +0000 @@ -43,7 +43,6 @@ from Mailman.Handlers import Moderate from Mailman.Handlers import Scrubber # Don't test handlers such as SMTPDirect and Sendmail here -from Mailman.Handlers import SpamDetect from Mailman.Handlers import ToArchive from Mailman.Handlers import ToDigest from Mailman.Handlers import ToOutgoing @@ -306,11 +305,6 @@ -class TestModerate(TestBase): - pass - - - class TestScrubber(TestBase): def test_save_attachment(self): mlist = self._mlist @@ -403,36 +397,6 @@ -class TestSpamDetect(TestBase): - def test_short_circuit(self): - msgdata = {'approved': 1} - rtn = SpamDetect.process(self._mlist, None, msgdata) - # Not really a great test, but there's little else to assert - self.assertEqual(rtn, None) - - def test_spam_detect(self): - msg1 = email.message_from_string("""\ -From: [EMAIL PROTECTED] - -A message. -""") - msg2 = email.message_from_string("""\ -To: [EMAIL PROTECTED] - -A message. -""") - spammers = config.KNOWN_SPAMMERS[:] - try: - config.KNOWN_SPAMMERS.append(('from', '.?person')) - self.assertRaises(SpamDetect.SpamDetected, - SpamDetect.process, self._mlist, msg1, {}) - rtn = SpamDetect.process(self._mlist, msg2, {}) - self.assertEqual(rtn, None) - finally: - config.KNOWN_SPAMMERS = spammers - - - class TestToArchive(TestBase): def setUp(self): TestBase.setUp(self) @@ -694,9 +658,7 @@ suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(TestApprove)) suite.addTest(unittest.makeSuite(TestMimeDel)) - suite.addTest(unittest.makeSuite(TestModerate)) suite.addTest(unittest.makeSuite(TestScrubber)) - suite.addTest(unittest.makeSuite(TestSpamDetect)) suite.addTest(unittest.makeSuite(TestToArchive)) suite.addTest(unittest.makeSuite(TestToDigest)) suite.addTest(unittest.makeSuite(TestToOutgoing)) -- (no title) https://code.launchpad.net/~mailman-coders/mailman/3.0 You are receiving this branch notification because you are subscribed to it. To unsubscribe from this branch go to https://code.launchpad.net/~mailman-coders/mailman/3.0/+subscription/mailman-checkins. _______________________________________________ Mailman-checkins mailing list Mailman-checkins@python.org Unsubscribe: http://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org