Add no header test

This commit is contained in:
Adrià Casajús 2022-03-29 15:59:35 +02:00
parent 085c166cb2
commit ac9b88f87d
No known key found for this signature in database
GPG key ID: F0033226A5AFC9B9
3 changed files with 36 additions and 2 deletions

View file

@ -563,7 +563,7 @@ def apply_dmarc_policy(
# DmarcCheckResult.soft_fail,
):
LOG.w(
f"put email from {contact} to {alias} to quarantine. {spam_result}, "
f"put email from {contact} to {alias} to quarantine. {spam_result.event_data()}, "
f"mail_from:{envelope.mail_from}, from_header: {msg[headers.FROM]}"
)
email_log = quarantine_dmarc_failed_email(alias, contact, envelope, msg)
@ -2595,7 +2595,8 @@ class MailHandler:
return_status = handle(envelope, msg)
elapsed = time.time() - start
if return_status[0] == "5":
if get_spamd_result(msg).spf in (
spamd_result = get_spamd_result(msg)
if spamd_result and get_spamd_result(msg).spf in (
SPFCheckResult.fail,
SPFCheckResult.soft_fail,
):

View file

@ -0,0 +1,19 @@
X-SimpleLogin-Client-IP: 54.39.200.130
Received-SPF: Softfail (mailfrom) identity=mailfrom; client-ip=34.59.200.130;
helo=relay.somewhere.net; envelope-from=everwaste@gmail.com;
receiver=<UNKNOWN>
Received: from relay.somewhere.net (relay.somewhere.net [34.59.200.130])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(No client certificate requested)
by mx1.sldev.ovh (Postfix) with ESMTPS id 6D8C13F069
for <wehrman_mannequin@sldev.ovh>; Thu, 17 Mar 2022 16:50:20 +0000 (UTC)
Date: Thu, 17 Mar 2022 16:50:18 +0000
To: {{ alias_email }}
From: somewhere@rainbow.com
Subject: test Thu, 17 Mar 2022 16:50:18 +0000
Message-Id: <20220317165018.000191@somewhere-5488dd4b6b-7crp6>
X-Mailer: swaks v20201014.0 jetmore.org/john/code/swaks/
X-Rspamd-Queue-Id: 6D8C13F069
X-Rspamd-Server: staging1
This is a test mailing

View file

@ -145,3 +145,17 @@ def test_preserve_5xx_with_valid_spf(flask_client):
envelope.rcpt_tos = [msg["to"]]
result = email_handler.MailHandler()._handle(envelope, msg)
assert result == status.E512
def test_preserve_5xx_with_no_header(flask_client):
user = create_random_user()
alias = Alias.create_new_random(user)
msg = load_eml_file(
"no_spamd_header.eml",
{"alias_email": alias.email},
)
envelope = Envelope()
envelope.mail_from = BOUNCE_EMAIL.format(999999999999999999)
envelope.rcpt_tos = [msg["to"]]
result = email_handler.MailHandler()._handle(envelope, msg)
assert result == status.E512