summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mailman/chains/headers.py2
-rw-r--r--src/mailman/chains/tests/test_headers.py9
-rw-r--r--src/mailman/rules/docs/header-matching.rst5
-rw-r--r--src/mailman/utilities/importer.py6
-rw-r--r--src/mailman/utilities/tests/test_import.py13
5 files changed, 22 insertions, 13 deletions
diff --git a/src/mailman/chains/headers.py b/src/mailman/chains/headers.py
index ea4652062..c98726e21 100644
--- a/src/mailman/chains/headers.py
+++ b/src/mailman/chains/headers.py
@@ -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
diff --git a/src/mailman/chains/tests/test_headers.py b/src/mailman/chains/tests/test_headers.py
index cca2e041f..c55d39876 100644
--- a/src/mailman/chains/tests/test_headers.py
+++ b/src/mailman/chains/tests/test_headers.py
@@ -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' ]
diff --git a/src/mailman/rules/docs/header-matching.rst b/src/mailman/rules/docs/header-matching.rst
index 3c175e6e1..7b2d8c6d7 100644
--- a/src/mailman/rules/docs/header-matching.rst
+++ b/src/mailman/rules/docs/header-matching.rst
@@ -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.
diff --git a/src/mailman/utilities/importer.py b/src/mailman/utilities/importer.py
index df0557c08..1261823fd 100644
--- a/src/mailman/utilities/importer.py
+++ b/src/mailman/utilities/importer.py
@@ -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
diff --git a/src/mailman/utilities/tests/test_import.py b/src/mailman/utilities/tests/test_import.py
index 52d3469c0..e9ad29a1b 100644
--- a/src/mailman/utilities/tests/test_import.py
+++ b/src/mailman/utilities/tests/test_import.py
@@ -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) ]
+ )