summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/mail
diff options
context:
space:
mode:
authordrebs <drebs@riseup.net>2016-09-27 20:44:53 -0300
committerdrebs <drebs@riseup.net>2016-09-30 13:10:14 -0300
commit9c4bf6adf42f0f9553ae11f24ffeb6f7cf39f374 (patch)
treec03b13ae17c0e6267ba8f3ba47c470aed7ad24d4 /src/leap/bitmask/mail
parent10f35cacf50148c34b11fba719fc8f734f99def1 (diff)
[refactor] turn mail services into twisted services
Diffstat (limited to 'src/leap/bitmask/mail')
-rw-r--r--src/leap/bitmask/mail/imap/service/imap.py5
-rw-r--r--src/leap/bitmask/mail/incoming/service.py10
-rw-r--r--src/leap/bitmask/mail/smtp/__init__.py9
3 files changed, 15 insertions, 9 deletions
diff --git a/src/leap/bitmask/mail/imap/service/imap.py b/src/leap/bitmask/mail/imap/service/imap.py
index aac49b63..9ccff4ab 100644
--- a/src/leap/bitmask/mail/imap/service/imap.py
+++ b/src/leap/bitmask/mail/imap/service/imap.py
@@ -158,7 +158,7 @@ class LeapIMAPFactory(ServerFactory):
return ServerFactory.doStop(self)
-def run_service(soledad_sessions, port=IMAP_PORT):
+def run_service(soledad_sessions, port=IMAP_PORT, factory=None):
"""
Main entry point to run the service from the client.
@@ -169,7 +169,8 @@ def run_service(soledad_sessions, port=IMAP_PORT):
the factory for the protocol.
:rtype: tuple
"""
- factory = LeapIMAPFactory(soledad_sessions)
+ if not factory:
+ factory = LeapIMAPFactory(soledad_sessions)
try:
interface = "localhost"
diff --git a/src/leap/bitmask/mail/incoming/service.py b/src/leap/bitmask/mail/incoming/service.py
index 05f9bb51..b4cdfcf3 100644
--- a/src/leap/bitmask/mail/incoming/service.py
+++ b/src/leap/bitmask/mail/incoming/service.py
@@ -29,12 +29,15 @@ from StringIO import StringIO
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
+from zope.interface import implements
+
from leap.common.events import emit_async, catalog
from leap.common.check import leap_assert, leap_assert_type
from leap.common.mail import get_email_charset
@@ -47,7 +50,7 @@ from leap.soledad.common.crypto import ENC_SCHEME_KEY, ENC_JSON_KEY
from leap.soledad.common.errors import InvalidAuthTokenError
-logger = Logger()
+logger = Logger(__name__)
MULTIPART_ENCRYPTED = "multipart/encrypted"
MULTIPART_SIGNED = "multipart/signed"
@@ -79,7 +82,8 @@ class IncomingMail(Service):
This loop will sync the soledad db with the remote server and
process all the documents found tagged as incoming mail.
"""
- # TODO implements IService?
+
+ implements(IService)
name = "IncomingMail"
@@ -227,7 +231,7 @@ class IncomingMail(Service):
def _signal_invalid_auth(failure):
failure.trap(InvalidAuthTokenError)
- logger.info('sync failed: %r' % failure)
+ logger.warn('sync failed because token has expired: %r' % failure)
# if the token is invalid, send an event so the GUI can
# disable mail and show an error message.
emit_async(catalog.SOLEDAD_INVALID_AUTH_TOKEN, self._userid)
diff --git a/src/leap/bitmask/mail/smtp/__init__.py b/src/leap/bitmask/mail/smtp/__init__.py
index 4e0ac894..f8b8e65f 100644
--- a/src/leap/bitmask/mail/smtp/__init__.py
+++ b/src/leap/bitmask/mail/smtp/__init__.py
@@ -32,7 +32,7 @@ SMTP_PORT = 2013
def run_service(soledad_sessions, keymanager_sessions, sendmail_opts,
- port=SMTP_PORT):
+ port=SMTP_PORT, factory=None):
"""
Main entry point to run the service from the client.
@@ -46,8 +46,9 @@ def run_service(soledad_sessions, keymanager_sessions, sendmail_opts,
the factory for the protocol.
:rtype: tuple
"""
- factory = SMTPFactory(soledad_sessions, keymanager_sessions,
- sendmail_opts)
+ if not factory:
+ factory = SMTPFactory(soledad_sessions, keymanager_sessions,
+ sendmail_opts)
try:
interface = "localhost"
@@ -60,7 +61,7 @@ def run_service(soledad_sessions, keymanager_sessions, sendmail_opts,
tport = reactor.listenTCP(port, factory, interface=interface)
emit_async(catalog.SMTP_SERVICE_STARTED, str(port))
- return factory, tport
+ return tport, factory
except CannotListenError:
logger.error("SMTP Service failed to start: "
"cannot listen in port %s" % port)