diff options
author | Tomás Touceda <chiiph@leap.se> | 2013-08-16 15:20:12 -0300 |
---|---|---|
committer | Tomás Touceda <chiiph@leap.se> | 2013-08-16 15:20:12 -0300 |
commit | 5db4bbed6eb1cfe707dfb8cb92a978e4313607d0 (patch) | |
tree | fa45506bbc08166a85184e6fc7255c2d29acadde /src/leap/mail/imap/service | |
parent | 5ea655824e838aec0a103fbf6f7ff820027d36fe (diff) | |
parent | fd48fff2676cb063663532f240197e9626d64363 (diff) |
Merge remote-tracking branch 'kali/feature/add_imap_events' into develop
Diffstat (limited to 'src/leap/mail/imap/service')
-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 |