improve config check

This commit is contained in:
2021-10-01 00:24:02 +02:00
parent 6a242e7d02
commit b9b6a62b5e
2 changed files with 7 additions and 8 deletions

View File

@@ -237,8 +237,12 @@ class AddDisclaimer:
raise RuntimeError(e) raise RuntimeError(e)
body = html.find('body') body = html.find('body')
self.html_template = body or html self.html_template = body or html
self.action = action self.action = action.lower()
self.error_policy = error_policy assert self.action in ["prepend", "append"], \
f"invalid action '{action}'"
self.error_policy = error_policy.lower()
assert self.error_policy in ["ignore", "reject", "wrap"], \
f"invalid error_policy '{error_policy}'"
self.pretend = pretend self.pretend = pretend
def patch_message_body(self, milter, logger): def patch_message_body(self, milter, logger):

View File

@@ -101,17 +101,12 @@ def main():
if not rule["actions"]: if not rule["actions"]:
raise RuntimeError( raise RuntimeError(
f"{rule['name']}: no actions configured") f"{rule['name']}: no actions configured")
ModifyMilter.set_config(cfg, args.debug)
except (RuntimeError, AssertionError) as e: except (RuntimeError, AssertionError) as e:
logger.error(f"config error: {e}") logger.error(f"config error: {e}")
sys.exit(255) sys.exit(255)
try:
ModifyMilter.set_config(cfg, args.debug)
except RuntimeError as e:
logger.error(e)
sys.exit(254)
if args.test: if args.test:
print("Configuration OK") print("Configuration OK")
sys.exit(0) sys.exit(0)