Commit 6a229576 authored by Aurélien Bompard's avatar Aurélien Bompard Committed by Barry Warsaw

Handle header-match rule-specific action

parent 49d17bc0
......@@ -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)
......
......@@ -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'),
])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment