summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2013-07-05 19:38:56 +0100
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2013-07-05 20:25:15 +0100
commit76cefcae360ddfec1b08018c70df45490abfd693 (patch)
treeb94f4ed76cd47ca0d7dbb6c849d914b8490ab0ab
parenta5735530bfa78ad9f926f578a4e17a6fc8dc3c28 (diff)
downloadpykolab-76cefcae360ddfec1b08018c70df45490abfd693.tar.gz
If a string isn't unicode, attempt to make it so
-rw-r--r--pykolab/imap_utf7.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/pykolab/imap_utf7.py b/pykolab/imap_utf7.py
index 6a670b5..038623b 100644
--- a/pykolab/imap_utf7.py
+++ b/pykolab/imap_utf7.py
@@ -29,7 +29,10 @@ class FolderNameError(ValueError):
def encode(s):
if isinstance(s, str) and sum(n for n in (ord(c) for c in s) if n > 127):
- raise FolderNameError("%r contains characters not valid in a str folder name. "
+ try:
+ s = unicode(s, "UTF-8")
+ except Exception, errmsg:
+ raise FolderNameError("%r contains characters not valid in a str folder name. "
"Convert to unicode first?" % s)
r = []
@@ -49,6 +52,7 @@ def encode(s):
_in.append(c)
if _in:
r.extend(['&', modified_base64(''.join(_in)), '-'])
+
return ''.join(r)