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 19:38:56 +0100
commit26a08fdcc8746650e279770ecf52077d96a0821f (patch)
tree8801745a81707c94ea37fcbca796018b04f04d8e
parentae26c04fefaf11e16601348099952b90bdf5bfc8 (diff)
downloadpykolab-26a08fdcc8746650e279770ecf52077d96a0821f.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)