Skip to content

Commit

Permalink
Dmarc fix (#2079)
Browse files Browse the repository at this point in the history
* Add log to spam check + remove invisible characters on import

* Update log
  • Loading branch information
acasajus committed Mar 26, 2024
1 parent 36cf530 commit 3c364da
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/handler/dmarc.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def apply_dmarc_policy_for_forward_phase(
) -> Tuple[Message, Optional[str]]:
spam_result = SpamdResult.extract_from_headers(msg, Phase.forward)
if not DMARC_CHECK_ENABLED or not spam_result:
LOG.i("DMARC check disabled")
return msg, None
LOG.i(f"Spam check result in {spam_result}")

from_header = get_header_unicode(msg[headers.FROM])

Expand Down Expand Up @@ -150,8 +152,10 @@ def apply_dmarc_policy_for_reply_phase(
) -> Optional[str]:
spam_result = SpamdResult.extract_from_headers(msg, Phase.reply)
if not DMARC_CHECK_ENABLED or not spam_result:
LOG.i("DMARC check disabled")
return None

LOG.i(f"Spam check result is {spam_result}")
if spam_result.dmarc not in (
DmarcCheckResult.quarantine,
DmarcCheckResult.reject,
Expand Down
5 changes: 4 additions & 1 deletion app/import_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ def handle_batch_import(batch_import: BatchImport):

LOG.d("Download file %s from %s", batch_import.file, file_url)
r = requests.get(file_url)
lines = [line.decode("utf-8") for line in r.iter_lines()]
# Replace invisible character
lines = [
line.decode("utf-8").replace("\ufeff", "").strip() for line in r.iter_lines()
]

import_from_csv(batch_import, user, lines)

Expand Down

0 comments on commit 3c364da

Please sign in to comment.