utils: relax conversion to unicode
authorOlivier Matz <zer0@droids-corp.org>
Sun, 29 Nov 2015 11:01:30 +0000 (12:01 +0100)
committerOlivier Matz <zer0@droids-corp.org>
Sun, 29 Nov 2015 11:01:30 +0000 (12:01 +0100)
commit4057b301a70d66aba805613e6c8798aaf86c719b
treee095d165affdd71cb972228b87b72375bd93414a
parent6a57a643b9616029a8142197a27cd76caf7dc5f5
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 "<stdin>", line 1, in <module>
  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 <zer0@droids-corp.org>
imapami/utils.py