summaryrefslogtreecommitdiff
path: root/mail/src
diff options
context:
space:
mode:
authorIvan Alejandro <ivanalejandro0@gmail.com>2015-05-11 18:04:29 -0300
committerIvan Alejandro <ivanalejandro0@gmail.com>2015-05-14 12:41:48 -0300
commitbaaae108dd9d0dbcdfe49da5690f49d40f5ce0a9 (patch)
tree374ab75fcb424429c8e1e7a557e55da15e5bd121 /mail/src
parentc42e54cc707a16e4c5bde75928b1ef50593f8df8 (diff)
[feat] adapt to new events api on common
- Related: #6359
Diffstat (limited to 'mail/src')
-rw-r--r--mail/src/leap/mail/imap/server.py5
-rw-r--r--mail/src/leap/mail/imap/service/imap.py8
-rw-r--r--mail/src/leap/mail/incoming/service.py29
-rw-r--r--mail/src/leap/mail/mail.py5
-rw-r--r--mail/src/leap/mail/outgoing/service.py16
-rw-r--r--mail/src/leap/mail/smtp/__init__.py6
-rw-r--r--mail/src/leap/mail/smtp/gateway.py12
7 files changed, 35 insertions, 46 deletions
diff --git a/mail/src/leap/mail/imap/server.py b/mail/src/leap/mail/imap/server.py
index 45da5359..2b670c11 100644
--- a/mail/src/leap/mail/imap/server.py
+++ b/mail/src/leap/mail/imap/server.py
@@ -26,9 +26,8 @@ from twisted.internet.defer import maybeDeferred
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.common.events.events_pb2 import IMAP_CLIENT_LOGIN
+from leap.common.events import emit, catalog
from leap.soledad.client import Soledad
# imports for LITERAL+ patch
@@ -222,7 +221,7 @@ class LEAPIMAPServer(imap4.IMAP4Server):
# bad username, reject.
raise cred.error.UnauthorizedLogin()
# any dummy password is allowed so far. use realm instead!
- leap_events.signal(IMAP_CLIENT_LOGIN, "1")
+ emit(catalog.IMAP_CLIENT_LOGIN, "1")
return imap4.IAccount, self.theAccount, lambda: None
def do_FETCH(self, tag, messages, query, uid=0):
diff --git a/mail/src/leap/mail/imap/service/imap.py b/mail/src/leap/mail/imap/service/imap.py
index b3282d4f..370c5132 100644
--- a/mail/src/leap/mail/imap/service/imap.py
+++ b/mail/src/leap/mail/imap/service/imap.py
@@ -31,14 +31,12 @@ from twisted.python import log
logger = logging.getLogger(__name__)
-from leap.common import events as leap_events
+from leap.common.events import emit, catalog
from leap.common.check import leap_assert_type, leap_check
from leap.mail.imap.account import IMAPAccount
from leap.mail.imap.server import LEAPIMAPServer
from leap.soledad.client import Soledad
-from leap.common.events.events_pb2 import IMAP_SERVICE_STARTED
-from leap.common.events.events_pb2 import IMAP_SERVICE_FAILED_TO_START
DO_MANHOLE = os.environ.get("LEAP_MAIL_MANHOLE", None)
if DO_MANHOLE:
@@ -182,10 +180,10 @@ def run_service(store, **kwargs):
reactor.listenTCP(manhole.MANHOLE_PORT, manhole_factory,
interface="127.0.0.1")
logger.debug("IMAP4 Server is RUNNING in port %s" % (port,))
- leap_events.signal(IMAP_SERVICE_STARTED, str(port))
+ emit(catalog.IMAP_SERVICE_STARTED, str(port))
# FIXME -- change service signature
return tport, factory
# not ok, signal error.
- leap_events.signal(IMAP_SERVICE_FAILED_TO_START, str(port))
+ emit(catalog.IMAP_SERVICE_FAILED_TO_START, str(port))
diff --git a/mail/src/leap/mail/incoming/service.py b/mail/src/leap/mail/incoming/service.py
index ea790fe8..be37396d 100644
--- a/mail/src/leap/mail/incoming/service.py
+++ b/mail/src/leap/mail/incoming/service.py
@@ -38,15 +38,8 @@ from twisted.internet.task import LoopingCall
from twisted.internet.task import deferLater
from u1db import errors as u1db_errors
-from leap.common import events as leap_events
+from leap.common.events import emit, catalog
from leap.common.check import leap_assert, leap_assert_type
-from leap.common.events.events_pb2 import IMAP_FETCHED_INCOMING
-from leap.common.events.events_pb2 import IMAP_MSG_PROCESSING
-from leap.common.events.events_pb2 import IMAP_MSG_DECRYPTED
-from leap.common.events.events_pb2 import IMAP_MSG_SAVED_LOCALLY
-from leap.common.events.events_pb2 import IMAP_MSG_DELETED_INCOMING
-from leap.common.events.events_pb2 import IMAP_UNREAD_MAIL
-from leap.common.events.events_pb2 import SOLEDAD_INVALID_AUTH_TOKEN
from leap.common.mail import get_email_charset
from leap.keymanager import errors as keymanager_errors
from leap.keymanager.openpgp import OpenPGPKey
@@ -242,7 +235,7 @@ class IncomingMail(Service):
except InvalidAuthTokenError:
# if the token is invalid, send an event so the GUI can
# disable mail and show an error message.
- leap_events.signal(SOLEDAD_INVALID_AUTH_TOKEN)
+ emit(catalog.SOLEDAD_INVALID_AUTH_TOKEN)
def _signal_fetch_to_ui(self, doclist):
"""
@@ -259,16 +252,16 @@ class IncomingMail(Service):
num_mails = len(doclist) if doclist is not None else 0
if num_mails != 0:
log.msg("there are %s mails" % (num_mails,))
- leap_events.signal(
- IMAP_FETCHED_INCOMING, str(num_mails), str(fetched_ts))
+ emit(catalog.MAIL_FETCHED_INCOMING,
+ str(num_mails), str(fetched_ts))
return doclist
def _signal_unread_to_ui(self, *args):
"""
Sends unread event to ui.
"""
- leap_events.signal(
- IMAP_UNREAD_MAIL, str(self._inbox_collection.count_unseen()))
+ emit(catalog.MAIL_UNREAD_MESSAGES,
+ str(self._inbox_collection.count_unseen()))
# process incoming mail.
@@ -291,8 +284,8 @@ class IncomingMail(Service):
deferreds = []
for index, doc in enumerate(doclist):
logger.debug("processing doc %d of %d" % (index + 1, num_mails))
- leap_events.signal(
- IMAP_MSG_PROCESSING, str(index), str(num_mails))
+ emit(catalog.MAIL_MSG_PROCESSING,
+ str(index), str(num_mails))
keys = doc.content.keys()
@@ -339,7 +332,7 @@ class IncomingMail(Service):
decrdata = ""
success = False
- leap_events.signal(IMAP_MSG_DECRYPTED, "1" if success else "0")
+ emit(catalog.MAIL_MSG_DECRYPTED, "1" if success else "0")
return self._process_decrypted_doc(doc, decrdata)
d = self._keymanager.decrypt(
@@ -724,10 +717,10 @@ class IncomingMail(Service):
listener(result)
def signal_deleted(doc_id):
- leap_events.signal(IMAP_MSG_DELETED_INCOMING)
+ emit(catalog.MAIL_MSG_DELETED_INCOMING)
return doc_id
- leap_events.signal(IMAP_MSG_SAVED_LOCALLY)
+ emit(catalog.MAIL_MSG_SAVED_LOCALLY)
d = self._delete_incoming_message(doc)
d.addCallback(signal_deleted)
return d
diff --git a/mail/src/leap/mail/mail.py b/mail/src/leap/mail/mail.py
index 4fe08a69..1649d4ad 100644
--- a/mail/src/leap/mail/mail.py
+++ b/mail/src/leap/mail/mail.py
@@ -27,8 +27,7 @@ import weakref
from twisted.internet import defer
from leap.common.check import leap_assert_type
-from leap.common import events as leap_events
-from leap.common.events.events_pb2 import IMAP_UNREAD_MAIL
+from leap.common.events import emit, catalog
from leap.common.mail import get_email_charset
from leap.mail.adaptors.soledad import SoledadMailAdaptor
@@ -654,7 +653,7 @@ class MessageCollection(object):
:type unseen: int
"""
# TODO change name of the signal, independent from imap now.
- leap_events.signal(IMAP_UNREAD_MAIL, str(unseen))
+ emit(catalog.MAIL_UNREAD_MESSAGES, str(unseen))
def copy_msg(self, msg, new_mbox_uuid):
"""
diff --git a/mail/src/leap/mail/outgoing/service.py b/mail/src/leap/mail/outgoing/service.py
index f3c23203..60ba8f53 100644
--- a/mail/src/leap/mail/outgoing/service.py
+++ b/mail/src/leap/mail/outgoing/service.py
@@ -31,7 +31,7 @@ from twisted.protocols.amp import ssl
from twisted.python import log
from leap.common.check import leap_assert_type, leap_assert
-from leap.common.events import proto, signal
+from leap.common.events import emit, catalog
from leap.keymanager import KeyManager
from leap.keymanager.openpgp import OpenPGPKey
from leap.keymanager.errors import KeyNotFound, KeyAddressMismatch
@@ -136,7 +136,7 @@ class OutgoingMail:
"""
dest_addrstr = smtp_sender_result[1][0][0]
log.msg('Message sent to %s' % dest_addrstr)
- signal(proto.SMTP_SEND_MESSAGE_SUCCESS, dest_addrstr)
+ emit(catalog.SMTP_SEND_MESSAGE_SUCCESS, dest_addrstr)
def sendError(self, failure):
"""
@@ -146,7 +146,7 @@ class OutgoingMail:
:type e: anything
"""
# XXX: need to get the address from the exception to send signal
- # signal(proto.SMTP_SEND_MESSAGE_ERROR, self._user.dest.addrstr)
+ # emit(catalog.SMTP_SEND_MESSAGE_ERROR, self._user.dest.addrstr)
err = failure.value
log.err(err)
raise err
@@ -179,7 +179,7 @@ class OutgoingMail:
requireAuthentication=False,
requireTransportSecurity=True)
factory.domain = __version__
- signal(proto.SMTP_SEND_MESSAGE_START, recipient.dest.addrstr)
+ emit(catalog.SMTP_SEND_MESSAGE_START, recipient.dest.addrstr)
reactor.connectSSL(
self._host, self._port, factory,
contextFactory=SSLContextFactory(self._cert, self._key))
@@ -241,7 +241,7 @@ class OutgoingMail:
return d
def signal_encrypt_sign(newmsg):
- signal(proto.SMTP_END_ENCRYPT_AND_SIGN,
+ emit(catalog.SMTP_END_ENCRYPT_AND_SIGN,
"%s,%s" % (self._from_address, to_address))
return newmsg, recipient
@@ -249,18 +249,18 @@ class OutgoingMail:
failure.trap(KeyNotFound, KeyAddressMismatch)
log.msg('Will send unencrypted message to %s.' % to_address)
- signal(proto.SMTP_START_SIGN, self._from_address)
+ emit(catalog.SMTP_START_SIGN, self._from_address)
d = self._sign(message, from_address)
d.addCallback(signal_sign)
return d
def signal_sign(newmsg):
- signal(proto.SMTP_END_SIGN, self._from_address)
+ emit(catalog.SMTP_END_SIGN, self._from_address)
return newmsg, recipient
log.msg("Will encrypt the message with %s and sign with %s."
% (to_address, from_address))
- signal(proto.SMTP_START_ENCRYPT_AND_SIGN,
+ emit(catalog.SMTP_START_ENCRYPT_AND_SIGN,
"%s,%s" % (self._from_address, to_address))
d = self._maybe_attach_key(origmsg, from_address, to_address)
d.addCallback(maybe_encrypt_and_sign)
diff --git a/mail/src/leap/mail/smtp/__init__.py b/mail/src/leap/mail/smtp/__init__.py
index 24402b4c..3ef016b7 100644
--- a/mail/src/leap/mail/smtp/__init__.py
+++ b/mail/src/leap/mail/smtp/__init__.py
@@ -26,7 +26,7 @@ from leap.mail.outgoing.service import OutgoingMail
logger = logging.getLogger(__name__)
-from leap.common.events import proto, signal
+from leap.common.events import emit, catalog
from leap.mail.smtp.gateway import SMTPFactory
@@ -65,12 +65,12 @@ def setup_smtp_gateway(port, userid, keymanager, smtp_host, smtp_port,
factory = SMTPFactory(userid, keymanager, encrypted_only, outgoing_mail)
try:
tport = reactor.listenTCP(port, factory, interface="localhost")
- signal(proto.SMTP_SERVICE_STARTED, str(port))
+ emit(catalog.SMTP_SERVICE_STARTED, str(port))
return factory, tport
except CannotListenError:
logger.error("STMP Service failed to start: "
"cannot listen in port %s" % port)
- signal(proto.SMTP_SERVICE_FAILED_TO_START, str(port))
+ emit(catalog.SMTP_SERVICE_FAILED_TO_START, str(port))
except Exception as exc:
logger.error("Unhandled error while launching smtp gateway service")
logger.exception(exc)
diff --git a/mail/src/leap/mail/smtp/gateway.py b/mail/src/leap/mail/smtp/gateway.py
index 954a7d0f..dd2c32d9 100644
--- a/mail/src/leap/mail/smtp/gateway.py
+++ b/mail/src/leap/mail/smtp/gateway.py
@@ -39,7 +39,7 @@ from twisted.python import log
from email.Header import Header
from leap.common.check import leap_assert_type
-from leap.common.events import proto, signal
+from leap.common.events import emit, catalog
from leap.keymanager.openpgp import OpenPGPKey
from leap.keymanager.errors import KeyNotFound
from leap.mail.utils import validate_address
@@ -201,19 +201,19 @@ class SMTPDelivery(object):
# verify if recipient key is available in keyring
def found(_):
log.msg("Accepting mail for %s..." % user.dest.addrstr)
- signal(proto.SMTP_RECIPIENT_ACCEPTED_ENCRYPTED, user.dest.addrstr)
+ emit(catalog.SMTP_RECIPIENT_ACCEPTED_ENCRYPTED, user.dest.addrstr)
def not_found(failure):
failure.trap(KeyNotFound)
# if key was not found, check config to see if will send anyway
if self._encrypted_only:
- signal(proto.SMTP_RECIPIENT_REJECTED, user.dest.addrstr)
+ emit(catalog.SMTP_RECIPIENT_REJECTED, user.dest.addrstr)
raise smtp.SMTPBadRcpt(user.dest.addrstr)
log.msg("Warning: will send an unencrypted message (because "
"encrypted_only' is set to False).")
- signal(
- proto.SMTP_RECIPIENT_ACCEPTED_UNENCRYPTED,
+ emit(
+ catalog.SMTP_RECIPIENT_ACCEPTED_UNENCRYPTED,
user.dest.addrstr)
def encrypt_func(_):
@@ -306,7 +306,7 @@ class EncryptedMessage(object):
"""
log.msg("Connection lost unexpectedly!")
log.err()
- signal(proto.SMTP_CONNECTION_LOST, self._user.dest.addrstr)
+ emit(catalog.SMTP_CONNECTION_LOST, self._user.dest.addrstr)
# unexpected loss of connection; don't save
self._lines = []