diff options
author | Kali Kaneko <kali@leap.se> | 2013-08-20 17:44:26 +0200 |
---|---|---|
committer | Kali Kaneko <kali@leap.se> | 2013-08-20 17:44:26 +0200 |
commit | eb5e965274aa5a7b84821f45d7bfeca318f994f6 (patch) | |
tree | 318c2871cd2c2aaa08f7dfff0cefcc262f80bb59 /src/leap/mail/imap/service/imap.py | |
parent | 75141e7504498b8092d1e860c8cd8879cc539fbb (diff) | |
parent | 5db4bbed6eb1cfe707dfb8cb92a978e4313607d0 (diff) |
Merge branch 'develop' of ssh://leap.se/leap_mail into develop
Diffstat (limited to 'src/leap/mail/imap/service/imap.py')
-rw-r--r-- | src/leap/mail/imap/service/imap.py | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/src/leap/mail/imap/service/imap.py b/src/leap/mail/imap/service/imap.py index 1a8c15c..380324c 100644 --- a/src/leap/mail/imap/service/imap.py +++ b/src/leap/mail/imap/service/imap.py @@ -27,6 +27,7 @@ from twisted.internet.protocol import ServerFactory from twisted.mail import imap4 from twisted.python import log +from leap.common import events as leap_events from leap.common.check import leap_assert, leap_assert_type from leap.keymanager import KeyManager from leap.mail.imap.server import SoledadBackedAccount @@ -42,6 +43,10 @@ INCOMING_CHECK_PERIOD = 5 # The period between succesive checks of the incoming mail # queue (in seconds) +from leap.common.events.events_pb2 import IMAP_SERVICE_STARTED +from leap.common.events.events_pb2 import IMAP_SERVICE_FAILED_TO_START +from leap.common.events.events_pb2 import IMAP_CLIENT_LOGIN + class LeapIMAPServer(imap4.IMAP4Server): """ @@ -84,6 +89,7 @@ class LeapIMAPServer(imap4.IMAP4Server): def authenticateLogin(self, username, password): # all is allowed so far. use realm instead + leap_events.signal(IMAP_CLIENT_LOGIN, True) return imap4.IAccount, self.theAccount, lambda: None @@ -150,15 +156,21 @@ def run_service(*args, **kwargs): factory = LeapIMAPFactory(uuid, soledad) from twisted.internet import reactor - reactor.listenTCP(port, factory) - - fetcher = LeapIncomingMail( - keymanager, - soledad, - factory.theAccount, - check_period) - - fetcher.start_loop() - logger.debug("IMAP4 Server is RUNNING in port %s" % (port,)) - return fetcher + try: + reactor.listenTCP(port, factory) + fetcher = LeapIncomingMail( + keymanager, + soledad, + factory.theAccount, + check_period) + except Exception as exc: + # XXX cannot listen? + logger.error("Error launching IMAP service: %r" % (exc,)) + leap_events.signal(IMAP_SERVICE_FAILED_TO_START, str(port)) + return + else: + fetcher.start_loop() + logger.debug("IMAP4 Server is RUNNING in port %s" % (port,)) + leap_events.signal(IMAP_SERVICE_STARTED, str(port)) + return fetcher |