From 7d36256b7ca7ee8e83622e3dbcf96ae1eb2e4b8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Casaj=C3=BAs?= Date: Tue, 29 Mar 2022 10:52:11 +0200 Subject: [PATCH] Check return-path spf record before bouncing a message --- app/models.py | 22 ++++++++++++++++++++++ email_handler.py | 3 ++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/models.py b/app/models.py index 96b303c5..c0eca242 100644 --- a/app/models.py +++ b/app/models.py @@ -257,6 +257,28 @@ class DmarcCheckResult(EnumE): } +class SPFCheckResult(EnumE): + allow = 0 + fail = 1 + soft_fail = 1 + neutral = 2 + temp_error = 3 + none = 4 + perm_error = 5 + + @staticmethod + def get_string_dict(): + return { + "R_SPF_ALLOW": SPFCheckResult.allow, + "R_SPF_FAIL": SPFCheckResult.fail, + "R_SPF_SOFTFAIL": SPFCheckResult.soft_fail, + "R_SPF_NEUTRAL": SPFCheckResult.neutral, + "R_SPF_DNSFAIL": SPFCheckResult.temp_error, + "R_SPF_NA": SPFCheckResult.none, + "R_SPF_PERMFAIL": SPFCheckResult.perm_error, + } + + class Hibp(Base, ModelMixin): __tablename__ = "hibp" name = sa.Column(sa.String(), nullable=False, unique=True, index=True) diff --git a/email_handler.py b/email_handler.py index 6c816b89..4f03854a 100644 --- a/email_handler.py +++ b/email_handler.py @@ -2601,10 +2601,11 @@ class MailHandler: elapsed = time.time() - start LOG.i( - "Finish mail_from %s, rcpt_tos %s, takes %s seconds <<===", + "Finish mail_from %s, rcpt_tos %s, takes %s seconds with return code '%s'<<===", envelope.mail_from, envelope.rcpt_tos, elapsed, + ret, ) newrelic.agent.record_custom_metric("Custom/email_handler_time", elapsed) newrelic.agent.record_custom_metric("Custom/number_incoming_email", 1)