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

Make sure site-wide header_matches take precedence over list-specific ones

parent ed772e4f
......@@ -140,14 +140,15 @@ class HeaderMatchChain(Chain):
'contains bogus line: {0}'.format(line))
continue
yield make_link(parts[0], parts[1].lstrip())
# Then return all the list-specific header matches.
# Python 3.3: Use 'yield from'
for entry in mlist.header_matches:
yield make_link(entry.header, entry.pattern, entry.chain)
# Then return all the explicitly added links.
for link in self._extended_links:
yield link
# Finally, if any of the above rules matched, jump to the chain
# defined in the configuration file.
# If any of the above rules matched, jump to the chain
# defined in the configuration file. This takes precedence over
# list-specific matches for security considerations.
yield Link(config.rules['any'], LinkAction.jump,
config.chains[config.antispam.jump_chain])
# Then return all the list-specific header matches.
# Python 3.3: Use 'yield from'
for entry in mlist.header_matches:
yield make_link(entry.header, entry.pattern, entry.chain)
......@@ -29,9 +29,12 @@ from mailman.chains.headers import HeaderMatchRule
from mailman.config import config
from mailman.email.message import Message
from mailman.model.mailinglist import HeaderMatch
from mailman.interfaces.chain import LinkAction
from mailman.interfaces.chain import LinkAction, HoldEvent
from mailman.core.chains import process
from mailman.testing.layers import ConfigLayer
from mailman.testing.helpers import LogFileMark, configuration
from mailman.testing.helpers import (LogFileMark, configuration,
event_subscribers, get_queue_messages,
specialized_message_from_string as mfs)
......@@ -152,3 +155,36 @@ class TestHeaderChain(unittest.TestCase):
('Bar', 'b+', LinkAction.jump, 'discard'),
('Baz', 'z+', LinkAction.jump, 'accept'),
])
@configuration('antispam', header_checks="""
Foo: foo
""", jump_chain="hold")
def test_priority_site_over_list(self):
# Test that the site-wide checks take precedence over the list-specific
# checks.
msg = mfs("""\
From: [email protected]
To: [email protected]
Subject: A message
Message-ID: <ant>
Foo: foo
MIME-Version: 1.0
A message body.
""")
msgdata = {}
self._mlist.header_matches = [
HeaderMatch(header='Foo', pattern='foo', chain='accept')
]
# This event subscriber records the event that occurs when the message
# is processed by the owner chain.
events = []
def catch_event(event):
events.append(event)
with event_subscribers(catch_event):
process(self._mlist, msg, msgdata, start_chain='header-match')
self.assertEqual(len(events), 1)
event = events[0]
# Site-wide wants to hold the message, the list wants to accept it.
self.assertTrue(isinstance(event, HoldEvent))
self.assertEqual(event.chain, config.chains['hold'])
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