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

Adapt the code and the tests to the new HeaderMatch object

parent 583a7639
......@@ -143,7 +143,7 @@ class HeaderMatchChain(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)
yield make_link(entry.header, entry.pattern, entry.chain)
# Then return all the explicitly added links.
for link in self._extended_links:
yield link
......
......@@ -28,6 +28,7 @@ from mailman.app.lifecycle import create_list
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.testing.layers import ConfigLayer
from mailman.testing.helpers import LogFileMark, configuration
......@@ -124,7 +125,7 @@ class TestHeaderChain(unittest.TestCase):
# 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+')]
self._mlist.header_matches = [HeaderMatch(header='Foo', pattern='a+')]
links = [ link for link in chain.get_links(self._mlist, Message(), {})
if link.rule.name != 'any' ]
self.assertEqual(len(links), 1)
......@@ -137,9 +138,9 @@ class TestHeaderChain(unittest.TestCase):
# properly.
chain = config.chains['header-match']
self._mlist.header_matches = [
('Foo', 'a+', 'reject'),
('Bar', 'b+', 'discard'),
('Baz', 'z+', 'accept'),
HeaderMatch(header='Foo', pattern='a+', chain='reject'),
HeaderMatch(header='Bar', pattern='b+', chain='discard'),
HeaderMatch(header='Baz', pattern='z+', chain='accept'),
]
links = [ link for link in chain.get_links(self._mlist, Message(), {})
if link.rule.name != 'any' ]
......
......@@ -125,7 +125,10 @@ with the same semantics as the global `[antispam]` section.
The list administrator wants to match not on four stars, but on three plus
signs, but only for the current mailing list.
>>> mlist.header_matches = [('x-spam-score', '[+]{3,}')]
>>> from mailman.model.mailinglist import HeaderMatch
>>> mlist.header_matches = [
... HeaderMatch(header='x-spam-score', pattern='[+]{3,}')
... ]
A message with a spam score of two pluses does not match.
......
......@@ -48,6 +48,7 @@ from mailman.interfaces.mailinglist import SubscriptionPolicy
from mailman.interfaces.member import DeliveryMode, DeliveryStatus, MemberRole
from mailman.interfaces.nntp import NewsgroupModeration
from mailman.interfaces.usermanager import IUserManager
from mailman.model.mailinglist import HeaderMatch
from mailman.utilities.filesystem import makedirs
from mailman.utilities.i18n import search
from sqlalchemy import Boolean
......@@ -334,7 +335,6 @@ def import_config_pck(mlist, config_dict):
# expression. Make that explicit for MM3.
alias_set.add('^' + address)
# Handle header_filter_rules conversion to header_matches
header_matches = []
for line_patterns, action, _unused in \
config_dict.get('header_filter_rules', []):
chain = action_to_chain(action)
......@@ -367,8 +367,8 @@ def import_config_pck(mlist, config_dict):
log.warning('Skipping header_filter rule because of an '
'invalid regular expression: %r', line_pattern)
continue
header_matches.append((header, pattern, chain))
mlist.header_matches = header_matches
mlist.header_matches.append(HeaderMatch(
header=header, pattern=pattern, chain=chain))
# Handle conversion to URIs. In MM2.1, the decorations are strings
# containing placeholders, and there's no provision for language-specific
# templates. In MM3, template locations are specified by URLs with the
......
......@@ -49,6 +49,7 @@ from mailman.interfaces.member import DeliveryMode, DeliveryStatus
from mailman.interfaces.nntp import NewsgroupModeration
from mailman.interfaces.templates import ITemplateLoader
from mailman.interfaces.usermanager import IUserManager
from mailman.model.mailinglist import HeaderMatch
from mailman.testing.layers import ConfigLayer
from mailman.testing.helpers import LogFileMark
from mailman.utilities.filesystem import makedirs
......@@ -364,7 +365,9 @@ class TestBasicImport(unittest.TestCase):
]
error_log = LogFileMark('mailman.error')
self._import()
self.assertListEqual(self._mlist.header_matches, [
self.assertListEqual(
[ (hm.header, hm.pattern, hm.chain)
for hm in self._mlist.header_matches ], [
('x-spam-status', 'Yes', 'discard'),
('x-spam-status', 'Yes', 'discard'),
('x-spam-status', 'Yes.*', 'discard'),
......@@ -435,9 +438,11 @@ class TestBasicImport(unittest.TestCase):
('^X-Spam-Status: Yes', 0, False),
]
self._import()
self.assertListEqual(self._mlist.header_matches, [
('x-spam-status', 'Yes', None),
])
self.assertListEqual(
[ (hm.header, hm.pattern, hm.chain)
for hm in self._mlist.header_matches ],
[ ('x-spam-status', 'Yes', None) ]
)
......
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