From dbcab06587c394cd44ca6a5059f98c636d4c5428 Mon Sep 17 00:00:00 2001 From: Dario Ernst Date: Sat, 7 Mar 2020 18:17:24 +0000 Subject: [PATCH] Ignore newlines and comment-lines in postfix overrides To make postfix override files understandable and readable, users may want to insert empty newlines and #-commented lines in their postfix override files too. This will now ignore such bogus-lines and not send them to `postconf`, which produced ugly errors in the past. closes #1098 --- core/postfix/start.py | 10 ++++++++-- towncrier/newsfragments/1098.misc | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 towncrier/newsfragments/1098.misc diff --git a/core/postfix/start.py b/core/postfix/start.py index 12aaa770..c32099bf 100755 --- a/core/postfix/start.py +++ b/core/postfix/start.py @@ -27,6 +27,10 @@ def start_podop(): ("senderlogin", "url", url + "sender/login/ยง") ]) +def is_valid_postconf_line(line): + return not line.startswith("#") \ + and not line == '' + # Actual startup script os.environ["FRONT_ADDRESS"] = system.get_host_address_from_environment("FRONT", "front") os.environ["ADMIN_ADDRESS"] = system.get_host_address_from_environment("ADMIN", "admin") @@ -38,11 +42,13 @@ for postfix_file in glob.glob("/conf/*.cf"): if os.path.exists("/overrides/postfix.cf"): for line in open("/overrides/postfix.cf").read().strip().split("\n"): - os.system('postconf -e "{}"'.format(line)) + if is_valid_postconf_line(line): + os.system('postconf -e "{}"'.format(line)) if os.path.exists("/overrides/postfix.master"): for line in open("/overrides/postfix.master").read().strip().split("\n"): - os.system('postconf -Me "{}"'.format(line)) + if is_valid_postconf_line(line): + os.system('postconf -Me "{}"'.format(line)) for map_file in glob.glob("/overrides/*.map"): destination = os.path.join("/etc/postfix", os.path.basename(map_file)) diff --git a/towncrier/newsfragments/1098.misc b/towncrier/newsfragments/1098.misc new file mode 100644 index 00000000..d99aa24d --- /dev/null +++ b/towncrier/newsfragments/1098.misc @@ -0,0 +1 @@ +Ignore newlines and comment-lines in postfix overrides - this means you can now make your override configfiles much more readable.