[Web][Postfix] Add mail policies: per-recipient send/receive rules for mailboxes and groups

This commit is contained in:
FreddleSpl0it committed 2026-11-07 15:55:43 +01:00
1 parent 329bca1d46
commit 4484cfcd42
36 files changed
+2677 -42

No files matched your search

@@ -0,0 +1,79 @@
{# Fields of a mail policy (add modal, edit page): policy, id (prefix of the element ids), groups (choices: id, name,
domain, address), mailboxes (choices), ro, label_class. Groups of a list are sent apart as <list>_groups. #}
{% set entries = {} %}
{% set listed = {} %}
{% for key in ['send_allow', 'send_block', 'receive_allow', 'receive_block'] %}
{% set plain = [] %}
{% set group_ids = [] %}
{% for entry in attribute(policy, key)|default([]) %}
{% if entry starts with 'group:' %}
{% set group_ids = group_ids|merge([entry|slice(6)]) %}
{% else %}
{% set plain = plain|merge([entry]) %}
{% endif %}
{% endfor %}
{% set entries = entries|merge({(key): plain|join("\n")}) %}
{% set listed = listed|merge({(key): group_ids}) %}
{% endfor %}
{% for side in ['send', 'receive'] %}
<legend class="fs-5 mt-4"><i class="bi {{ side == 'send' ? 'bi-send' : 'bi-inbox' }}"></i> {{ attribute(lang.mail_policy, side) }}</legend><hr>
<p class="text-muted small">{{ attribute(lang.mail_policy, side ~ '_info') }}</p>
<div class="row mb-2">
<label class="control-label col-sm-2{{ label_class }}" for="{{ id }}_{{ side }}_mode">{{ lang.mail_policy.mode }}</label>
<div class="col-sm-10">
<select class="form-control" name="{{ side }}_mode" id="{{ id }}_{{ side }}_mode"{% if ro %} disabled{% endif %}>
{% for mode in ['all', 'internal', 'list'] %}
<option value="{{ mode }}"{% if attribute(policy, side ~ '_mode')|default('all') == mode %} selected{% endif %}>{{ attribute(lang.mail_policy, 'mode_' ~ side ~ '_' ~ mode) }}</option>
{% endfor %}
</select>
<small class="text-muted d-block">{{ lang.mail_policy.internal_info }}</small>
</div>
</div>
{% for list in ['allow', 'block'] %}
{% set key = side ~ '_' ~ list %}
<div class="row mb-2">
<label class="control-label col-sm-2{{ label_class }}" for="{{ id }}_{{ key }}">{{ attribute(lang.mail_policy, list ~ '_' ~ side) }}</label>
<div class="col-sm-10">
<textarea class="form-control" rows="3" name="{{ key }}" id="{{ id }}_{{ key }}" placeholder="partner.example, user@example.org"{% if ro %} disabled{% endif %}>{{ attribute(entries, key) }}</textarea>
<small class="text-muted d-block mb-1">{{ lang.mail_policy.entries_info }}</small>
{% if not ro %}<input type="hidden" name="{{ key }}_groups" value="">{% endif %}
<select data-live-search="true" data-width="100%" name="{{ key }}_groups" class="form-control mail-policy-groups" multiple title="{{ lang.mail_policy.groups }}"{% if ro %} disabled{% endif %}>
{% for group in groups %}
<option value="{{ group.id }}" data-domain="{{ group.domain }}"{% if group.id ~ '' in attribute(listed, key) %} selected{% endif %}>{{ group.name }}{% if group.address %} ({{ group.address }}){% endif %}</option>
{% endfor %}
</select>
</div>
</div>
{% endfor %}
{% endfor %}
<div class="row mb-2">
<label class="control-label col-sm-2{{ label_class }}" for="{{ id }}_reject_text">{{ lang.mail_policy.reject_text }}</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="reject_text" id="{{ id }}_reject_text" maxlength="200" value="{{ policy.reject_text|default('') }}"{% if ro %} disabled{% endif %}>
<small class="text-muted d-block">{{ lang.mail_policy.reject_text_info }}</small>
</div>
</div>
<legend class="fs-5 mt-4"><i class="bi bi-people"></i> {{ lang.mail_policy.assign }}</legend><hr>
<p class="text-muted small">{{ lang.mail_policy.assign_info }}</p>
<div class="row mb-2">
<label class="control-label col-sm-2{{ label_class }}" for="{{ id }}_mailboxes">{{ lang.mail_policy.mailboxes }}</label>
<div class="col-sm-10">
{% if not ro %}<input type="hidden" name="mailboxes" value="">{% endif %}
<select data-live-search="true" data-width="100%" name="mailboxes" id="{{ id }}_mailboxes" class="form-control mail-policy-mailboxes" multiple title="{{ lang.mail_policy.mailboxes }}"{% if ro %} disabled{% endif %}>
{% for mailbox in mailboxes %}
<option value="{{ mailbox }}" data-domain="{{ mailbox|split('@')|last }}"{% if mailbox in policy.mailboxes|default([]) %} selected{% endif %}>{{ mailbox }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="row mb-2">
<label class="control-label col-sm-2{{ label_class }}" for="{{ id }}_groups">{{ lang.mail_policy.groups }}</label>
<div class="col-sm-10">
{% if not ro %}<input type="hidden" name="groups" value="">{% endif %}
<select data-live-search="true" data-width="100%" name="groups" id="{{ id }}_groups" class="form-control mail-policy-groups" multiple title="{{ lang.mail_policy.groups }}"{% if ro %} disabled{% endif %}>
{% for group in groups %}
<option value="{{ group.id }}" data-domain="{{ group.domain }}"{% if group.id in policy.groups|default([]) %} selected{% endif %}>{{ group.name }}{% if group.address %} ({{ group.address }}){% endif %}</option>
{% endfor %}
</select>
</div>
</div>
+46
View File
@@ -0,0 +1,46 @@
{% extends 'edit.twig' %}
{% block inner_content %}
{% if result %}
{% set ro = not result.can_edit %}
<h4>{{ lang.mail_policy.policy }}: {{ result.name }}</h4>
<form data-id="edit_mail_policy" class="form-horizontal" role="form" method="post" autocapitalize="none" autocorrect="off">
<input type="hidden" value="0" name="active">
<div class="row mb-2">
<label class="control-label col-sm-2" for="mail_policy_domain">{{ lang.mail_policy.domain }}</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="mail_policy_domain" value="{{ result.domain }}" disabled>
</div>
</div>
<div class="row mb-2">
<label class="control-label col-sm-2" for="mail_policy_name">{{ lang.mail_policy.name }}</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="name" id="mail_policy_name" value="{{ result.name }}" maxlength="100" required{% if ro %} disabled{% endif %}>
</div>
</div>
<div class="row mb-2">
<label class="control-label col-sm-2" for="mail_policy_description">{{ lang.mail_policy.description }}</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="description" id="mail_policy_description" value="{{ result.description }}" maxlength="255"{% if ro %} disabled{% endif %}>
</div>
</div>
{% include 'edit/mail-policy-fields.twig' with {'policy': result, 'id': 'mail_policy', 'groups': mail_policy_groups, 'mailboxes': mailboxes, 'ro': ro, 'label_class': ''} %}
<div class="row mb-4">
<div class="offset-sm-2 col-sm-10">
<div class="form-check">
<label><input type="checkbox" class="form-check-input" value="1" name="active"{% if result.active == 1 %} checked{% endif %}{% if ro %} disabled{% endif %}> {{ lang.mailbox.active }}</label>
</div>
</div>
</div>
{% if not ro %}
<div class="row">
<div class="offset-sm-2 col-sm-10">
<button class="btn btn-xs-lg d-block d-sm-inline btn-success" data-action="edit_selected" data-id="edit_mail_policy" data-item="{{ result.id }}" data-api-url='edit/mail-policy' data-api-attr='{}' href="#"><i class="bi bi-check-lg"></i> {{ lang.admin.save }}</button>
</div>
</div>
{% endif %}
</form>
{% else %}
{{ parent() }}
{% endif %}
{% endblock %}