-
Notifications
You must be signed in to change notification settings - Fork 8
TA-dmarc - No longer pulling events - TypeError #48
Comments
Is it possible that you were sent an improperly-formatted DMARC report on April 14, hence the runtime error? If you moved all of the reports from April 14 to another folder, and let the input run again, does it resume ingestion? Could you paste the full log message with the error? |
No problem, please see the full log message below:
|
Do you have any emails that arrived on the 14th without the report attached (or with an abnormal name)? |
We actually only got 1 email on the 14th that came from |
The issue seems to be:
I'm working on a patch to catch this. |
Here's a patch. I'm unable to test it so don't run it in production. diff --git a/bin/dmarc/imap2dir.py b/bin/dmarc/imap2dir.py
index 9e07116..c60d2bd 100644
--- a/bin/dmarc/imap2dir.py
+++ b/bin/dmarc/imap2dir.py
@@ -9,6 +9,7 @@ from imapclient import IMAPClient
import dkim
import dns
import msal
+import uuid
# Copyright 2017-2020 Jorrit Folmer
#
@@ -179,12 +180,55 @@ class Imap2Dir(object):
set(messageslist[x:x + fetch_size]), [b'RFC822']))
return response
+ def get_file_ext_from_content_type(self,ctype,uid):
+ """ For an eligible mime-type, return an appropriate file extension string
+ """
+ self.helper.log_debug(
+ 'get_file_ext_from_content_type: determining file extention for content-type %s of msg uid %d' %
+ (ctype, uid))
+ if ctype == "application/zip":
+ return "zip"
+ elif ctype == "application/gzip":
+ return "gz"
+ elif ctype == "application/x-gzip":
+ return "gz"
+ elif ctype == "application/octet-stream":
+ # Non-standard mimetype used by Amazon SES dmarc reports
+ return None
+ elif ctype == "application-x-gzip":
+ # Non-standard mimetype used by Comcast dmarc reports
+ return "gz"
+ elif ctype == "application/x-zip-compressed":
+ # Non-standard mimetype used by Yahoo dmarc reports
+ return "zip"
+ elif ctype == "application/xml":
+ return "xml"
+ elif ctype == "text/xml":
+ return "xml"
+ else:
+ self.helper.log_debug(
+ 'get_file_ext_from_content_type: skipping content-type %s of msg uid %d' %
+ (ctype, uid))
+ return None
+
def write_part_to_file(self, uid, part):
""" Write the selected message part to file """
filename = part.get_filename()
- # Sanitize filename, see issue #43
- filename = re.sub('[^\w\d!.-]', '', filename)
- filename = os.path.join(self.tmp_dir, os.path.basename(filename))
+ if filename is not None:
+ # Sanitize filename, see issue #43
+ filename = re.sub('[^\w\d!.-]', '', filename)
+ filename = os.path.join(self.tmp_dir, os.path.basename(filename))
+ else:
+ # Try to create a random file name because there isn't one in the mime header
+ # See issue #48.
+ # Since we don't have a file name, we have to guess the file extension based
+ # on the content type first.
+ ctype = part.get_content_type()
+ file_ext = self.get_file_ext_from_content_type(ctype, uid)
+ if file_ext is None:
+ # Guessing failed so skip writing this attachment
+ return None
+ filename = "{}.{}".format(uuid.uuid4(),file_ext)
try:
open(filename, 'wb').write(part.get_payload(decode=True))
except Exception as e:
@@ -246,7 +290,8 @@ class Imap2Dir(object):
ctype = part.get_content_type()
if self.check_eligible_mimetype(ctype, uid):
filename = self.write_part_to_file(uid, part)
- filelist.append(filename)
+ if filename is not None:
+ filelist.append(filename)
else:
self.helper.log_debug(
'save_reports_from_message_bodies: start non-multipart processing of msg uid %d' %
@@ -254,7 +299,8 @@ class Imap2Dir(object):
ctype = msg.get_content_type()
if self.check_eligible_mimetype(ctype, uid):
filename = self.write_part_to_file(uid, msg)
- filelist.append(filename)
+ if filename is not None:
+ filelist.append(filename)
else:
self.helper.log_debug(
'save_reports_from_message_bodies: skipping content-type %s of msg uid %d' % |
No worries, thank you for the quick update on this @jorritfolmer ! Do you anticipate this rolling out in an upcoming update for the app? |
No sorry I don’t think so, see #49 |
Good afternoon,
We have the TA-dmarc add-on installed on our HF and recently stopped receiving dmarc events on Friday, April 14, 2023. After reenabling the inputs and performing a restart on the HF, the events will still not come up. After performing a search on the source type for dmarc, we found the following error:
Are you aware of these issues and would you be able to possibly provide a fix when possible?
Please advise when you can, thank you!
The text was updated successfully, but these errors were encountered: