summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mailman/chains/headers.py9
-rw-r--r--src/mailman/chains/tests/test_headers.py32
2 files changed, 39 insertions, 2 deletions
diff --git a/src/mailman/chains/headers.py b/src/mailman/chains/headers.py
index 7c5d11bee..ea4652062 100644
--- a/src/mailman/chains/headers.py
+++ b/src/mailman/chains/headers.py
@@ -37,7 +37,7 @@ log = logging.getLogger('mailman.error')
-def make_link(header, pattern):
+def make_link(header, pattern, chain=None):
"""Create a Link object.
The link action is always to defer, since at the end of all the header
@@ -52,7 +52,12 @@ def make_link(header, pattern):
:rtype: `ILink`
"""
rule = HeaderMatchRule(header, pattern)
- return Link(rule, LinkAction.defer)
+ if chain is None:
+ action = LinkAction.defer
+ else:
+ chain = config.chains[chain]
+ action = LinkAction.jump
+ return Link(rule, action, chain)
diff --git a/src/mailman/chains/tests/test_headers.py b/src/mailman/chains/tests/test_headers.py
index a00f9c588..cca2e041f 100644
--- a/src/mailman/chains/tests/test_headers.py
+++ b/src/mailman/chains/tests/test_headers.py
@@ -119,3 +119,35 @@ class TestHeaderChain(unittest.TestCase):
HeaderMatchRule, 'x-spam-score', '.*')
finally:
config.rules = saved_rules
+
+ def test_list_rule(self):
+ # Test that the header-match chain has the header checks from the
+ # mailing-list configuration.
+ chain = config.chains['header-match']
+ self._mlist.header_matches = [('Foo', 'a+')]
+ links = [ link for link in chain.get_links(self._mlist, Message(), {})
+ if link.rule.name != 'any' ]
+ self.assertEqual(len(links), 1)
+ self.assertEqual(links[0].action, LinkAction.defer)
+ self.assertEqual(links[0].rule.header, 'Foo')
+ self.assertEqual(links[0].rule.pattern, 'a+')
+
+ def test_list_complex_rule(self):
+ # Test that the mailing-list header-match complex rules are read
+ # properly.
+ chain = config.chains['header-match']
+ self._mlist.header_matches = [
+ ('Foo', 'a+', 'reject'),
+ ('Bar', 'b+', 'discard'),
+ ('Baz', 'z+', 'accept'),
+ ]
+ links = [ link for link in chain.get_links(self._mlist, Message(), {})
+ if link.rule.name != 'any' ]
+ self.assertEqual(len(links), 3)
+ self.assertListEqual(
+ [ (link.rule.header, link.rule.pattern, link.action, link.chain.name)
+ for link in links ],
+ [('Foo', 'a+', LinkAction.jump, 'reject'),
+ ('Bar', 'b+', LinkAction.jump, 'discard'),
+ ('Baz', 'z+', LinkAction.jump, 'accept'),
+ ])