From: Olivier Matz Date: Sun, 29 Nov 2015 11:01:30 +0000 (+0100) Subject: utils: relax conversion to unicode X-Git-Url: http://git.droids-corp.org/?p=imapami.git;a=commitdiff_plain;h=4057b301a70d66aba805613e6c8798aaf86c719b utils: relax conversion to unicode Some mails have incorrectly encoded headers, resulting in an exception when decoding them. This can be reproduced manually: >>> s='Vos deux avantages : 20% de r\xc3\xa9duction + Q1|\x051\xa5\xd9\xc9\x85\xa5\xcd\xbd\xb8\x80\xd0\xe1\xa0\x81\xbd\x99\x99\x95\xc9\xd1\x94\x80\x84' >>> s.decode("utf-8") Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/encodings/utf_8.py", line 16, in decode return codecs.utf_8_decode(input, errors, True) Be more relax and try to fix the encoding errors instead of throwing an exception. Signed-off-by: Olivier Matz --- diff --git a/imapami/utils.py b/imapami/utils.py index 291b71f..4af970c 100644 --- a/imapami/utils.py +++ b/imapami/utils.py @@ -76,7 +76,7 @@ def headers_to_unicode(headers): if encoding is None: value = unicode(value) else: - value = value.decode(encoding) + value = value.decode(encoding, errors="replace") unicode_headers[key] = value return unicode_headers