Also quarantine soft_fail dmarc results

This commit is contained in:
Adrià Casajús 2022-03-21 17:38:41 +01:00
parent 4d13e0c2b8
commit 16275620ae
No known key found for this signature in database
GPG Key ID: F0033226A5AFC9B9
2 changed files with 21 additions and 0 deletions

View File

@ -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

View File

@ -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