4.1.7 - Remove any invalid XML schema tags before parsing the XML (#18)

This commit is contained in:
Sean Whalen
2018-10-06 15:29:02 -04:00
parent ad922ad028
commit ead03b9779
4 changed files with 57 additions and 2 deletions
+5
View File
@@ -1,3 +1,8 @@
4.1.7
-----
- Remove any invalid XML schema tags before parsing the XML (#18)
4.1.6
-----
+4 -1
View File
@@ -44,12 +44,13 @@ import imapclient.exceptions
import dateparser
import mailparser
__version__ = "4.1.6"
__version__ = "4.1.7"
logger = logging.getLogger(__name__)
logger.setLevel(logging.ERROR)
feedback_report_regex = re.compile(r"^([\w\-]+): (.+)$", re.MULTILINE)
xml_schema_regex = re.compile(r"\s*<xs:schema.*>", re.MULTILINE)
MAGIC_ZIP = b"\x50\x4B\x03\x04"
MAGIC_GZIP = b"\x1F\x8B"
@@ -457,6 +458,8 @@ def parse_aggregate_report_xml(xml, nameservers=None, timeout=2.0):
OrderedDict: The parsed aggregate DMARC report
"""
try:
# Remove invalid schema tags
xml = xml_schema_regex.sub("", xml)
report = xmltodict.parse(xml)["feedback"]
report_metadata = report["report_metadata"]
schema = "draft"
@@ -0,0 +1,47 @@
<?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://dmarc.org/dmarc-xml/0.1">
<feedback>
<report_metadata>
<org_name>ikea.com</org_name>
<email>double-bounce@ikea.com</email>
<report_id>aggr_report_2018_10_05_5bc7e9b4f3e8a</report_id>
<date_range>
<begin>1538690400</begin>
<end>1538776800</end>
</date_range>
</report_metadata>
<policy_published>
<domain>xxxxxx.de</domain>
<adkim>r</adkim>
<aspf>r</aspf>
<p>none</p>
<sp>none</sp>
<pct>100</pct>
<fo>0</fo>
</policy_published>
<record>
<row>
<source_ip>234.234.234.234</source_ip>
<count>1</count>
<policy_evaluated>
<disposition>none</disposition>
<dkim>fail</dkim>
<spf>fail</spf>
</policy_evaluated>
</row>
<identifiers>
<header_from>xxxxxx.de</header_from>
<envelope_from>xxxxxx.de</envelope_from>
</identifiers>
<auth_results>
<dkim>
<domain>xxxxxx.de</domain>
<result>pass</result>
</dkim>
<spf>
<domain>mailrelay.com</domain>
<scope>helo</scope>
<result>none</result>
</spf>
</auth_results>
</record>
</feedback>
+1 -1
View File
@@ -14,7 +14,7 @@ from setuptools import setup
from codecs import open
from os import path
__version__ = "4.1.6"
__version__ = "4.1.7"
description = "A Python package and CLI for parsing aggregate and " \
"forensic DMARC reports"