From: Florian Klink Date: Sun, 24 Sep 2017 12:36:11 +0000 (+0200) Subject: python: open messages in binary mode X-Git-Tag: 0.26_rc0~134 X-Git-Url: https://git.notmuchmail.org/git?a=commitdiff_plain;ds=sidebyside;h=91fe20cd90ce46bf80c416a5c4451f76b4d69ec5;hp=91fe20cd90ce46bf80c416a5c4451f76b4d69ec5;p=notmuch python: open messages in binary mode currently, notmuch's get_message_parts() opens the file in text mode and passes the file object to email.message_from_file(fp). In case the email contains UTF-8 characters, reading might fail inside email.parser with the following exception: File "/usr/lib/python3.6/site-packages/notmuch/message.py", line 591, in get_message_parts email_msg = email.message_from_binary_file(fp) File "/usr/lib/python3.6/email/__init__.py", line 62, in message_from_binary_file return BytesParser(*args, **kws).parse(fp) File "/usr/lib/python3.6/email/parser.py", line 110, in parse return self.parser.parse(fp, headersonly) File "/usr/lib/python3.6/email/parser.py", line 54, in parse data = fp.read(8192) File "/usr/lib/python3.6/codecs.py", line 321, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 1865: invalid continuation byte To fix this, read file in binary mode and pass to email.message_from_binary_file(fp). Unfortunately, Python 2 doesn't support email.message_from_binary_file(fp), so keep using email.message_from_file(fp) there. Signed-off-by: Florian Klink ---