improve exception handling

This commit is contained in:
2020-06-11 12:03:02 +02:00
parent d52e3965a5
commit 533fef1d63

View File

@@ -154,6 +154,11 @@ class ModifyMilter(Milter.Base):
self.rules = ModifyMilter._rules.copy()
def connect(self, IPname, family, hostaddr):
try:
if hostaddr is None:
self.logger.error("unable to proceed, host address is None")
return Milter.TEMPFAIL
self.logger.debug(
f"accepted milter connection from {hostaddr[0]} "
f"port {hostaddr[1]}")
@@ -168,10 +173,15 @@ class ModifyMilter(Milter.Base):
f"host {hostaddr[0]} is ignored by all rules, "
f"skip further processing")
return Milter.ACCEPT
except Exception as e:
self.logger.exception(
f"an exception occured in connect function: {e}")
return Milter.TEMPFAIL
return Milter.CONTINUE
def envfrom(self, mailfrom, *str):
try:
mailfrom = "@".join(parse_addr(mailfrom)).lower()
for rule in self.rules.copy():
if rule.ignores(envfrom=mailfrom):
@@ -179,16 +189,27 @@ class ModifyMilter(Milter.Base):
if not self.rules:
self.logger.debug(
f"envelope-from address {mailfrom} is ignored by all rules, "
f"skip further processing")
f"envelope-from address {mailfrom} is ignored by "
f"all rules, skip further processing")
return Milter.ACCEPT
self.recipients = set()
except Exception as e:
self.logger.exception(
f"an exception occured in envfrom function: {e}")
return Milter.TEMPFAIL
return Milter.CONTINUE
@Milter.noreply
def envrcpt(self, to, *str):
try:
self.recipients.add("@".join(parse_addr(to)).lower())
except Exception as e:
self.logger.exception(
f"an exception occured in envrcpt function: {e}")
return Milter.TEMPFAIL
return Milter.CONTINUE
def data(self):