Skip to content

dim: fix handling of 8-bit non-UTF-8 messages

Python's open() function will return a file object that decodes input bytes to an UTF-8 string. Python assumes all files are UTF-8 by default (unless an explicit encoding param is passed).

This works fine with 7-bit and UTF-8 messages. However, when a message uses a 8-bit Content-Transfer-Encoding and a non-UTF-8 charset (such as iso-8859-1), Python will error out.

To prevent this, open the file in binary mode to prevent Python from doing any charset conversion under-the-hood.

Signed-off-by: Simon Ser contact@emersion.fr

cc @danvet

Edited by Simon Ser

Merge request reports