diff options
author | Folker Bernitt <fbernitt@thoughtworks.com> | 2015-09-10 16:54:22 +0200 |
---|---|---|
committer | Folker Bernitt <fbernitt@thoughtworks.com> | 2015-09-10 16:54:22 +0200 |
commit | 6f708c2b53c8faa2bc3d73891413a44d33044237 (patch) | |
tree | 88a23628c9579b34d986e7fe12180a461cefda07 | |
parent | a2610d545a8a26d9f2101a6b1ccb7f467bb9484d (diff) |
Handle encoding errors in headers gracefully.
- Issue #450
-rw-r--r-- | service/pixelated/adapter/mailstore/leap_mailstore.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/service/pixelated/adapter/mailstore/leap_mailstore.py b/service/pixelated/adapter/mailstore/leap_mailstore.py index eb12bd1d..b7c6d0ff 100644 --- a/service/pixelated/adapter/mailstore/leap_mailstore.py +++ b/service/pixelated/adapter/mailstore/leap_mailstore.py @@ -115,10 +115,13 @@ class LeapMail(Mail): return self.remove_duplicates([self._decoded_header_utf_8(v) for v in header_value]) elif header_value is not None: def encode_chunk(content, encoding): - return unicode(content, encoding=encoding or 'ascii') + return unicode(content, encoding=encoding or 'ascii', errors='ignore') - encoded_chunks = [encode_chunk(content, encoding) for content, encoding in decode_header(header_value)] - return ' '.join(encoded_chunks) # decode_header strips whitespaces on all chunks, joining over ' ' is only a workaround, not a proper fix + try: + encoded_chunks = [encode_chunk(content, encoding) for content, encoding in decode_header(header_value)] + return ' '.join(encoded_chunks) # decode_header strips whitespaces on all chunks, joining over ' ' is only a workaround, not a proper fix + except UnicodeEncodeError: + return unicode(header_value.encode('ascii', errors='ignore')) def as_dict(self): return { |