diff options
-rw-r--r-- | service/pixelated/bitmask_libraries/session.py | 16 | ||||
-rw-r--r-- | service/pixelated/config/leap.py | 2 | ||||
-rw-r--r-- | service/test/unit/bitmask_libraries/test_session.py | 2 |
3 files changed, 11 insertions, 9 deletions
diff --git a/service/pixelated/bitmask_libraries/session.py b/service/pixelated/bitmask_libraries/session.py index ca3c80ff..7abe2a63 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, smtp): + def __init__(self, provider, user_auth, mail_store, soledad_session, nicknym, smtp): self.smtp = smtp self.config = provider.config self.provider = provider @@ -63,15 +63,17 @@ class LeapSession(object): self.mail_store = mail_store self.soledad_session = soledad_session self.nicknym = nicknym - self.account = soledad_account @defer.inlineCallbacks def initial_sync(self): yield self.sync() yield self.after_first_sync() + defer.returnValue(self) + @defer.inlineCallbacks def after_first_sync(self): yield self.nicknym.generate_openpgp_key() + self.account = self._create_account(self.account_email, self.soledad_session) self.incoming_mail_fetcher = yield self._create_incoming_mail_fetcher( self.nicknym, self.soledad_session, @@ -79,6 +81,10 @@ class LeapSession(object): self.account_email()) reactor.callFromThread(self.incoming_mail_fetcher.startService) + def _create_account(self, user_mail, soledad_session): + account = IMAPAccount(user_mail, soledad_session.soledad) + return account + def account_email(self): name = self.user_auth.username return self.provider.address_for(name) @@ -131,11 +137,10 @@ class LeapSessionFactory(object): mail_store = LeapMailStore(soledad.soledad) nicknym = self._create_nicknym(account_email, auth.token, auth.uuid, soledad) - account = self._create_account(account_email, soledad) smtp = LeapSmtp(self._provider, auth, nicknym.keymanager) - return LeapSession(self._provider, auth, mail_store, soledad, nicknym, account, smtp) + return LeapSession(self._provider, auth, mail_store, soledad, nicknym, smtp) def _lookup_session(self, key): global SESSIONS @@ -163,8 +168,5 @@ class LeapSessionFactory(object): def _create_nicknym(self, email_address, token, uuid, soledad_session): return NickNym(self._provider, self._config, soledad_session, email_address, token, uuid) - def _create_account(self, user_mail, soledad_session): - account = IMAPAccount(user_mail, soledad_session.soledad) - return account # memstore = MemoryStore(permanent_store=SoledadStore(soledad_session.soledad)) # return SoledadBackedAccount(uuid, soledad_session.soledad, memstore) diff --git a/service/pixelated/config/leap.py b/service/pixelated/config/leap.py index f96710d4..c1280756 100644 --- a/service/pixelated/config/leap.py +++ b/service/pixelated/config/leap.py @@ -24,7 +24,7 @@ def initialize_leap(leap_provider_cert, LeapCertificate(provider).setup_ca_bundle() leap_session = LeapSessionFactory(provider).create(username, password) - yield leap_session.initial_sync() + leap_session = yield leap_session.initial_sync() defer.returnValue(leap_session) diff --git a/service/test/unit/bitmask_libraries/test_session.py b/service/test/unit/bitmask_libraries/test_session.py index e4dddf68..e20f96f9 100644 --- a/service/test/unit/bitmask_libraries/test_session.py +++ b/service/test/unit/bitmask_libraries/test_session.py @@ -50,7 +50,7 @@ class SessionTest(AbstractLeapTest): self.soledad_session.sync.assert_called_once_with() def _create_session(self): - return LeapSession(self.provider, self.auth, self.mail_store, self.soledad_session, self.nicknym, self.soledad_account, self.smtp_mock) + return LeapSession(self.provider, self.auth, self.mail_store, self.soledad_session, self.nicknym, self.smtp_mock) def _execute_func(func): |