summaryrefslogtreecommitdiff
path: root/alot
diff options
context:
space:
mode:
authorJustus Winter <4winter@informatik.uni-hamburg.de>2011-12-25 03:19:26 +0100
committerPatrick Totzke <patricktotzke@gmail.com>2011-12-25 15:18:18 +0000
commit6de4310b1f81692a7aa0ace95affae82c2b18e22 (patch)
tree07ad28d97566637b57561a1d5c915b3397542e83 /alot
parent763882dbc46572e66a1bc0b12e06db453c54a389 (diff)
Add helper.guess_encoding
Diffstat (limited to 'alot')
-rw-r--r--alot/helper.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/alot/helper.py b/alot/helper.py
index 8b28fa37..9a15bb5d 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.