From 16275620aedd39d89979e476e0fc8ba503777a19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Casaj=C3=BAs?= Date: Mon, 21 Mar 2022 17:38:41 +0100 Subject: [PATCH] Also quarantine soft_fail dmarc results --- email_handler.py | 1 + tests/test_email_handler.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/email_handler.py b/email_handler.py index ca410abe..3fc24639 100644 --- a/email_handler.py +++ b/email_handler.py @@ -549,6 +549,7 @@ def apply_dmarc_policy(alias: Alias, contact: Contact, msg: Message) -> Optional if dmarc_result in ( DmarcCheckResult.quarantine, DmarcCheckResult.reject, + DmarcCheckResult.soft_fail, ): add_or_replace_header(msg, headers.SL_DIRECTION, "Forward") msg[headers.SL_ENVELOPE_TO] = alias.email diff --git a/tests/test_email_handler.py b/tests/test_email_handler.py index f82777c5..98d9ad94 100644 --- a/tests/test_email_handler.py +++ b/tests/test_email_handler.py @@ -85,3 +85,23 @@ def test_dmarc_quarantine(flask_client): email_log = email_logs[0] assert email_log.blocked assert email_log.refused_email_id + + +def test_gmail_dmarc_softfail(flask_client): + user = create_random_user() + alias = Alias.create_new_random(user) + msg = load_eml_file("dmarc_gmail_softfail.eml", {"alias_email": alias.email}) + envelope = Envelope() + envelope.mail_from = msg["from"] + envelope.rcpt_tos = [msg["to"]] + result = email_handler.handle(envelope, msg) + assert result == status.E519 + email_logs = ( + EmailLog.filter_by(user_id=user.id, alias_id=alias.id) + .order_by(EmailLog.id.desc()) + .all() + ) + assert len(email_logs) == 1 + email_log = email_logs[0] + assert email_log.blocked + assert email_log.refused_email_id