summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomás Touceda <chiiph@leap.se>2014-01-09 11:20:43 -0300
committerTomás Touceda <chiiph@leap.se>2014-01-09 11:20:43 -0300
commitb6bc40e8e3c32cecf80dc7b9d5d64209e0a018a5 (patch)
tree453930abda588ed99ea3b1d7bc8ce5d7281fd173
parentb92e0962d4ab08f450700dc9fabf2d7eab203aa7 (diff)
parent8d729209ceab5d9b4f4837d2f7f21118dd072655 (diff)
Merge remote-tracking branch 'refs/remotes/drebs/bug/4830_convert-unicode-to-str-when-raising-on-imap-server' into develop
-rw-r--r--mail/changes/bug_4830_convert-unicode-to-str-when-raising1
-rw-r--r--mail/src/leap/mail/imap/account.py32
-rw-r--r--mail/src/leap/mail/imap/parser.py5
3 files changed, 32 insertions, 6 deletions
diff --git a/mail/changes/bug_4830_convert-unicode-to-str-when-raising b/mail/changes/bug_4830_convert-unicode-to-str-when-raising
new file mode 100644
index 00000000..86d9b1cd
--- /dev/null
+++ b/mail/changes/bug_4830_convert-unicode-to-str-when-raising
@@ -0,0 +1 @@
+ o Convert unicode to str when raising exceptions in IMAP server (#4830).
diff --git a/mail/src/leap/mail/imap/account.py b/mail/src/leap/mail/imap/account.py
index fd861e7e..8f5b57bd 100644
--- a/mail/src/leap/mail/imap/account.py
+++ b/mail/src/leap/mail/imap/account.py
@@ -36,6 +36,23 @@ from leap.soledad.client import Soledad
#######################################
+def _unicode_as_str(text):
+ """
+ Return some representation of C{text} as a str.
+
+ This is here mainly because Twisted's exception methods are not able to
+ print unicode text.
+
+ :param text: The text to convert.
+ :type text: unicode
+
+ :return: A representation of C{text} as str.
+ :rtype: str
+ """
+ # XXX is there a better str representation for unicode?
+ return repr(text)
+
+
class SoledadBackedAccount(WithMsgFields, IndexedDB, MBoxParser):
"""
An implementation of IAccount and INamespacePresenteer
@@ -128,7 +145,8 @@ class SoledadBackedAccount(WithMsgFields, IndexedDB, MBoxParser):
name = self._parse_mailbox_name(name)
if name not in self.mailboxes:
- raise imap4.MailboxException("No such mailbox")
+ raise imap4.MailboxException("No such mailbox: %s" %
+ _unicode_as_str(name))
return SoledadMailbox(name, soledad=self._soledad)
@@ -154,7 +172,7 @@ class SoledadBackedAccount(WithMsgFields, IndexedDB, MBoxParser):
name = self._parse_mailbox_name(name)
if name in self.mailboxes:
- raise imap4.MailboxCollision, name
+ raise imap4.MailboxCollision, _unicode_as_str(name)
if not creation_ts:
# by default, we pass an int value
@@ -240,7 +258,8 @@ class SoledadBackedAccount(WithMsgFields, IndexedDB, MBoxParser):
name = self._parse_mailbox_name(name)
if not name in self.mailboxes:
- raise imap4.MailboxException("No such mailbox")
+ raise imap4.MailboxException("No such mailbox: %s" %
+ _unicode_as_str(name))
mbox = self.getMailbox(name)
@@ -279,14 +298,14 @@ class SoledadBackedAccount(WithMsgFields, IndexedDB, MBoxParser):
newname = self._parse_mailbox_name(newname)
if oldname not in self.mailboxes:
- raise imap4.NoSuchMailbox, oldname
+ raise imap4.NoSuchMailbox, _unicode_as_str(oldname)
inferiors = self._inferiorNames(oldname)
inferiors = [(o, o.replace(oldname, newname, 1)) for o in inferiors]
for (old, new) in inferiors:
if new in self.mailboxes:
- raise imap4.MailboxCollision, new
+ raise imap4.MailboxCollision, _unicode_as_str(new)
for (old, new) in inferiors:
mbox = self._get_mailbox_by_name(old)
@@ -367,7 +386,8 @@ class SoledadBackedAccount(WithMsgFields, IndexedDB, MBoxParser):
"""
name = self._parse_mailbox_name(name)
if name not in self.subscriptions:
- raise imap4.MailboxException, "Not currently subscribed to " + name
+ raise imap4.MailboxException, \
+ "Not currently subscribed to %s" % _unicode_as_str(name)
self._set_subscription(name, False)
def listMailboxes(self, ref, wildcard):
diff --git a/mail/src/leap/mail/imap/parser.py b/mail/src/leap/mail/imap/parser.py
index 306dcf0a..6a9ace99 100644
--- a/mail/src/leap/mail/imap/parser.py
+++ b/mail/src/leap/mail/imap/parser.py
@@ -102,6 +102,11 @@ class MBoxParser(object):
def _parse_mailbox_name(self, name):
"""
+ Return a normalized representation of the mailbox C{name}.
+
+ This method ensures that an eventual initial 'inbox' part of a
+ mailbox name is made uppercase.
+
:param name: the name of the mailbox
:type name: unicode