diff options
author | Folker Bernitt <fbernitt@thoughtworks.com> | 2015-03-12 19:27:33 +0100 |
---|---|---|
committer | Folker Bernitt <fbernitt@thoughtworks.com> | 2015-03-12 19:27:33 +0100 |
commit | 787f6ffaa5cbac73d7966dd9a58e158bcf382c90 (patch) | |
tree | a446e560c29a934c80aabcc8a8ab09cbb0c8c000 /service/pixelated/adapter | |
parent | 03c278827766a084d30c793106eb0fb0b211e6d8 (diff) |
Added some error logging if mail part parsing fails.
- Especially interested in the Content-Type header field
Diffstat (limited to 'service/pixelated/adapter')
-rw-r--r-- | service/pixelated/adapter/model/mail.py | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/service/pixelated/adapter/model/mail.py b/service/pixelated/adapter/model/mail.py index c11b2aa3..f262d420 100644 --- a/service/pixelated/adapter/model/mail.py +++ b/service/pixelated/adapter/model/mail.py @@ -26,6 +26,10 @@ from email.MIMEMultipart import MIMEMultipart from pycryptopp.hash import sha256 import re from pixelated.support.functional import compact +import logging + + +logger = logging.getLogger(__name__) class Mail(object): @@ -232,16 +236,22 @@ class PixelatedMail(Mail): encoding = part['headers'].get('Content-Transfer-Encoding', '') content_type = self._parse_charset_header(part['headers'].get('Content-Type')) - decoding_map = { - 'quoted-printable': lambda content, content_type: unicode(content.decode('quopri'), content_type), - 'base64': lambda content, content_type: content.decode('base64').decode('utf-8'), - '7bit': lambda content, content_type: content.encode(content_type), - '8bit': lambda content, content_type: content.encode(content_type) - } - if encoding: - return decoding_map[encoding](part['content'], content_type) - else: - return part['content'] + try: + decoding_map = { + 'quoted-printable': lambda content, content_type: unicode(content.decode('quopri'), content_type), + 'base64': lambda content, content_type: content.decode('base64').decode('utf-8'), + '7bit': lambda content, content_type: content.encode(content_type), + '8bit': lambda content, content_type: content.encode(content_type) + } + if encoding: + return decoding_map[encoding](part['content'], content_type) + else: + return part['content'] + except Exception: + logger.error('Failed to decode mail part with:') + logger.error('Content-Transfer-Encoding: %s' % encoding) + logger.error('Content-Type: %s' % part['headers'].get('Content-Type')) + raise @property def alternatives(self): |