summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAurélien Bompard2016-02-29 16:05:42 +0100
committerBarry Warsaw2016-02-29 21:52:13 -0500
commit0699f9dcb8680ea99346f915680903a3c6f25318 (patch)
treebb25c942166c8df8a7ed3de447a6ea21cb23cb29
parent9684f1fc0e8bbe2c41566bf16dab92a0ff0f8b81 (diff)
downloadmailman-0699f9dcb8680ea99346f915680903a3c6f25318.tar.gz
mailman-0699f9dcb8680ea99346f915680903a3c6f25318.tar.zst
mailman-0699f9dcb8680ea99346f915680903a3c6f25318.zip
-rw-r--r--src/mailman/rest/docs/listconf.rst16
-rw-r--r--src/mailman/rest/header_matches.py23
2 files changed, 24 insertions, 15 deletions
diff --git a/src/mailman/rest/docs/listconf.rst b/src/mailman/rest/docs/listconf.rst
index 74a58afbf..5e32844de 100644
--- a/src/mailman/rest/docs/listconf.rst
+++ b/src/mailman/rest/docs/listconf.rst
@@ -299,7 +299,7 @@ Header matches
--------------
Mailman can do pattern based header matching during its normal rule
-processing. Each mailing list can also be configured with a set of header
+processing. Each mailing list can also be configured with a set of header
matching regular expression rules. These can be used to impose list-specific
header filtering with the same semantics as the global ``[antispam]`` section,
or to have a different action.
@@ -334,11 +334,10 @@ New header matches can be created by POSTing to the resource.
position: 0
self_link: http://localhost:9001/3.0/lists/ant.example.com/header-matches/0
-
To follow the global antispam action, the header match rule must not specify
an ``action`` key. If the default antispam action is changed in the
configuration file and Mailman is restarted, those rules will get the new
-jump action. If a specific action is desired, the ``action`` key must point
+jump action. If a specific action is desired, the ``action`` key must point
to a valid action.
>>> dump_json('http://localhost:9001/3.0/lists/ant.example.com'
@@ -362,9 +361,9 @@ to a valid action.
position: 1
self_link: http://localhost:9001/3.0/lists/ant.example.com/header-matches/1
-The resource can be changed by PATCHing it. The ``position`` key can be used to
-change the priority of the header match in the list. If it is not supplied, the
-priority is not changed.
+The resource can be changed by PATCHing it. The ``position`` key can be used
+to change the priority of the header match in the list. If it is not supplied,
+the priority is not changed.
>>> dump_json('http://localhost:9001/3.0/lists/ant.example.com'
... '/header-matches/1',
@@ -410,7 +409,7 @@ priority is not changed.
start: 0
total_size: 2
-The PUT method can replace an entire header match. The ``position`` key is
+The PUT method can replace an entire header match. The ``position`` key is
optional: if it is omitted, the order will not be changed.
>>> dump_json('http://localhost:9001/3.0/lists/ant.example.com'
@@ -454,7 +453,8 @@ A header match can be removed using the DELETE method.
start: 0
total_size: 1
-The mailing list's header matches can be cleared by issuing a DELETE request on the top resource.
+The mailing list's header matches can be cleared by issuing a DELETE request on
+the top resource.
>>> dump_json('http://localhost:9001/3.0/lists/ant.example.com'
... '/header-matches',
diff --git a/src/mailman/rest/header_matches.py b/src/mailman/rest/header_matches.py
index c5fe88184..9d1afa546 100644
--- a/src/mailman/rest/header_matches.py
+++ b/src/mailman/rest/header_matches.py
@@ -54,8 +54,8 @@ class _HeaderMatchBase:
pattern=header_match.pattern,
self_link=self._location(header_match.position),
)
- if header_match.action is not None:
- resource['action'] = header_match.action
+ if header_match.chain is not None:
+ resource['action'] = header_match.chain
return resource
@@ -95,10 +95,10 @@ class HeaderMatch(_HeaderMatchBase):
self._position))
return
kws = dict(
- header=GetterSetter(lowercase),
- pattern=GetterSetter(str),
- position=GetterSetter(int),
- action=GetterSetter(enum_validator(Action)),
+ header=lowercase,
+ pattern=str,
+ position=int,
+ action=enum_validator(Action),
)
if is_optional:
# For a PATCH, all attributes are optional.
@@ -106,8 +106,14 @@ class HeaderMatch(_HeaderMatchBase):
else:
# For a PUT, position can remain unchanged and action can be None.
kws['_optional'] = ('action', 'position')
+ validator = Validator(**kws)
try:
- Validator(**kws).update(header_match, request)
+ arguments = validator(request)
+ if 'action' in arguments:
+ arguments['chain'] = arguments['action'].name
+ del arguments['action']
+ for key, value in arguments.items():
+ setattr(header_match, key, value)
except ValueError as error:
bad_request(response, str(error))
return
@@ -148,6 +154,9 @@ class HeaderMatches(_HeaderMatchBase, CollectionMixin):
except ValueError as error:
bad_request(response, str(error))
return
+ if 'action' in arguments:
+ arguments['chain'] = arguments['action'].name
+ del arguments['action']
try:
self.header_matches.append(**arguments)
except ValueError: