Skip to content

Commit

Permalink
Add BCC validation script and language file
Browse files Browse the repository at this point in the history
  • Loading branch information
stephdl committed Apr 25, 2024
1 parent 89e4fbe commit fae8fe3
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
48 changes: 48 additions & 0 deletions imageroot/actions/configure-module/02_validate_bcc_server
Original file line number Diff line number Diff line change
@@ -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 ([email protected])
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'])

3 changes: 2 additions & 1 deletion ui/public/i18n/language.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit fae8fe3

Please sign in to comment.