From 0dcecf5f47827a44cf363d60b9845e431c6f643c Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sun, 14 Jan 2024 17:12:42 +0100 Subject: [PATCH] Remove rspamd from recommends, replace with a global setting similar to pop3 to enable/disable antispam --- debian/control | 1 - locales/en.json | 6 ++++-- share/config_global.toml | 8 +++++++- src/settings.py | 32 +++++++++++++++++++++++++++++--- 4 files changed, 40 insertions(+), 7 deletions(-) diff --git a/debian/control b/debian/control index a84a3ddad..79b042f6e 100644 --- a/debian/control +++ b/debian/control @@ -35,7 +35,6 @@ Recommends: yunohost-admin, yunohost-portal (>= 12.0) , bash-completion, rsyslog , unattended-upgrades , libdbd-ldap-perl, libnet-dns-perl - , rspamd Conflicts: iptables-persistent , apache2 , bind9 diff --git a/locales/en.json b/locales/en.json index d48f912ba..7c56c0793 100644 --- a/locales/en.json +++ b/locales/en.json @@ -447,7 +447,9 @@ "global_settings_setting_nginx_redirect_to_https_help": "Redirect HTTP requests to HTTPs by default (DO NOT TURN OFF unless you really know what you're doing!)", "global_settings_setting_passwordless_sudo": "Allow admins to use 'sudo' without re-typing their passwords", "global_settings_setting_pop3_enabled": "Enable POP3", - "global_settings_setting_pop3_enabled_help": "Enable the POP3 protocol for the mail server", + "global_settings_setting_pop3_enabled_help": "Enable the POP3 protocol for the mail server. POP3 is an older protocol to access mailboxes from email clients and is more lightweight, but has less features than IMAP (enabled by default)", + "global_settings_setting_antispam_enabled": "Enable antispam", + "global_settings_setting_antispam_enabled_help": "Install and configure rspamd, a spam filtering system", "global_settings_setting_portal_theme": "Portal theme", "global_settings_setting_portal_theme_help": "More info regarding creating custom portal themes at https://yunohost.org/theming", "global_settings_setting_postfix_compatibility": "Postfix Compatibility", @@ -824,4 +826,4 @@ "yunohost_installing": "Installing YunoHost...", "yunohost_not_installed": "YunoHost is not correctly installed. Please run 'yunohost tools postinstall'", "yunohost_postinstall_end_tip": "The post-install completed! To finalize your setup, please consider:\n - diagnose potential issues through the 'Diagnosis' section of the webadmin (or 'yunohost diagnosis run' in command-line);\n - reading the 'Finalizing your setup' and 'Getting to know YunoHost' parts in the admin documentation: https://yunohost.org/admindoc." -} \ No newline at end of file +} diff --git a/share/config_global.toml b/share/config_global.toml index 40b71ab19..156196ed0 100644 --- a/share/config_global.toml +++ b/share/config_global.toml @@ -107,7 +107,13 @@ name = "Email" [email.pop3.pop3_enabled] type = "boolean" default = false - + + [email.antispam] + name = "Antispam" + [email.antispam.antispam_enabled] + type = "boolean" + default = false + [email.smtp] name = "SMTP" [email.smtp.smtp_allow_ipv6] diff --git a/src/settings.py b/src/settings.py index f858e7e80..e7f30085c 100644 --- a/src/settings.py +++ b/src/settings.py @@ -367,7 +367,6 @@ def reconfigure_postfix(setting_name, old_value, new_value): @post_change_hook("pop3_enabled") def reconfigure_dovecot(setting_name, old_value, new_value): - dovecot_package = "dovecot-pop3d" environment = os.environ.copy() environment.update({"DEBIAN_FRONTEND": "noninteractive"}) @@ -381,7 +380,7 @@ def reconfigure_dovecot(setting_name, old_value, new_value): "-o Dpkg::Options::=--force-confdef", "-o Dpkg::Options::=--force-confold", "install", - dovecot_package, + "dovecot-pop3d", ] subprocess.call(command, env=environment) if old_value != new_value: @@ -389,5 +388,32 @@ def reconfigure_dovecot(setting_name, old_value, new_value): else: if old_value != new_value: regen_conf(names=["dovecot"]) - command = ["apt-get", "-y", "remove", dovecot_package] + command = ["apt-get", "-y", "remove", "dovecot-pop3d"] + subprocess.call(command, env=environment) + + +@post_change_hook("antispam_enabled") +def reconfigure_rspamd(setting_name, old_value, new_value): + + environment = os.environ.copy() + environment.update({"DEBIAN_FRONTEND": "noninteractive"}) + + # Depending on how consistent the config panel is, it may spit 1 or True or ..? ... + if new_value: + command = [ + "apt-get", + "-y", + "--no-remove", + "-o Dpkg::Options::=--force-confdef", + "-o Dpkg::Options::=--force-confold", + "install", + "rspamd", + ] + subprocess.call(command, env=environment) + if old_value != new_value: + regen_conf(names=["rspamd"]) + else: + if old_value != new_value: + regen_conf(names=["rspamd"]) + command = ["apt-get", "-y", "remove", "rspamd"] subprocess.call(command, env=environment)