X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=dmarc_to_database;fp=dmarc_to_database;h=38ec02837ae4c6d4caf8ffb080c755ebd5c4a4dd;hb=1347c11e6608456984d0bb12fc03b405d7c26f6c;hp=ca6eafb52c20477651a6078a97f824cc8be86dc1;hpb=ffcd7c45aeb60112bacfb559db75295ebbccf515;p=dmarc.git diff --git a/dmarc_to_database b/dmarc_to_database index ca6eafb..38ec028 100755 --- a/dmarc_to_database +++ b/dmarc_to_database @@ -24,10 +24,13 @@ def fetch_msg(num): return mailbox.uid('FETCH', num, '(RFC822)')[1][0][1] def xml_of_part(part): - with zipfile.ZipFile(io.BytesIO(part.get_payload(decode=True))) as zf: + try: + with zipfile.ZipFile(io.BytesIO(part.get_payload(decode=True))) as zf: fn = zf.infolist()[0].filename contents = zf.read(fn).decode('utf-8') return xml.etree.ElementTree.fromstring(contents) + except zipfile.BadZipFile: + return None def xml_of(message): @@ -201,7 +204,8 @@ resp, nums = mailbox.uid('SEARCH', None, mails_from) dmarc_reports = [report for report_set in [extract_report(fetch_msg(n)) for n in nums[0].split()] - for report in report_set] + for report in report_set + if report] mailbox.close() mailbox.logout()