diff options
author | Folker Bernitt <fbernitt@thoughtworks.com> | 2015-04-09 11:46:35 +0200 |
---|---|---|
committer | Folker Bernitt <fbernitt@thoughtworks.com> | 2015-04-09 11:49:09 +0200 |
commit | 88b281330c6fca313bbfd3482ea2aeb5efa08c78 (patch) | |
tree | d592e550dae89965e6aa4d0b7c05f04ff687a327 /service/pixelated/adapter/model/mail.py | |
parent | 2b5ab82d00fb7ebe746f0df6ef66b014fd4e50f6 (diff) |
Default broken Content-Transfer-Encoding to 8bit.
- Issue #347
Diffstat (limited to 'service/pixelated/adapter/model/mail.py')
-rw-r--r-- | service/pixelated/adapter/model/mail.py | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/service/pixelated/adapter/model/mail.py b/service/pixelated/adapter/model/mail.py index 7e0d5ad1..8e7b745c 100644 --- a/service/pixelated/adapter/model/mail.py +++ b/service/pixelated/adapter/model/mail.py @@ -239,22 +239,26 @@ class PixelatedMail(Mail): content_type = self._parse_charset_header(part['headers'].get('Content-Type')) try: - decoding_map = { - 'quoted-printable': lambda content, content_type: content.decode('quopri').decode(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 self._decode_content_with_fallback(part['content'], decoding_map[encoding], content_type) - else: - return self._decode_content_with_fallback(part['content'], lambda content, content_type: content.encode(content_type), 'ascii') + decoding_func = self._decoding_function_for_encoding(encoding) + return self._decode_content_with_fallback(part['content'], decoding_func, content_type) 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 + def _decoding_function_for_encoding(self, encoding): + decoding_map = { + 'quoted-printable': lambda content, content_type: content.decode('quopri').decode(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 in decoding_map: + return decoding_map[encoding] + else: + return decoding_map['8bit'] + def _decode_content_with_fallback(self, content, decode_func, content_type): try: return decode_func(content, content_type) |