mailman/templates/seed-empty-list-header-matc...

29 lines
846 B
Django/Jinja

"""Seed configured header matches on otherwise unconfigured mailing lists."""
from json import loads
from mailman.interfaces.mailinglist import IHeaderMatchList
RULES = loads({{ mailman_empty_list_header_matches | to_json | to_json }})
def apply(mlist):
"""Add all configured rules if *mlist* has no header matches."""
header_matches = IHeaderMatchList(mlist)
existing_count = len(header_matches)
if existing_count:
print('SKIPPED {} existing_header_matches={}'.format(
mlist.fqdn_listname, existing_count))
return
for rule in RULES:
header_matches.append(
rule['header'],
rule['pattern'],
chain=rule.get('action'),
tag=rule.get('tag'))
print('CHANGED {} added_header_matches={}'.format(
mlist.fqdn_listname, len(RULES)))