summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Mailman/docs/antispam.txt75
-rw-r--r--Mailman/testing/test_handlers.py38
2 files changed, 75 insertions, 38 deletions
diff --git a/Mailman/docs/antispam.txt b/Mailman/docs/antispam.txt
new file mode 100644
index 000000000..1fce25338
--- /dev/null
+++ b/Mailman/docs/antispam.txt
@@ -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('_xtest@example.com')
+ >>> flush()
+
+
+Short circuiting
+----------------
+
+If a message is pre-approved, this handler does nothing.
+
+ >>> msg = message_from_string("""\
+ ... From: aperson@example.com
+ ...
+ ... An important message.
+ ... """, Message)
+ >>> msgdata = {'approved': True}
+ >>> process(mlist, msg, msgdata)
+ >>> print msg.as_string()
+ From: aperson@example.com
+ <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: aperson@example.com
+ <BLANKLINE>
+ An important message.
+ <BLANKLINE>
+ >>> msgdata
+ {}
+
+
+Header filter rules
+-------------------
+
+XXX Need tests.
diff --git a/Mailman/testing/test_handlers.py b/Mailman/testing/test_handlers.py
index 8f9dbedb8..efd9123c5 100644
--- a/Mailman/testing/test_handlers.py
+++ b/Mailman/testing/test_handlers.py
@@ -43,7 +43,6 @@ from Mailman.Handlers import MimeDel
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 @@ This is plain text
-class TestModerate(TestBase):
- pass
-
-
-
class TestScrubber(TestBase):
def test_save_attachment(self):
mlist = self._mlist
@@ -403,36 +397,6 @@ Name: xtext.txt""")
-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: aperson@example.org
-
-A message.
-""")
- msg2 = email.message_from_string("""\
-To: xlist@example.com
-
-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 @@ def test_suite():
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))