generated from NethServer/ns8-kickstart
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add BCC validation script and language file
- Loading branch information
Showing
2 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters