From fae8fe3360889429c472f701c055ae80efc9f796 Mon Sep 17 00:00:00 2001 From: Stephane de Labrusse Date: Thu, 25 Apr 2024 12:54:46 +0200 Subject: [PATCH] Add BCC validation script and language file --- .../configure-module/02_validate_bcc_server | 48 +++++++++++++++++++ ui/public/i18n/language.json | 3 +- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100755 imageroot/actions/configure-module/02_validate_bcc_server diff --git a/imageroot/actions/configure-module/02_validate_bcc_server b/imageroot/actions/configure-module/02_validate_bcc_server new file mode 100755 index 0000000..d0ac33d --- /dev/null +++ b/imageroot/actions/configure-module/02_validate_bcc_server @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 + +# +# Copyright (C) 2024 Nethesis S.r.l. +# SPDX-License-Identifier: GPL-3.0-or-later +# + +import json +import sys +import os +import agent + +agent.set_weight(os.path.basename(__file__), 0) # Validation step, no task progress at all + +# Try to parse the stdin as JSON. +# If parsing fails, output everything to stderr +data = json.load(sys.stdin) + +# Connect to redis +rdb = agent.redis_connect() + +providers = agent.list_service_providers(rdb, 'imap', 'tcp', { + 'module_uuid': data["mail_server"], +}) +# function to test get-alaways-bcc +def get_always_bcc(email): + mail_id = providers[0]["module_id"] + response = agent.tasks.run(f"module/{mail_id}", action='get-always-bcc') + agent.assert_exp(response['exit_code'] == 0) + # check if the always_bcc is not set + if response['output']['bcc'] == '': + sys.exit(0) + # check if the always_bcc is set to the email + elif response['output']['bcc'] == email: + sys.exit(0) + # check if the always_bcc is previouslys set to piler (archive@host.domain.com) + elif response['output']['bcc'] == 'archive@'+os.environ.get('TRAEFIK_HOST'): + sys.exit(0) + else: + agent.set_status('validation-failed') + json.dump([{'field':'mail_server','parameter':'mail_server','value': response['output']['bcc'],'error':'always_bcc_is_already_set'}], fp=sys.stdout) + sys.exit(2) + + +if providers: + # we need to set bcc address for the mail server + get_always_bcc('archive@'+data['host']) + diff --git a/ui/public/i18n/language.json b/ui/public/i18n/language.json index 7d1b504..cdcf624 100644 --- a/ui/public/i18n/language.json +++ b/ui/public/i18n/language.json @@ -48,7 +48,8 @@ "import_email_is_running_description": "Please wait until the import emails action is finished", "import_email_to_piler": "Import emails to Piler", "advanced": "Advanced", - "import_old_emails_to_piler_description": "Import old emails to Piler, this process may take a long time" + "import_old_emails_to_piler_description": "Import old emails to Piler, this process may take a long time", + "always_bcc_is_already_set": "Always BCC is already set in the server, you need to manually remove it (POSTFIX_ALWAYS_BCC)" }, "about": { "title": "About"