From 7729355e679bb8f7e2cef2caf6219664a333006f Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Tue, 26 Aug 2014 17:42:39 -0500 Subject: fix and migrate tests to trial We cannot use setUpClass when running tests with trial. But, after all, it's not *so* expensive to initialize a new soledad instance (since we'll be mostly using the memstore for the tests). --- src/leap/mail/imap/account.py | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'src/leap/mail/imap/account.py') diff --git a/src/leap/mail/imap/account.py b/src/leap/mail/imap/account.py index 199a2a4..74ec11e 100644 --- a/src/leap/mail/imap/account.py +++ b/src/leap/mail/imap/account.py @@ -129,8 +129,9 @@ class SoledadBackedAccount(WithMsgFields, IndexedDB, MBoxParser): def mailboxes(self): """ A list of the current mailboxes for this account. + :rtype: set """ - return self.__mailboxes + return sorted(self.__mailboxes) def _load_mailboxes(self): self.__mailboxes.update( @@ -149,7 +150,7 @@ class SoledadBackedAccount(WithMsgFields, IndexedDB, MBoxParser): def getMailbox(self, name): """ - Returns a Mailbox with that name, without selecting it. + Return a Mailbox with that name, without selecting it. :param name: name of the mailbox :type name: str @@ -165,9 +166,9 @@ class SoledadBackedAccount(WithMsgFields, IndexedDB, MBoxParser): return SoledadMailbox(name, self._soledad, memstore=self._memstore) - ## - ## IAccount - ## + # + # IAccount + # def addMailbox(self, name, creation_ts=None): """ @@ -189,7 +190,7 @@ class SoledadBackedAccount(WithMsgFields, IndexedDB, MBoxParser): if name in self.mailboxes: raise imap4.MailboxCollision(repr(name)) - if not creation_ts: + if creation_ts is None: # by default, we pass an int value # taken from the current time # we make sure to take enough decimals to get a unique @@ -278,15 +279,15 @@ class SoledadBackedAccount(WithMsgFields, IndexedDB, MBoxParser): """ name = self._parse_mailbox_name(name) - if not name in self.mailboxes: + if name not in self.mailboxes: raise imap4.MailboxException("No such mailbox: %r" % name) - mbox = self.getMailbox(name) if force is False: # See if this box is flagged \Noselect # XXX use mbox.flags instead? - if self.NOSELECT_FLAG in mbox.getFlags(): + mbox_flags = mbox.getFlags() + if self.NOSELECT_FLAG in mbox_flags: # Check for hierarchically inferior mailboxes with this one # as part of their root. for others in self.mailboxes: @@ -294,16 +295,16 @@ class SoledadBackedAccount(WithMsgFields, IndexedDB, MBoxParser): raise imap4.MailboxException, ( "Hierarchically inferior mailboxes " "exist and \\Noselect is set") + self.__mailboxes.discard(name) mbox.destroy() - self._load_mailboxes() # XXX FIXME --- not honoring the inferior names... # if there are no hierarchically inferior names, we will # delete it from our ken. - #if self._inferiorNames(name) > 1: - # ??! -- can this be rite? - #self._index.removeMailbox(name) + # if self._inferiorNames(name) > 1: + # ??! -- can this be rite? + # self._index.removeMailbox(name) def rename(self, oldname, newname): """ @@ -332,6 +333,7 @@ class SoledadBackedAccount(WithMsgFields, IndexedDB, MBoxParser): self._memstore.rename_fdocs_mailbox(old, new) mbox = self._get_mailbox_by_name(old) mbox.content[self.MBOX_KEY] = new + self.__mailboxes.discard(old) self._soledad.put_doc(mbox) self._load_mailboxes() @@ -374,7 +376,7 @@ class SoledadBackedAccount(WithMsgFields, IndexedDB, MBoxParser): """ # maybe we should store subscriptions in another # document... - if not name in self.mailboxes: + if name not in self.mailboxes: self.addMailbox(name) mbox = self._get_mailbox_by_name(name) @@ -428,9 +430,9 @@ class SoledadBackedAccount(WithMsgFields, IndexedDB, MBoxParser): wildcard = imap4.wildcardToRegexp(wildcard, '/') return [(i, self.getMailbox(i)) for i in ref if wildcard.match(i)] - ## - ## INamespacePresenter - ## + # + # INamespacePresenter + # def getPersonalNamespaces(self): return [["", "/"]] -- cgit v1.2.3 From b52104f908d668aec39e563923c7f04c05e5f221 Mon Sep 17 00:00:00 2001 From: Duda Dornelles Date: Tue, 9 Sep 2014 15:07:41 -0300 Subject: addMailbox shouldn't accept empty names since it makes it impossible to retrieve it later --- src/leap/mail/imap/account.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/leap/mail/imap/account.py') diff --git a/src/leap/mail/imap/account.py b/src/leap/mail/imap/account.py index 74ec11e..70ed13b 100644 --- a/src/leap/mail/imap/account.py +++ b/src/leap/mail/imap/account.py @@ -187,6 +187,8 @@ class SoledadBackedAccount(WithMsgFields, IndexedDB, MBoxParser): """ name = self._parse_mailbox_name(name) + leap_assert(name, "Need a mailbox name to create a mailbox") + if name in self.mailboxes: raise imap4.MailboxCollision(repr(name)) -- cgit v1.2.3