summaryrefslogtreecommitdiff
path: root/alot/helper.py
diff options
context:
space:
mode:
authorJustus Winter <4winter@informatik.uni-hamburg.de>2011-12-25 03:19:26 +0100
committerJustus Winter <4winter@informatik.uni-hamburg.de>2011-12-25 03:36:00 +0100
commit5255f191cd2908842fa9b16796ca5a7b26adf185 (patch)
treec2e247f2a321592fb9af12267e652cb797d7c8e7 /alot/helper.py
parent609ab8064e77e5fbb5c54d1c4f20a8fed86f1f85 (diff)
Add helper.guess_encoding
Diffstat (limited to 'alot/helper.py')
-rw-r--r--alot/helper.py14
1 files changed, 14 insertions, 0 deletions
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.