Merge pull request #855 from simple-login/fix/dmarc

Fix/dmarc
This commit is contained in:
Son Nguyen Kim 2022-03-25 18:01:28 +01:00 committed by GitHub
commit beee438445
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -1445,12 +1445,15 @@ def get_dmarc_status(msg: Message) -> Optional[DmarcCheckResult]:
spam_result = msg.get_all(headers.SPAMD_RESULT)
if not spam_result:
return None
spam_entries = [entry.strip() for entry in spam_result[-1].split("\n")]
spam_entries = [entry.strip() for entry in str(spam_result[-1]).split("\n")]
for entry_pos in range(len(spam_entries)):
sep = spam_entries[entry_pos].find("(")
if sep > -1:
spam_entries[entry_pos] = spam_entries[entry_pos][:sep]
for header_value, dmarc_result in DmarcCheckResult.get_string_dict().items():
if header_value in spam_entries:
return dmarc_result
return None

View File

@ -545,6 +545,8 @@ def apply_dmarc_policy(
dmarc_result = get_dmarc_status(msg)
if dmarc_result:
newrelic.agent.record_custom_event("DmarcCheck", {"result": dmarc_result.name})
else:
newrelic.agent.record_custom_event("DmarcCheck", {"result": "unknown"})
if not DMARC_CHECK_ENABLED or not dmarc_result:
return None
@ -554,7 +556,10 @@ def apply_dmarc_policy(
DmarcCheckResult.reject,
DmarcCheckResult.soft_fail,
):
LOG.w(f"put email from {contact} to {alias} to quarantine. {dmarc_result}")
LOG.w(
f"put email from {contact} to {alias} to quarantine. {dmarc_result}, "
f"mail_from:{envelope.mail_from}, from_header: {msg[headers.FROM]}"
)
quarantine_dmarc_failed_email(alias, contact, envelope, msg)
Notification.create(
user_id=alias.user_id,