From 6cbdfcecaa8ea4f4ac0a7efcfb6f7ecbbb762465 Mon Sep 17 00:00:00 2001 From: "max.mehl" Date: Thu, 23 Dec 2021 12:10:36 +0100 Subject: [PATCH] embed RE escape in get_maildropline --- autoreply_editor/main.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/autoreply_editor/main.py b/autoreply_editor/main.py index bb65606..b24541e 100644 --- a/autoreply_editor/main.py +++ b/autoreply_editor/main.py @@ -21,7 +21,7 @@ def qmail_status(user): # try to find active filter if re.search( - rf"^{re.escape(get_maildropline(user))}$", qmailfile.read(), re.MULTILINE + rf"^{get_maildropline(user, regex=True)}$", qmailfile.read(), re.MULTILINE ): # if get_maildropline(user) in qmailfile.read(): return True @@ -31,7 +31,7 @@ def qmail_status(user): # filter is deactivated (commented) if re.search( - rf"^#{re.escape(get_maildropline(user))}$", + rf"^#{get_maildropline(user, regex=True)}$", qmailfile.read(), re.MULTILINE, ): @@ -88,8 +88,11 @@ def get_filterfile(user, name): return filepath -def get_maildropline(user): - return f"|maildrop {get_filterfile(user, 'FOOBAR')}" +def get_maildropline(user, regex=False): + if regex: + return re.escape(f"|maildrop {get_filterfile(user, 'FOOBAR')}") + else: + return f"|maildrop {get_filterfile(user, 'FOOBAR')}" @app.route("/")