summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBarry Warsaw2016-02-29 22:08:18 -0500
committerBarry Warsaw2016-02-29 22:08:18 -0500
commita6f442b8812849efcf41d72e82801be6238aa61f (patch)
tree1447bbb1680e58f9db70b5afb4222187af6b5989 /src
parent5505a9208581a9b0b015e78f61db12e645847189 (diff)
downloadmailman-a6f442b8812849efcf41d72e82801be6238aa61f.tar.gz
mailman-a6f442b8812849efcf41d72e82801be6238aa61f.tar.zst
mailman-a6f442b8812849efcf41d72e82801be6238aa61f.zip
Diffstat (limited to 'src')
-rw-r--r--src/mailman/chains/headers.py7
-rw-r--r--src/mailman/chains/tests/test_headers.py41
2 files changed, 27 insertions, 21 deletions
diff --git a/src/mailman/chains/headers.py b/src/mailman/chains/headers.py
index 23ad79fdf..f14ec754f 100644
--- a/src/mailman/chains/headers.py
+++ b/src/mailman/chains/headers.py
@@ -36,7 +36,6 @@ from zope.interface import implementer
log = logging.getLogger('mailman.error')
-
def make_link(header, pattern, chain=None):
"""Create a Link object.
@@ -61,7 +60,6 @@ def make_link(header, pattern, chain=None):
return Link(rule, LinkAction.jump, chain)
-
@implementer(IRule)
class HeaderMatchRule:
"""Header matching rule used by header-match chain."""
@@ -96,7 +94,6 @@ class HeaderMatchRule:
return False
-
class HeaderMatchChain(Chain):
"""Default header matching chain.
@@ -151,5 +148,7 @@ class HeaderMatchChain(Chain):
# Then return all the list-specific header matches.
for entry in mlist.header_matches:
# Jump to the default antispam chain if the entry chain is None.
- chain = entry.chain or config.antispam.jump_chain
+ chain = (config.antispam.jump_chain
+ if entry.chain is None
+ else entry.chain)
yield make_link(entry.header, entry.pattern, chain)
diff --git a/src/mailman/chains/tests/test_headers.py b/src/mailman/chains/tests/test_headers.py
index 693f132d0..11b00f7ba 100644
--- a/src/mailman/chains/tests/test_headers.py
+++ b/src/mailman/chains/tests/test_headers.py
@@ -30,7 +30,6 @@ from mailman.config import config
from mailman.core.chains import process
from mailman.email.message import Message
from mailman.interfaces.chain import LinkAction, HoldEvent, DiscardEvent
-from mailman.interfaces.configuration import ConfigurationUpdatedEvent
from mailman.interfaces.mailinglist import IHeaderMatchList
from mailman.testing.helpers import (
LogFileMark, configuration, event_subscribers,
@@ -38,7 +37,6 @@ from mailman.testing.helpers import (
from mailman.testing.layers import ConfigLayer
-
class TestHeaderChain(unittest.TestCase):
"""Test the header chain code."""
@@ -208,8 +206,8 @@ A message body.
self.assertEqual(event.chain, config.chains['hold'])
def test_no_action_defaults_to_site_wide_action(self):
- # Test that list-specific checks with no action always follow the
- # site-wide antispam action.
+ # If the list-specific header check matches, but there is no defined
+ # action, the site-wide antispam action is used.
msg = mfs("""\
From: anne@example.com
To: test@example.com
@@ -220,33 +218,42 @@ MIME-Version: 1.0
A message body.
""")
- msgdata = {}
header_matches = IHeaderMatchList(self._mlist)
header_matches.append('Foo', 'foo')
# This event subscriber records the event that occurs when the message
- # is processed by the owner chain.
+ # is processed by the owner chain, which holds its for approval.
events = []
- def record_event(event):
- if isinstance(event, ConfigurationUpdatedEvent):
+ def record_holds(event):
+ if not isinstance(event, HoldEvent):
return
events.append(event)
- with event_subscribers(record_event):
- # The site-wide default is hold.
+ with event_subscribers(record_holds):
+ # Set the site-wide antispam action to hold the message.
with configuration('antispam', header_checks="""
Spam: [*]{3,}
""", jump_chain='hold'):
- process(self._mlist, msg, msgdata, start_chain='header-match')
+ process(self._mlist, msg, {}, start_chain='header-match')
self.assertEqual(len(events), 1)
event = events[0]
- self.assertTrue(isinstance(event, HoldEvent))
+ self.assertIsInstance(event, HoldEvent)
self.assertEqual(event.chain, config.chains['hold'])
- # The site-wide default is now discard.
+ self.assertEqual(event.mlist, self._mlist)
+ self.assertEqual(event.msg, msg)
+ events = []
+ def record_discards(event):
+ if not isinstance(event, DiscardEvent):
+ return
+ events.append(event)
+ with event_subscribers(record_discards):
+ # Set the site-wide default to discard the message.
msg.replace_header('Message-Id', '<bee>')
with configuration('antispam', header_checks="""
Spam: [*]{3,}
""", jump_chain='discard'):
- process(self._mlist, msg, msgdata, start_chain='header-match')
- self.assertEqual(len(events), 2)
- event = events[1]
- self.assertTrue(isinstance(event, DiscardEvent))
+ process(self._mlist, msg, {}, start_chain='header-match')
+ self.assertEqual(len(events), 1)
+ event = events[0]
+ self.assertIsInstance(event, DiscardEvent)
self.assertEqual(event.chain, config.chains['discard'])
+ self.assertEqual(event.mlist, self._mlist)
+ self.assertEqual(event.msg, msg)