summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKali Kaneko (leap communications) <kali@leap.se>2016-10-07 13:01:11 -0400
committerKali Kaneko (leap communications) <kali@leap.se>2016-10-07 14:00:16 -0400
commitb5d2c2cc4af0919eccfb5489280972fb0a6efa37 (patch)
tree72caa3a7ac7665530f14a10ab9ec64f2f814012d
parent750549f3707a8a27b4cbeaaa110811606bb3b46e (diff)
[bug] fail gracefully in mail service if instance not found
also, small refactor to make the function clearer.
-rw-r--r--src/leap/bitmask/core/mail_services.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/leap/bitmask/core/mail_services.py b/src/leap/bitmask/core/mail_services.py
index a82659a..14f6e0f 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)