diff --git a/document_preview/helper/emlrender.py b/document_preview/helper/emlrender.py index be74e8a..c854aeb 100644 --- a/document_preview/helper/emlrender.py +++ b/document_preview/helper/emlrender.py @@ -28,6 +28,7 @@ try: from PIL import Image + Image.MAX_IMAGE_PIXELS = 2147483647 except: print('[ERROR] pillow module not installed ("pip install pillow")') @@ -40,8 +41,8 @@ __email__ = "xavier@erootshell.be" __name__ = "EMLRender" -textTypes = ['text/plain', 'text/html'] -imageTypes = ['image/gif', 'image/jpeg', 'image/png'] +textTypes = ["text/plain", "text/html"] +imageTypes = ["image/gif", "image/jpeg", "image/png"] def appendImages(images): @@ -50,7 +51,7 @@ def appendImages(images): new_width = max(widths) new_height = sum(heights) - new_im = Image.new('RGB', (new_width, new_height), color=bgColor) + new_im = Image.new("RGB", (new_width, new_height), color=bgColor) offset = 0 for im in images: # x = int((new_width - im.size[0])/2) @@ -61,58 +62,58 @@ def appendImages(images): def processEml(data, output_dir, logger, load_ext_images=False, load_images=False): - ''' + """ Process the email (bytes), extract MIME parts and useful headers. Generate a PNG picture of the mail - ''' + """ msg = email.message_from_bytes(data) try: - decode = email.header.decode_header(msg['Date'])[0] + decode = email.header.decode_header(msg["Date"])[0] dateField = str(decode[0]) except: - dateField = '<Unknown>' - logger.info('Date: %s' % dateField) + dateField = "<Unknown>" + logger.info("Date: %s" % dateField) try: - decode = email.header.decode_header(msg['From'])[0] + decode = email.header.decode_header(msg["From"])[0] fromField = str(decode[0]) except: - fromField = '<Unknown>' - logger.info('From: %s' % fromField) - fromField = fromField.replace('<', '<').replace('>', '>') + fromField = "<Unknown>" + logger.info("From: %s" % fromField) + fromField = fromField.replace("<", "<").replace(">", ">") try: - decode = email.header.decode_header(msg['To'])[0] + decode = email.header.decode_header(msg["To"])[0] toField = str(decode[0]) except: - toField = '<Unknown>' - logger.info('To: %s' % toField) - toField = toField.replace('<', '<').replace('>', '>') + toField = "<Unknown>" + logger.info("To: %s" % toField) + toField = toField.replace("<", "<").replace(">", ">") try: - decode = email.header.decode_header(msg['Subject'])[0] + decode = email.header.decode_header(msg["Subject"])[0] subjectField = str(decode[0]) except: - subjectField = '<Unknown>' - logger.info('Subject: %s' % subjectField) - subjectField = subjectField.replace('<', '<').replace('>', '>') + subjectField = "<Unknown>" + logger.info("Subject: %s" % subjectField) + subjectField = subjectField.replace("<", "<").replace(">", ">") try: - decode = email.header.decode_header(msg['Message-Id'])[0] + decode = email.header.decode_header(msg["Message-Id"])[0] idField = str(decode[0]) except: - idField = '<Unknown>' - logger.info('Message-Id: %s' % idField) - idField = idField.replace('<', '<').replace('>', '>') + idField = "<Unknown>" + logger.info("Message-Id: %s" % idField) + idField = idField.replace("<", "<").replace(">", ">") - imgkitOptions = {'load-error-handling': 'skip'} + imgkitOptions = {"load-error-handling": "skip", "quiet": None} if not load_ext_images: - imgkitOptions.update({'no-images': None, 'disable-javascript': None}) + imgkitOptions.update({"no-images": None, "disable-javascript": None}) # imgkitOptions.update({ 'quiet': None }) imagesList = [] # Build a first image with basic mail details - headers = ''' + headers = """
Date: | %s |
From: | %s |
Message-Id: | %s |