diff options
Diffstat (limited to 'src/leap')
-rw-r--r-- | src/leap/bitmask/bonafide/service.py | 3 | ||||
-rw-r--r-- | src/leap/bitmask/core/mail_services.py | 20 | ||||
-rw-r--r-- | src/leap/bitmask/core/service.py | 5 | ||||
-rw-r--r-- | src/leap/bitmask/mail/incoming/service.py | 21 |
4 files changed, 32 insertions, 17 deletions
diff --git a/src/leap/bitmask/bonafide/service.py b/src/leap/bitmask/bonafide/service.py index 797e6065..1f0d6362 100644 --- a/src/leap/bitmask/bonafide/service.py +++ b/src/leap/bitmask/bonafide/service.py @@ -98,6 +98,9 @@ class BonafideService(HookableService): self._active_user = None return passthrough + data = dict(username=username) + self.trigger_hook('on_bonafide_logout', **data) + d = self._bonafide.do_logout(username) d.addCallback(reset_active) d.addCallback(lambda response: {'logout': 'ok'}) diff --git a/src/leap/bitmask/core/mail_services.py b/src/leap/bitmask/core/mail_services.py index d2967f89..f971c1a2 100644 --- a/src/leap/bitmask/core/mail_services.py +++ b/src/leap/bitmask/core/mail_services.py @@ -435,8 +435,6 @@ class StandardMailService(service.MultiService, HookableService): # TODO factor out Mail Service to inside mail package. - subscribed_to_hooks = ('on_new_keymanager_instance',) - def __init__(self, basedir): self._basedir = basedir self._soledad_sessions = {} @@ -502,12 +500,22 @@ class StandardMailService(service.MultiService, HookableService): def hook_on_bonafide_auth(self, **kw): # TODO: if it's expired we should renew it userid = kw['username'] + + # turn on incoming mail service for the user that just logged in + multiservice = self.getServiceNamed('incoming_mail') + incoming = multiservice.getServiceNamed(userid) + log.msg('looking for incoming mail service for auth: %s' % userid) + if incoming: + incoming.startService() + + # check if smtp cert exists username, provider = userid.split('@') cert_path = _get_smtp_client_cert_path(self._basedir, provider, username) if os.path.exists(cert_path): return + # fetch smtp cert and store bonafide = self.parent.getServiceNamed("bonafide") _, cert_str = yield bonafide.do_get_smtp_cert(userid) @@ -518,6 +526,14 @@ class StandardMailService(service.MultiService, HookableService): outf.write(cert_str) check_and_fix_urw_only(cert_path) + def hook_on_bonafide_logout(self, **kw): + username = kw['username'] + multiservice = self.getServiceNamed('incoming_mail') + incoming = multiservice.getServiceNamed(username) + log.msg('looking for incoming mail service for logout: %s' % username) + if incoming: + incoming.stopService() + # commands def do_status(self): diff --git a/src/leap/bitmask/core/service.py b/src/leap/bitmask/core/service.py index de99ea55..1a544acf 100644 --- a/src/leap/bitmask/core/service.py +++ b/src/leap/bitmask/core/service.py @@ -89,6 +89,7 @@ class BitmaskBackend(configurable.ConfigurableService): bf.register_hook('on_passphrase_change', listener='soledad') bf.register_hook('on_bonafide_auth', listener='keymanager') bf.register_hook('on_bonafide_auth', listener='mail') + bf.register_hook('on_bonafide_logout', listener='mail') def _start_child_service(self, name): log.msg('starting backend child service: %s' % name) @@ -156,13 +157,13 @@ class BitmaskBackend(configurable.ConfigurableService): def _maybe_init_service(self, label, klass, *args, **kw): try: - self.getServiceNamed(label) + service = self.getServiceNamed(label) except KeyError: log.msg("initializing service: %s" % label) service = klass(*args, **kw) service.setName(label) service.setServiceParent(self) - return service + return service def do_stats(self): return self.core_commands.do_stats() diff --git a/src/leap/bitmask/mail/incoming/service.py b/src/leap/bitmask/mail/incoming/service.py index b4cdfcf3..86c3055c 100644 --- a/src/leap/bitmask/mail/incoming/service.py +++ b/src/leap/bitmask/mail/incoming/service.py @@ -31,7 +31,6 @@ from urlparse import urlparse from twisted.application.service import Service from twisted.application.service import IService from twisted.logger import Logger -from twisted.python.failure import Failure from twisted.internet import defer, reactor from twisted.internet.task import LoopingCall from twisted.internet.task import deferLater @@ -183,27 +182,23 @@ class IncomingMail(Service): def startService(self): """ - Starts a loop to fetch mail. - - :returns: A Deferred whose callback will be invoked with - the LoopingCall instance when loop.stop is called, or - whose errback will be invoked when the function raises an - exception or returned a deferred that has its errback - invoked. + Start a loop to fetch mail. """ + if self.running: + return + Service.startService(self) if self._loop is None: self._loop = LoopingCall(self.fetch) - stop_deferred = self._loop.start(self._check_period) - return stop_deferred - else: - logger.warning("Tried to start an already running fetching loop.") - return defer.fail(Failure('Already running loop.')) + self._loop.start(self._check_period) def stopService(self): """ Stops the loop that fetches mail. """ + if not self.running: + return + if self._loop and self._loop.running is True: self._loop.stop() self._loop = None |