improve performance of header conditions
This commit is contained in:
@@ -151,16 +151,16 @@ class Conditions:
|
|||||||
|
|
||||||
if self.envfrom is not None:
|
if self.envfrom is not None:
|
||||||
envfrom = milter.msginfo["mailfrom"]
|
envfrom = milter.msginfo["mailfrom"]
|
||||||
match = self.envfrom.match(envfrom)
|
if match := self.envfrom.match(envfrom):
|
||||||
if not match:
|
logger.debug(
|
||||||
|
f"envfrom matches for "
|
||||||
|
f"envelope-from address {envfrom}")
|
||||||
|
self.update_msginfo_from_match(milter, match)
|
||||||
|
else:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"ignore envelope-from address {envfrom}, "
|
f"ignore envelope-from address {envfrom}, "
|
||||||
f"envfrom does not match")
|
f"envfrom does not match")
|
||||||
return False
|
return False
|
||||||
logger.debug(
|
|
||||||
f"envfrom matches for "
|
|
||||||
f"envelope-from address {envfrom}")
|
|
||||||
self.update_msginfo_from_match(milter, match)
|
|
||||||
|
|
||||||
if self.envto is not None:
|
if self.envto is not None:
|
||||||
envto = milter.msginfo["rcpts"]
|
envto = milter.msginfo["rcpts"]
|
||||||
@@ -181,21 +181,16 @@ class Conditions:
|
|||||||
self.update_msginfo_from_match(milter, match)
|
self.update_msginfo_from_match(milter, match)
|
||||||
|
|
||||||
if self.headers is not None:
|
if self.headers is not None:
|
||||||
headers = self.headers.copy()
|
headers = map(lambda h: f"{h[0]}: {h[1]}", milter.msg.items())
|
||||||
for field, value in milter.msg.items():
|
for hdr in self.headers:
|
||||||
header = f"{field}: {value}"
|
matches = filter(None, map(lambda h: hdr.search(h), headers))
|
||||||
for h in headers.copy():
|
if match := next(matches, None):
|
||||||
match = h.search(header)
|
logger.debug(
|
||||||
if match:
|
f"headers matches for "
|
||||||
logger.debug(
|
f"header: {match.string}")
|
||||||
f"headers matches for "
|
self.update_msginfo_from_match(milter, match)
|
||||||
f"header: {header}")
|
continue
|
||||||
self.update_msginfo_from_match(milter, match)
|
|
||||||
headers.remove(h)
|
|
||||||
if not headers:
|
|
||||||
break
|
|
||||||
|
|
||||||
if headers:
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"ignore message, "
|
"ignore message, "
|
||||||
"headers does not match")
|
"headers does not match")
|
||||||
|
|||||||
Reference in New Issue
Block a user