diff options
author | Bruno Wagner <bwagner@riseup.net> | 2015-09-16 15:59:13 -0300 |
---|---|---|
committer | Bruno Wagner <bwagner@riseup.net> | 2015-09-16 16:04:58 -0300 |
commit | 3f150ba7c119ad6f7a52d05915966ac1f78a6f0b (patch) | |
tree | a0faa23fe355fac2bb7e793ab60a71fc91a78f2a /service/pixelated/bitmask_libraries | |
parent | ab4387345975cde8681c6af4ee92a10dc7e3be8e (diff) |
Fixed duplicate document error on reruns #458
Setting up the incoming mail fetcher checked for an INBOX
before the first sync, that created an INBOX on every new
machine and when you removed the leap folder.
We moved that right after the initial sync, along the
generation of the OpenPGP keys and adapted the tests
Diffstat (limited to 'service/pixelated/bitmask_libraries')
-rw-r--r-- | service/pixelated/bitmask_libraries/session.py | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/service/pixelated/bitmask_libraries/session.py b/service/pixelated/bitmask_libraries/session.py index 2098c9ce..ca3c80ff 100644 --- a/service/pixelated/bitmask_libraries/session.py +++ b/service/pixelated/bitmask_libraries/session.py @@ -55,7 +55,7 @@ class LeapSession(object): - ``incoming_mail_fetcher`` Background job for fetching incoming mails from LEAP server (LeapIncomingMail) """ - def __init__(self, provider, user_auth, mail_store, soledad_session, nicknym, soledad_account, incoming_mail_fetcher, smtp): + def __init__(self, provider, user_auth, mail_store, soledad_session, nicknym, soledad_account, smtp): self.smtp = smtp self.config = provider.config self.provider = provider @@ -64,27 +64,35 @@ class LeapSession(object): self.soledad_session = soledad_session self.nicknym = nicknym self.account = soledad_account - self.incoming_mail_fetcher = incoming_mail_fetcher @defer.inlineCallbacks def initial_sync(self): yield self.sync() + yield self.after_first_sync() + + def after_first_sync(self): yield self.nicknym.generate_openpgp_key() - yield self.start_background_jobs() - defer.returnValue(self) + self.incoming_mail_fetcher = yield self._create_incoming_mail_fetcher( + self.nicknym, + self.soledad_session, + self.account, + self.account_email()) + reactor.callFromThread(self.incoming_mail_fetcher.startService) def account_email(self): name = self.user_auth.username return self.provider.address_for(name) def close(self): - self.stop_background_jobs() + self.stop_background_jobs @defer.inlineCallbacks - def start_background_jobs(self): - self.incoming_mail_fetcher = yield self.incoming_mail_fetcher - - reactor.callFromThread(self.incoming_mail_fetcher.startService) + def _create_incoming_mail_fetcher(self, nicknym, soledad_session, account, user_mail): + inbox = yield account.callWhenReady(lambda _: account.getMailbox('INBOX')) + defer.returnValue(IncomingMail(nicknym.keymanager, + soledad_session.soledad, + inbox.collection, + user_mail)) def stop_background_jobs(self): reactor.callFromThread(self.incoming_mail_fetcher.stopService) @@ -124,11 +132,10 @@ class LeapSessionFactory(object): nicknym = self._create_nicknym(account_email, auth.token, auth.uuid, soledad) account = self._create_account(account_email, soledad) - deferred_incoming_mail_fetcher = self._create_incoming_mail_fetcher(nicknym, soledad, account, account_email) smtp = LeapSmtp(self._provider, auth, nicknym.keymanager) - return LeapSession(self._provider, auth, mail_store, soledad, nicknym, account, deferred_incoming_mail_fetcher, smtp) + return LeapSession(self._provider, auth, mail_store, soledad, nicknym, account, smtp) def _lookup_session(self, key): global SESSIONS @@ -161,11 +168,3 @@ class LeapSessionFactory(object): return account # memstore = MemoryStore(permanent_store=SoledadStore(soledad_session.soledad)) # return SoledadBackedAccount(uuid, soledad_session.soledad, memstore) - - @defer.inlineCallbacks - def _create_incoming_mail_fetcher(self, nicknym, soledad_session, account, user_mail): - inbox = yield account.callWhenReady(lambda _: account.getMailbox('INBOX')) - defer.returnValue(IncomingMail(nicknym.keymanager, - soledad_session.soledad, - inbox.collection, - user_mail)) |