mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
email: Simplify setting milter configuration and running sievec
- Drop diagnosis. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
75ec7c5a5a
commit
4b741e9192
@ -146,7 +146,6 @@ class EmailApp(plinth.app.App):
|
|||||||
"""Run diagnostics and return the results"""
|
"""Run diagnostics and return the results"""
|
||||||
results = super().diagnose()
|
results = super().diagnose()
|
||||||
results.extend([r.summarize() for r in audit.ldap.get()])
|
results.extend([r.summarize() for r in audit.ldap.get()])
|
||||||
results.extend([r.summarize() for r in audit.spam.get()])
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,16 +1,10 @@
|
|||||||
"""Configures spam filters and the virus scanner"""
|
"""Configures spam filters and the virus scanner"""
|
||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
import glob
|
|
||||||
import logging
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
from plinth import actions
|
from plinth import actions
|
||||||
from plinth.modules.email import interproc, lock, postconf
|
from plinth.modules.email import postconf
|
||||||
|
|
||||||
from . import models
|
|
||||||
|
|
||||||
milter_config = {
|
milter_config = {
|
||||||
'milter_mail_macros': 'i ' + ' '.join([
|
'milter_mail_macros': 'i ' + ' '.join([
|
||||||
@ -71,54 +65,20 @@ egress_filter_cleanup_options = {
|
|||||||
'nested_header_checks': ''
|
'nested_header_checks': ''
|
||||||
}
|
}
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def get():
|
|
||||||
translation_table = [
|
|
||||||
(check_filter, _('Inbound and outbound mail filters')),
|
|
||||||
]
|
|
||||||
results = []
|
|
||||||
with postconf.mutex.lock_all():
|
|
||||||
for check, title in translation_table:
|
|
||||||
results.append(check(title))
|
|
||||||
return results
|
|
||||||
|
|
||||||
|
|
||||||
def repair():
|
def repair():
|
||||||
actions.superuser_run('email', ['spam', 'set_filter'])
|
actions.superuser_run('email', ['spam', 'set_filter'])
|
||||||
|
|
||||||
|
|
||||||
def check_filter(title=''):
|
|
||||||
diagnosis = models.MainCfDiagnosis(title)
|
|
||||||
diagnosis.compare(milter_config, postconf.get_many_unsafe)
|
|
||||||
return diagnosis
|
|
||||||
|
|
||||||
|
|
||||||
def fix_filter(diagnosis):
|
|
||||||
diagnosis.apply_changes(postconf.set_many_unsafe)
|
|
||||||
|
|
||||||
|
|
||||||
def action_set_filter():
|
def action_set_filter():
|
||||||
_compile_sieve()
|
_compile_sieve()
|
||||||
postconf.set_master_cf_options(egress_filter, egress_filter_options)
|
postconf.set_master_cf_options(egress_filter, egress_filter_options)
|
||||||
postconf.set_master_cf_options(egress_filter_cleanup,
|
postconf.set_master_cf_options(egress_filter_cleanup,
|
||||||
egress_filter_cleanup_options)
|
egress_filter_cleanup_options)
|
||||||
|
|
||||||
with postconf.mutex.lock_all():
|
postconf.set_many(milter_config)
|
||||||
fix_filter(check_filter())
|
|
||||||
|
|
||||||
|
|
||||||
def _compile_sieve():
|
def _compile_sieve():
|
||||||
sieve_list = glob.glob('/etc/dovecot/freedombox-sieve-after/*.sieve')
|
"""Compile all .sieve script to binary format for performance."""
|
||||||
for sieve_file in sieve_list:
|
sieve_dir = '/etc/dovecot/freedombox-sieve-after/'
|
||||||
_run_sievec(sieve_file)
|
subprocess.run(['sievec', sieve_dir], check=True)
|
||||||
|
|
||||||
|
|
||||||
def _run_sievec(sieve_file):
|
|
||||||
logger.info('Compiling sieve script %s', sieve_file)
|
|
||||||
args = ['sievec', '--', sieve_file]
|
|
||||||
completed = subprocess.run(args, capture_output=True, check=False)
|
|
||||||
if completed.returncode != 0:
|
|
||||||
interproc.log_subprocess(completed)
|
|
||||||
raise OSError('Sieve compilation failed: ' + sieve_file)
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user