Skip to content

Commit

Permalink
Ignore errors when parsing text-based forensic reports (#460)
Browse files Browse the repository at this point in the history
Starting 8.2.0, parsedmarc crashes instead of ignoring some invalid reports.

The original change was introduced in abf9695.
  • Loading branch information
bendem committed Feb 19, 2024
1 parent b808850 commit fc49f7f
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions parsedmarc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1056,16 +1056,23 @@ def parse_report_email(input_, offline=False, ip_db_path=None,

elif content_type == "text/plain":
if "A message claiming to be from you has failed" in payload:
parts = payload.split("detected.")
field_matches = text_report_regex.findall(parts[0])
fields = dict()
for match in field_matches:
field_name = match[0].lower().replace(" ", "-")
fields[field_name] = match[1].strip()
feedback_report = "Arrival-Date: {}\n" \
"Source-IP: {}" \
"".format(fields["received-date"],
fields["sender-ip-address"])
try:
parts = payload.split("detected.", 1)
field_matches = text_report_regex.findall(parts[0])
fields = dict()
for match in field_matches:
field_name = match[0].lower().replace(" ", "-")
fields[field_name] = match[1].strip()

feedback_report = "Arrival-Date: {}\n" \
"Source-IP: {}" \
"".format(fields["received-date"],
fields["sender-ip-address"])
except Exception as e:
error = 'Unable to parse message with ' \
'subject "{0}": {1}'.format(subject, e)
raise InvalidDMARCReport(error)

sample = parts[1].lstrip()
logger.debug(sample)
else:
Expand Down

0 comments on commit fc49f7f

Please sign in to comment.