summaryrefslogtreecommitdiff
path: root/src/leap/common/mail.py
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2014-04-09 14:25:14 -0500
committerKali Kaneko <kali@leap.se>2014-04-09 14:25:14 -0500
commit09c0d339b0885dc09f39ca2c1598dc7263c86e93 (patch)
tree1d458e293f6750a56dfb1e613bcac33d45f35ced /src/leap/common/mail.py
parentf15cf332f1fa78f467253666485a0953590289a7 (diff)
parent75309e8bd6b762cad41eaf7d6bf8d4a3696105d2 (diff)
Merge tag '0.3.7' into deb-0.3.7
Tag leap.common version 0.3.7
Diffstat (limited to 'src/leap/common/mail.py')
-rw-r--r--src/leap/common/mail.py9
1 files changed, 4 insertions, 5 deletions
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]