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) spam_result = msg.get_all(headers.SPAMD_RESULT)
if not spam_result: if not spam_result:
return None 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)): for entry_pos in range(len(spam_entries)):
sep = spam_entries[entry_pos].find("(") sep = spam_entries[entry_pos].find("(")
if sep > -1: if sep > -1:
spam_entries[entry_pos] = spam_entries[entry_pos][:sep] spam_entries[entry_pos] = spam_entries[entry_pos][:sep]
for header_value, dmarc_result in DmarcCheckResult.get_string_dict().items(): for header_value, dmarc_result in DmarcCheckResult.get_string_dict().items():
if header_value in spam_entries: if header_value in spam_entries:
return dmarc_result return dmarc_result
return None return None

View file

@ -545,6 +545,8 @@ def apply_dmarc_policy(
dmarc_result = get_dmarc_status(msg) dmarc_result = get_dmarc_status(msg)
if dmarc_result: if dmarc_result:
newrelic.agent.record_custom_event("DmarcCheck", {"result": dmarc_result.name}) 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: if not DMARC_CHECK_ENABLED or not dmarc_result:
return None return None
@ -554,7 +556,10 @@ def apply_dmarc_policy(
DmarcCheckResult.reject, DmarcCheckResult.reject,
DmarcCheckResult.soft_fail, 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) quarantine_dmarc_failed_email(alias, contact, envelope, msg)
Notification.create( Notification.create(
user_id=alias.user_id, user_id=alias.user_id,