Add tasks to configure the header acceptance rules in the mailing lists settings.

This commit is contained in:
Andrea Dell'Amico 2026-08-21 16:49:41 +02:00
parent 123e9f3f7e
commit 9d2e4c48d0
Signed by: adellam
GPG Key ID: 147ABE6CEB9E20FF
3 changed files with 62 additions and 3 deletions

View File

@ -10,3 +10,17 @@ mailman_antispam_chain_behaviour: discard
Mailing-list owners can manage list-specific header matches and select their
action (`accept`, `discard`, `hold`, or `reject`) from Postorius. The global
chain is used only when a matching rule has no explicit action.
Existing lists without any header matches can be initialized through the
Mailman database model by enabling the optional seed operation:
```yaml
mailman_seed_empty_list_header_matches: true
mailman_empty_list_header_matches:
- header: 'X-Spam-Flag'
pattern: '^YES$'
action: 'discard'
```
The operation is idempotent. A list is modified only when its header-match
collection is empty; lists with one or more existing rules are left untouched.

View File

@ -127,6 +127,12 @@ mailman_antispam_header_checks: []
# 'accept', otherwise 'hold' will be used.
mailman_antispam_chain_behaviour: "discard"
# Optionally seed list-specific header matches, but only on mailing lists that
# do not already have any rules. Existing list configuration is never merged
# with or replaced by these defaults.
mailman_seed_empty_list_header_matches: false
mailman_empty_list_header_matches: []
mailman_start_nntp_runner: 'no'
mailman_repository: 'https://gitlab.com/mailman/mailman-suite.git'
@ -182,5 +188,3 @@ mailman_postorius_cronjob_frequency:
mailman_postorius_cronjob_special_times:
- 'quarter_hourly'
- 'minutely'

View File

@ -33,7 +33,7 @@
- '{{ mailman_spool_dir }}'
- name: Create the mailman virtualenv. Manually, because python 3.6
become: True
become: true
become_user: '{{ mailman_user }}'
shell: cd '{{ mailman_home }}' && python3 -m venv '{{ mailman_virtualenv_name }}'
args:
@ -111,6 +111,47 @@
tags: [ 'mailman', 'mailman_conf' ]
- name: Seed header matches on lists without existing rules
block:
- name: Create the Mailman administration scripts directory
ansible.builtin.file:
path: '{{ mailman_conf_dir }}/scripts'
state: directory
owner: root
group: '{{ mailman_user }}'
mode: '0750'
- name: Install the list header matches seed script
ansible.builtin.template:
src: seed-empty-list-header-matches.py.j2
dest: '{{ mailman_conf_dir }}/scripts/seed_empty_list_header_matches.py'
owner: root
group: '{{ mailman_user }}'
mode: '0440'
- name: Add header matches only to lists without rules
become: true
become_user: '{{ mailman_user }}'
ansible.builtin.command:
argv:
- '{{ mailman_bindir }}/mailman'
- -C
- '{{ mailman_conf_dir }}/mailman.cfg'
- shell
- --run
- seed_empty_list_header_matches.apply
- --listspec
- '^.*'
environment:
PYTHONPATH: '{{ mailman_conf_dir }}/scripts'
register: mailman_seed_header_matches_result
changed_when: "'CHANGED ' in mailman_seed_header_matches_result.stdout"
when:
- not ansible_check_mode
- mailman_seed_empty_list_header_matches | bool
- mailman_empty_list_header_matches | length > 0
tags: [ 'mailman', 'mailman_conf', 'mailman_header_matches' ]
- name: Add the maintenance cron jobs
tags: ['mailman', 'mailman_conf', 'mailman_cron']