From b5d2c2cc4af0919eccfb5489280972fb0a6efa37 Mon Sep 17 00:00:00 2001 From: "Kali Kaneko (leap communications)" Date: Fri, 7 Oct 2016 13:01:11 -0400 Subject: [bug] fail gracefully in mail service if instance not found also, small refactor to make the function clearer. --- src/leap/bitmask/core/mail_services.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/leap') diff --git a/src/leap/bitmask/core/mail_services.py b/src/leap/bitmask/core/mail_services.py index a82659a9..14f6e0f2 100644 --- a/src/leap/bitmask/core/mail_services.py +++ b/src/leap/bitmask/core/mail_services.py @@ -509,19 +509,30 @@ class StandardMailService(service.MultiService, HookableService): # TODO: if it's expired we should renew it userid = kw['username'] - # turn on incoming mail service for the user that just logged in + self._maybe_start_incoming_service(userid) + yield self._maybe_fetch_smtp_certificate(userid) + + def _maybe_start_incoming_service(self, userid): + """ + try to turn on incoming mail service for the user that just logged in + """ + logger.debug( + 'looking for incoming mail service for auth: %s' % userid) multiservice = self.getServiceNamed('incoming_mail') - incoming = multiservice.getServiceNamed(userid) - logger.debug('looking for incoming mail service for auth: %s' % userid) - if incoming: + try: + incoming = multiservice.getServiceNamed(userid) incoming.startService() + except KeyError: + logger.debug('no incoming service for %s' % userid) + @defer.inlineCallbacks + def _maybe_fetch_smtp_certificate(self, userid): # 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 + defer.returnValue(None) # fetch smtp cert and store bonafide = self.parent.getServiceNamed("bonafide") @@ -683,6 +694,7 @@ class IncomingMailService(service.MultiService): keymanager, soledad, inbox, userid, check_period=INCOMING_CHECK_PERIOD) + logger.debug('setting incoming mail service for %s' % userid) incoming_mail.setName(userid) self.addService(incoming_mail) -- cgit v1.2.3