summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaio Carrara <ccarrara@thoughtworks.com>2016-04-13 16:12:09 -0300
committerKali Kaneko <kali@leap.se>2016-04-15 16:10:42 -0400
commitc5980d0be3732f30bcbcd6a7742ad56ee3d48cd7 (patch)
treea2deb62b8a591cc2b0bb9a37150fc70d0cef16bd
parent317cdf3e126fda6f4504ad8b18095f6f36266f9f (diff)
[bug] Adds user_id to Account
Previously Account used user id from the store, but this attribute is optional and None by default. This caused the collection_mapping to be unable to distinct between multiple users message collections. This chance adds a non optional user_id attribute to Account and use it to index the collection_mapping. - Resolves: https://github.com/pixelated/pixelated-user-agent/issues/674 - Releases: 0.4.0
-rw-r--r--mail/src/leap/mail/imap/account.py2
-rw-r--r--mail/src/leap/mail/mail.py7
-rw-r--r--mail/src/leap/mail/smtp/bounces.py3
-rw-r--r--mail/src/leap/mail/tests/test_mail.py14
4 files changed, 14 insertions, 12 deletions
diff --git a/mail/src/leap/mail/imap/account.py b/mail/src/leap/mail/imap/account.py
index 2f9ed1d..0b8e019 100644
--- a/mail/src/leap/mail/imap/account.py
+++ b/mail/src/leap/mail/imap/account.py
@@ -88,7 +88,7 @@ class IMAPAccount(object):
# about user_id, only the client backend.
self.user_id = user_id
- self.account = Account(store, ready_cb=lambda: d.callback(self))
+ self.account = Account(store, user_id, ready_cb=lambda: d.callback(self))
def end_session(self):
"""
diff --git a/mail/src/leap/mail/mail.py b/mail/src/leap/mail/mail.py
index c6e053c..d3659de 100644
--- a/mail/src/leap/mail/mail.py
+++ b/mail/src/leap/mail/mail.py
@@ -941,8 +941,9 @@ class Account(object):
# tree we can let it be an instance attribute.
_collection_mapping = defaultdict(weakref.WeakValueDictionary)
- def __init__(self, store, ready_cb=None):
+ def __init__(self, store, user_id, ready_cb=None):
self.store = store
+ self.user_id = user_id
self.adaptor = self.adaptor_class()
self.mbox_indexer = MailboxIndexer(self.store)
@@ -1077,7 +1078,7 @@ class Account(object):
:rtype: deferred
:return: a deferred that will fire with a MessageCollection
"""
- collection = self._collection_mapping[self.store.userid].get(
+ collection = self._collection_mapping[self.user_id].get(
name, None)
if collection:
return defer.succeed(collection)
@@ -1086,7 +1087,7 @@ class Account(object):
def get_collection_for_mailbox(mbox_wrapper):
collection = MessageCollection(
self.adaptor, self.store, self.mbox_indexer, mbox_wrapper)
- self._collection_mapping[self.store.userid][name] = collection
+ self._collection_mapping[self.user_id][name] = collection
return collection
d = self.adaptor.get_or_create_mbox(self.store, name)
diff --git a/mail/src/leap/mail/smtp/bounces.py b/mail/src/leap/mail/smtp/bounces.py
index 64f2dd7..7a4674b 100644
--- a/mail/src/leap/mail/smtp/bounces.py
+++ b/mail/src/leap/mail/smtp/bounces.py
@@ -83,7 +83,8 @@ class Bouncer(object):
def bouncerFactory(soledad):
- acc = Account(soledad)
+ user_id = soledad.uuid
+ acc = Account(soledad, user_id)
d = acc.callWhenReady(lambda _: acc.get_collection_by_mailbox(INBOX_NAME))
d.addCallback(lambda inbox: Bouncer(inbox))
return d
diff --git a/mail/src/leap/mail/tests/test_mail.py b/mail/src/leap/mail/tests/test_mail.py
index 9f40ffb..aca406f 100644
--- a/mail/src/leap/mail/tests/test_mail.py
+++ b/mail/src/leap/mail/tests/test_mail.py
@@ -317,12 +317,12 @@ class AccountTestCase(SoledadTestMixin):
"""
Tests for the Account class.
"""
- def get_account(self):
+ def get_account(self, user_id):
store = self._soledad
- return Account(store)
+ return Account(store, user_id)
def test_add_mailbox(self):
- acc = self.get_account()
+ acc = self.get_account('some_user_id')
d = acc.callWhenReady(lambda _: acc.add_mailbox("TestMailbox"))
d.addCallback(lambda _: acc.list_all_mailbox_names())
d.addCallback(self._test_add_mailbox_cb)
@@ -333,7 +333,7 @@ class AccountTestCase(SoledadTestMixin):
self.assertItemsEqual(mboxes, expected)
def test_delete_mailbox(self):
- acc = self.get_account()
+ acc = self.get_account('some_user_id')
d = acc.callWhenReady(lambda _: acc.delete_mailbox("Inbox"))
d.addCallback(lambda _: acc.list_all_mailbox_names())
d.addCallback(self._test_delete_mailbox_cb)
@@ -344,7 +344,7 @@ class AccountTestCase(SoledadTestMixin):
self.assertItemsEqual(mboxes, expected)
def test_rename_mailbox(self):
- acc = self.get_account()
+ acc = self.get_account('some_user_id')
d = acc.callWhenReady(lambda _: acc.add_mailbox("OriginalMailbox"))
d.addCallback(lambda _: acc.rename_mailbox(
"OriginalMailbox", "RenamedMailbox"))
@@ -357,7 +357,7 @@ class AccountTestCase(SoledadTestMixin):
self.assertItemsEqual(mboxes, expected)
def test_get_all_mailboxes(self):
- acc = self.get_account()
+ acc = self.get_account('some_user_id')
d = acc.callWhenReady(lambda _: acc.add_mailbox("OneMailbox"))
d.addCallback(lambda _: acc.add_mailbox("TwoMailbox"))
d.addCallback(lambda _: acc.add_mailbox("ThreeMailbox"))
@@ -374,7 +374,7 @@ class AccountTestCase(SoledadTestMixin):
self.assertItemsEqual(names, expected)
def test_get_collection_by_mailbox(self):
- acc = self.get_account()
+ acc = self.get_account('some_user_id')
d = acc.callWhenReady(lambda _: acc.get_collection_by_mailbox("INBOX"))
d.addCallback(self._test_get_collection_by_mailbox_cb)
return d