summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomás Touceda <chiiph@leap.se>2014-01-17 15:52:21 -0300
committerTomás Touceda <chiiph@leap.se>2014-01-17 15:52:21 -0300
commitb17dee1c1ef4f423de4ff56c90e9c6d6b39e2504 (patch)
tree9c9c97be243360f29347ee9013604de21c5b8e85
parent646dd2fd5fb3980f08490dcba03948164ab62bdf (diff)
parent3117dd17ebbce9dcf31ecb2951ba58ed67bcf7ce (diff)
Merge remote-tracking branch 'refs/remotes/ivan/feature/support-str-in-charset-detection' into develop
-rw-r--r--changes/support-str-in-charset-detection1
-rw-r--r--src/leap/common/mail.py9
2 files changed, 5 insertions, 5 deletions
diff --git a/changes/support-str-in-charset-detection b/changes/support-str-in-charset-detection
new file mode 100644
index 0000000..015aab0
--- /dev/null
+++ b/changes/support-str-in-charset-detection
@@ -0,0 +1 @@
+ o Support str type in email charset detection.
diff --git a/src/leap/common/mail.py b/src/leap/common/mail.py
index 2f2146d..b630c90 100644
--- a/src/leap/common/mail.py
+++ b/src/leap/common/mail.py
@@ -20,26 +20,25 @@ Utility functions for email.
import email
import re
-from leap.common.check import leap_assert_type
-
def get_email_charset(content, default="utf-8"):
"""
Mini parser to retrieve the charset of an email.
:param content: mail contents
- :type content: unicode
+ :type content: unicode or str
:param default: optional default value for encoding
:type default: str or None
:returns: the charset as parsed from the contents
:rtype: str
"""
- leap_assert_type(content, unicode)
+ if isinstance(content, unicode):
+ content.encode("utf-8", "replace")
charset = default
try:
- em = email.message_from_string(content.encode("utf-8", "replace"))
+ em = email.message_from_string(content)
# Miniparser for: Content-Type: <something>; charset=<charset>
charset_re = r'''charset=(?P<charset>[\w|\d|-]*)'''
charset = re.findall(charset_re, em["Content-Type"])[0]