From 5255f191cd2908842fa9b16796ca5a7b26adf185 Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Sun, 25 Dec 2011 03:19:26 +0100 Subject: Add helper.guess_encoding --- alot/helper.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/alot/helper.py b/alot/helper.py index b12b7cb5..61a0ff37 100644 --- a/alot/helper.py +++ b/alot/helper.py @@ -258,6 +258,20 @@ def guess_mimetype(blob): return m.buffer(blob) +def guess_encoding(blob): + """ + uses file magic to determine the encoding of the given data blob. + + :param blob: file content as read by file.read() + :type blob: data + :returns: encoding + :rtype: str + """ + m = magic.open(magic.MAGIC_MIME_ENCODING) + m.load() + return m.buffer(blob) + + def guess_mimetype_of_path(path): """ uses file magic to determine the mime-type of a file at given path. -- cgit v1.2.3