embed RE escape in get_maildropline

This commit is contained in:
2021-12-23 12:10:36 +01:00
parent 002512cf20
commit 6cbdfcecaa

View File

@@ -21,7 +21,7 @@ def qmail_status(user):
# try to find active filter # try to find active filter
if re.search( 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(): # if get_maildropline(user) in qmailfile.read():
return True return True
@@ -31,7 +31,7 @@ def qmail_status(user):
# filter is deactivated (commented) # filter is deactivated (commented)
if re.search( if re.search(
rf"^#{re.escape(get_maildropline(user))}$", rf"^#{get_maildropline(user, regex=True)}$",
qmailfile.read(), qmailfile.read(),
re.MULTILINE, re.MULTILINE,
): ):
@@ -88,7 +88,10 @@ def get_filterfile(user, name):
return filepath return filepath
def get_maildropline(user): 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')}" return f"|maildrop {get_filterfile(user, 'FOOBAR')}"