diff options
6 files changed, 24 insertions, 25 deletions
diff --git a/service/pixelated/adapter/listeners/mailbox_indexer_listener.py b/service/pixelated/adapter/listeners/mailbox_indexer_listener.py index 74b4f5af..97a887f4 100644 --- a/service/pixelated/adapter/listeners/mailbox_indexer_listener.py +++ b/service/pixelated/adapter/listeners/mailbox_indexer_listener.py @@ -27,9 +27,8 @@ class MailboxIndexerListener(object): @defer.inlineCallbacks def listen(cls, account, mailbox_name, mail_store, search_engine): listener = MailboxIndexerListener(mailbox_name, mail_store, search_engine) - if listener not in (yield account.getMailbox(mailbox_name)).listeners: - mbx = yield account.getMailbox(mailbox_name) - mbx.addListener(listener) + mail_collection = yield account.get_collection_by_mailbox(mailbox_name) + mail_collection.addListener(listener) defer.returnValue(listener) @@ -39,7 +38,7 @@ class MailboxIndexerListener(object): self.search_engine = search_engine @defer.inlineCallbacks - def newMessages(self, exists, recent): + def notify_new(self): try: indexed_idents = set(self.search_engine.search('tag:' + self.mailbox_name.lower(), all_mails=True)) soledad_idents = yield self.mail_store.get_mailbox_mail_ids(self.mailbox_name) @@ -63,6 +62,6 @@ class MailboxIndexerListener(object): @defer.inlineCallbacks def listen_all_mailboxes(account, search_engine, mail_store): - mailboxes = yield account.account.list_all_mailbox_names() + mailboxes = yield account.list_all_mailbox_names() for mailbox_name in mailboxes: yield MailboxIndexerListener.listen(account, mailbox_name, mail_store, search_engine) diff --git a/service/pixelated/bitmask_libraries/session.py b/service/pixelated/bitmask_libraries/session.py index ae3eb992..d575a9c6 100644 --- a/service/pixelated/bitmask_libraries/session.py +++ b/service/pixelated/bitmask_libraries/session.py @@ -24,7 +24,7 @@ from twisted.internet import reactor, defer from pixelated.bitmask_libraries.certs import LeapCertificate from pixelated.adapter.mailstore import LeapMailStore from leap.mail.incoming.service import IncomingMail -from leap.mail.imap.account import IMAPAccount +from leap.mail.mail import Account from leap.auth import SRPAuth from .nicknym import NickNym from .smtp import LeapSMTPConfig @@ -73,7 +73,7 @@ class LeapSession(object): @defer.inlineCallbacks def after_first_sync(self): yield self.nicknym.generate_openpgp_key() - self.account = self._create_account(self.account_email, self.soledad) + yield self._create_account(self.soledad) self.incoming_mail_fetcher = yield self._create_incoming_mail_fetcher( self.nicknym, self.soledad, @@ -81,8 +81,9 @@ class LeapSession(object): self.account_email()) reactor.callFromThread(self.incoming_mail_fetcher.startService) - def _create_account(self, user_mail, soledad): - return IMAPAccount(user_mail, soledad, defer.Deferred()) + def _create_account(self, soledad): + self.account = Account(soledad) + return self.account.deferred_initialization def _set_fresh_account(self, event, email_address): log.debug('Key for email %s has been generated' % email_address) @@ -115,10 +116,10 @@ class LeapSession(object): @defer.inlineCallbacks def _create_incoming_mail_fetcher(self, nicknym, soledad, account, user_mail): - inbox = yield account.callWhenReady(lambda _: account.getMailbox('INBOX')) + inbox = yield account.callWhenReady(lambda _: account.get_collection_by_mailbox('INBOX')) defer.returnValue(IncomingMail(nicknym.keymanager, soledad, - inbox.collection, + inbox, user_mail)) def stop_background_jobs(self): diff --git a/service/test/integration/test_incoming_mail.py b/service/test/integration/test_incoming_mail.py index 682ca118..e413d6c1 100644 --- a/service/test/integration/test_incoming_mail.py +++ b/service/test/integration/test_incoming_mail.py @@ -25,12 +25,12 @@ class IncomingMailTest(SoledadTestBase): @defer.inlineCallbacks def test_message_collection(self): # given - mbx = yield self.account.getMailbox('INBOX') + mail_collection = yield self.account.get_collection_by_mailbox('INBOX') input_mail = MailBuilder().build_input_mail() # when yield MailboxIndexerListener.listen(self.account, 'INBOX', self.mail_store, self.search_engine) - yield mbx.addMessage(input_mail.raw, [], notify_just_mdoc=False) + yield mail_collection.add_msg(input_mail.raw) # then yield self.wait_in_reactor() # event handlers are called async, wait for it diff --git a/service/test/support/integration/app_test_client.py b/service/test/support/integration/app_test_client.py index f3ec5d25..95facec0 100644 --- a/service/test/support/integration/app_test_client.py +++ b/service/test/support/integration/app_test_client.py @@ -25,7 +25,7 @@ import uuid import random -from leap.mail.imap.account import IMAPAccount +from leap.mail.mail import Account from leap.soledad.client import Soledad from mock import Mock from twisted.internet import reactor, defer @@ -77,7 +77,7 @@ class AppTestAccount(object): self.mail_store = SearchableMailStore(LeapMailStore(self.soledad), self.search_engine) self.attachment_store = LeapAttachmentStore(self.soledad) - yield self._initialize_imap_account() + yield self._initialize_account() self.draft_service = DraftService(self.mail_store) self.leap_session = mock() @@ -110,10 +110,9 @@ class AppTestAccount(object): soledad_test_folder = os.path.join(self._leap_home, self._uuid) shutil.rmtree(soledad_test_folder) - def _initialize_imap_account(self): - account_ready_cb = defer.Deferred() - self.account = IMAPAccount(self._user_id, self.soledad, account_ready_cb) - return account_ready_cb + def _initialize_account(self): + self.account = Account(self.soledad) + return self.account.deferred_initialization def _create_mail_service(self, mail_sender, mail_store, search_engine, attachment_store): return MailService(mail_sender, mail_store, search_engine, self._mail_address, attachment_store) diff --git a/service/test/unit/adapter/test_mailbox_indexer_listener.py b/service/test/unit/adapter/test_mailbox_indexer_listener.py index c88ba035..c101aa1a 100644 --- a/service/test/unit/adapter/test_mailbox_indexer_listener.py +++ b/service/test/unit/adapter/test_mailbox_indexer_listener.py @@ -31,7 +31,7 @@ class MailboxListenerTest(unittest.TestCase): def test_add_itself_to_mailbox_listeners(self): self.account.mailboxes = ['INBOX'] mailbox = mock() - when(self.account).getMailbox('INBOX').thenReturn(mailbox) + when(self.account).get_collection_by_mailbox('INBOX').thenReturn(mailbox) mailbox.listeners = set() when(mailbox).addListener = lambda x: mailbox.listeners.add(x) @@ -49,7 +49,7 @@ class MailboxListenerTest(unittest.TestCase): listener = MailboxIndexerListener('INBOX', self.mail_store, search_engine) when(self.mail_store).get_mailbox_mail_ids('INBOX').thenReturn({'ident1', 'ident2', 'missing_ident'}) when(self.mail_store).get_mails({'missing_ident'}, include_body=True).thenReturn([mail]) - listener.newMessages(10, 5) + listener.notify_new() verify(self.mail_store, times=1).get_mails({'missing_ident'}, include_body=True) verify(search_engine).index_mails([mail]) @@ -59,6 +59,6 @@ class MailboxListenerTest(unittest.TestCase): when(logger).error(ANY()).thenReturn(None) listener = MailboxIndexerListener('INBOX', self.mail_store, mock()) - yield listener.newMessages(1, 1) + yield listener.notify_new() verify(logger).error(ANY()) diff --git a/service/test/unit/bitmask_libraries/test_session.py b/service/test/unit/bitmask_libraries/test_session.py index aad2cac2..84f9f023 100644 --- a/service/test/unit/bitmask_libraries/test_session.py +++ b/service/test/unit/bitmask_libraries/test_session.py @@ -29,7 +29,7 @@ class SessionTest(AbstractLeapTest): self.smtp_mock = MagicMock() @patch('pixelated.bitmask_libraries.session.register') - @patch('pixelated.bitmask_libraries.session.IMAPAccount') + @patch('pixelated.bitmask_libraries.session.Account') @defer.inlineCallbacks def test_background_jobs_are_started_during_initial_sync(self, *unused): mailFetcherMock = MagicMock() @@ -41,7 +41,7 @@ class SessionTest(AbstractLeapTest): @patch('pixelated.bitmask_libraries.session.register') @patch('pixelated.bitmask_libraries.session.unregister') - @patch('pixelated.bitmask_libraries.session.IMAPAccount') + @patch('pixelated.bitmask_libraries.session.Account') @defer.inlineCallbacks def test_that_close_stops_background_jobs(self, *unused): with patch('pixelated.bitmask_libraries.session.reactor.callFromThread', new=_execute_func) as _: @@ -153,7 +153,7 @@ class SessionTest(AbstractLeapTest): @patch('pixelated.bitmask_libraries.session.register') @patch('pixelated.bitmask_libraries.session.unregister') - @patch('pixelated.bitmask_libraries.session.IMAPAccount') + @patch('pixelated.bitmask_libraries.session.Account') @defer.inlineCallbacks def test_session_initial_sync_only_triggered_once(self, *unused): mailFetcherMock = MagicMock() |