summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/mail
diff options
context:
space:
mode:
Diffstat (limited to 'src/leap/bitmask/mail')
-rw-r--r--src/leap/bitmask/mail/adaptors/soledad.py39
-rw-r--r--src/leap/bitmask/mail/imap/account.py8
-rw-r--r--src/leap/bitmask/mail/imap/mailbox.py7
-rw-r--r--src/leap/bitmask/mail/imap/messages.py6
-rw-r--r--src/leap/bitmask/mail/imap/server.py20
-rw-r--r--src/leap/bitmask/mail/imap/service/__init__.py7
-rw-r--r--src/leap/bitmask/mail/mail.py18
-rw-r--r--src/leap/bitmask/mail/outgoing/service.py20
-rw-r--r--src/leap/bitmask/mail/rfc3156.py6
-rw-r--r--src/leap/bitmask/mail/smtp/__init__.py6
-rw-r--r--src/leap/bitmask/mail/smtp/gateway.py22
-rw-r--r--src/leap/bitmask/mail/smtp/service.py6
-rw-r--r--src/leap/bitmask/mail/sync_hooks.py12
-rw-r--r--src/leap/bitmask/mail/testing/imap.py6
14 files changed, 95 insertions, 88 deletions
diff --git a/src/leap/bitmask/mail/adaptors/soledad.py b/src/leap/bitmask/mail/adaptors/soledad.py
index 39c6bcb..b8153e5 100644
--- a/src/leap/bitmask/mail/adaptors/soledad.py
+++ b/src/leap/bitmask/mail/adaptors/soledad.py
@@ -16,16 +16,14 @@
"""
Soledadad MailAdaptor module.
"""
-import logging
import re
from collections import defaultdict
from email import message_from_string
from twisted.internet import defer
-from twisted.python import log
+from twisted.logger import Logger
from zope.interface import implements
-from leap.soledad.common import l2db
from leap.common.check import leap_assert, leap_assert_type
@@ -39,10 +37,11 @@ from leap.bitmask.mail.utils import lowerdict, first
from leap.bitmask.mail.utils import stringify_parts_map
from leap.bitmask.mail.interfaces import IMailAdaptor, IMessageWrapper
+from leap.soledad.common import l2db
from leap.soledad.common.document import SoledadDocument
-logger = logging.getLogger(__name__)
+logger = Logger()
# TODO
# [ ] Convenience function to create mail specifying subject, date, etc?
@@ -187,7 +186,7 @@ class SoledadDocumentWrapper(models.DocumentWrapper):
# error, we should mark them in the copy so there is no attempt to
# create/update them.
failure.trap(l2db.errors.RevisionConflict)
- logger.debug("Got conflict while putting %s" % doc_id)
+ logger.debug("got conflict while putting %s" % doc_id)
def delete(self, store):
"""
@@ -505,7 +504,7 @@ class MessageWrapper(object):
for (key, doc) in cdocs.items()])
for doc_id, cdoc in zip(self.mdoc.cdocs, self.cdocs.values()):
if cdoc.raw == "":
- log.msg("Empty raw field in cdoc %s" % doc_id)
+ logger.warning("Empty raw field in cdoc %s" % doc_id)
cdoc.set_future_doc_id(doc_id)
def create(self, store, notify_just_mdoc=False, pending_inserts_dict=None):
@@ -567,8 +566,8 @@ class MessageWrapper(object):
mdoc_created = self.mdoc.create(store, is_copy=self._is_copy)
fdoc_created = self.fdoc.create(store, is_copy=self._is_copy)
- mdoc_created.addErrback(lambda f: log.err(f))
- fdoc_created.addErrback(lambda f: log.err(f))
+ mdoc_created.addErrback(logger.error)
+ fdoc_created.addErrback(logger.error)
self.d.append(mdoc_created)
self.d.append(fdoc_created)
@@ -584,13 +583,13 @@ class MessageWrapper(object):
self.d.append(cdoc.create(store))
def log_all_inserted(result):
- log.msg("All parts inserted for msg!")
+ logger.debug("All parts inserted for msg!")
return result
self.all_inserted_d = defer.gatherResults(self.d, consumeErrors=True)
self.all_inserted_d.addCallback(log_all_inserted)
self.all_inserted_d.addCallback(unblock_pending_insert)
- self.all_inserted_d.addErrback(lambda failure: log.err(failure))
+ self.all_inserted_d.addErrback(logger.error)
if notify_just_mdoc:
return mdoc_created
@@ -639,7 +638,7 @@ class MessageWrapper(object):
d = new_wrapper.create(store)
d.addCallback(lambda result: new_wrapper)
- d.addErrback(lambda failure: log.err(failure))
+ d.addErrback(logger.error)
return d
def set_mbox_uuid(self, mbox_uuid):
@@ -946,15 +945,15 @@ class SoledadMailAdaptor(SoledadIndexMixin):
# See https://leap.se/code/issues/7495.
# This avoids blocks, but the real cause still needs to be
# isolated (0.9.0rc3) -- kali
- log.msg("BUG ---------------------------------------------------")
- log.msg("BUG: Error while retrieving part docs for mdoc id %s" %
- mdoc_id)
- log.err(failure)
- log.msg("BUG (please report above info) ------------------------")
+ logger.debug("BUG ---------------------------------------------------")
+ logger.debug("BUG: Error while retrieving part docs for mdoc id %s" %
+ mdoc_id)
+ logger.error(failure)
+ logger.debug("BUG (please report above info) ------------------------")
return []
def _err_log_cannot_find_msg(failure):
- log.msg("BUG: Error while getting msg (uid=%s)" % uid)
+ logger.error("BUG: Error while getting msg (uid=%s)" % uid)
return None
if get_cdocs:
@@ -1041,7 +1040,7 @@ class SoledadMailAdaptor(SoledadIndexMixin):
Delete all messages flagged as deleted.
"""
def err(failure):
- log.err(failure)
+ logger.errror(failure)
def delete_fdoc_and_mdoc_flagged(fdocs):
# low level here, not using the wrappers...
@@ -1125,7 +1124,7 @@ class SoledadMailAdaptor(SoledadIndexMixin):
def get_mdoc_id(hdoc):
if not hdoc:
- log.msg("Could not find a HDOC with MSGID %s" % msgid)
+ logger.warning("Could not find a HDOC with MSGID %s" % msgid)
return None
hdoc = hdoc[0]
mdoc_id = hdoc.doc_id.replace("H-", "M-%s-" % uuid)
@@ -1177,7 +1176,7 @@ class SoledadMailAdaptor(SoledadIndexMixin):
return MailboxWrapper.get_all(store)
def _errback(self, failure):
- log.err(failure)
+ logger.error(failure)
def _split_into_parts(raw):
diff --git a/src/leap/bitmask/mail/imap/account.py b/src/leap/bitmask/mail/imap/account.py
index d885d59..8ee0cbf 100644
--- a/src/leap/bitmask/mail/imap/account.py
+++ b/src/leap/bitmask/mail/imap/account.py
@@ -17,14 +17,14 @@
"""
Soledad Backed IMAP Account.
"""
-import logging
import os
import time
from functools import partial
from twisted.internet import defer
+from twisted.logger import Logger
from twisted.mail import imap4
-from twisted.python import log
+from twisted.logger import Logger
from zope.interface import implements
from leap.common.check import leap_assert, leap_assert_type
@@ -33,7 +33,7 @@ from leap.bitmask.mail.mail import Account
from leap.bitmask.mail.imap.mailbox import IMAPMailbox, normalize_mailbox
from leap.soledad.client import Soledad
-logger = logging.getLogger(__name__)
+logger = Logger()
PROFILE_CMD = os.environ.get('LEAP_PROFILE_IMAPCMD', False)
@@ -247,7 +247,7 @@ class IMAPAccount(object):
def check_it_exists(mailboxes):
if name not in mailboxes:
- logger.warning("SELECT: No such mailbox!")
+ logger.warn('SELECT: No such mailbox!')
return None
return name
diff --git a/src/leap/bitmask/mail/imap/mailbox.py b/src/leap/bitmask/mail/imap/mailbox.py
index b80280c..10ac01e 100644
--- a/src/leap/bitmask/mail/imap/mailbox.py
+++ b/src/leap/bitmask/mail/imap/mailbox.py
@@ -18,7 +18,6 @@
IMAP Mailbox.
"""
import re
-import logging
import os
import cStringIO
import StringIO
@@ -29,7 +28,7 @@ from email.utils import formatdate
from twisted.internet import defer
from twisted.internet import reactor
-from twisted.python import log
+from twisted.logger import Logger
from twisted.mail import imap4
from zope.interface import implements
@@ -39,7 +38,7 @@ from leap.common.check import leap_assert_type
from leap.bitmask.mail.constants import INBOX_NAME, MessageFlags
from leap.bitmask.mail.imap.messages import IMAPMessage
-logger = logging.getLogger(__name__)
+logger = Logger()
# TODO LIST
# [ ] Restore profile_cmd instrumentation
@@ -894,7 +893,7 @@ class IMAPMailbox(object):
return d
# nothing implemented for any other query
- logger.warning("Cannot process query: %s" % (query,))
+ logger.warn("Cannot process query: %s" % (query,))
return []
# IMessageCopier
diff --git a/src/leap/bitmask/mail/imap/messages.py b/src/leap/bitmask/mail/imap/messages.py
index 841ebb2..98d64fe 100644
--- a/src/leap/bitmask/mail/imap/messages.py
+++ b/src/leap/bitmask/mail/imap/messages.py
@@ -17,15 +17,15 @@
"""
IMAPMessage implementation.
"""
-import logging
from twisted.mail import imap4
from twisted.internet import defer
+from twisted.logger import Logger
from zope.interface import implements
from leap.bitmask.mail.utils import find_charset, CaseInsensitiveDict
-logger = logging.getLogger(__name__)
+logger = Logger()
# TODO
# [ ] Add ref to incoming message during add_msg.
@@ -213,7 +213,7 @@ def _format_headers(headers, negate, *names):
# some reason we do not have headers, we have to return at least that
# one
if not headers:
- logger.warning("No headers found")
+ logger.warn("No headers found")
return {str('content-type'): str('')}
names = map(lambda s: s.upper(), names)
diff --git a/src/leap/bitmask/mail/imap/server.py b/src/leap/bitmask/mail/imap/server.py
index 5a63af0..897e1f0 100644
--- a/src/leap/bitmask/mail/imap/server.py
+++ b/src/leap/bitmask/mail/imap/server.py
@@ -22,7 +22,7 @@ from copy import copy
from twisted.internet.defer import maybeDeferred
from twisted.mail import imap4
-from twisted.python import log
+from twisted.logger import Logger
# imports for LITERAL+ patch
from twisted.internet import defer, interfaces
@@ -32,6 +32,9 @@ from twisted.mail.imap4 import LiteralString, LiteralFile
from leap.common.events import emit_async, catalog
+logger = Logger()
+
+
def _getContentType(msg):
"""
Return a two-tuple of the main and subtype of the given message.
@@ -164,7 +167,7 @@ class LEAPIMAPServer(imap4.IMAP4Server):
msg = line[:7] + " [...]"
else:
msg = copy(line)
- log.msg('rcv (%s): %s' % (self.state, msg))
+ logger.debug('rcv (%s): %s' % (self.state, msg))
imap4.IMAP4Server.lineReceived(self, line)
def close_server_connection(self):
@@ -449,7 +452,7 @@ class LEAPIMAPServer(imap4.IMAP4Server):
def _subscribeEb(failure):
m = failure.value
- log.err()
+ logger.error()
if failure.check(imap4.MailboxException):
self.sendNegativeResponse(tag, str(m))
else:
@@ -474,7 +477,7 @@ class LEAPIMAPServer(imap4.IMAP4Server):
def _unsubscribeEb(failure):
m = failure.value
- log.err()
+ logger.error()
if failure.check(imap4.MailboxException):
self.sendNegativeResponse(tag, str(m))
else:
@@ -509,7 +512,7 @@ class LEAPIMAPServer(imap4.IMAP4Server):
elif failure.check(imap4.MailboxException):
self.sendNegativeResponse(tag, str(m))
else:
- log.err()
+ logger.error()
self.sendBadResponse(
tag,
"Server error encountered while "
@@ -536,7 +539,7 @@ class LEAPIMAPServer(imap4.IMAP4Server):
if failure.check(imap4.MailboxException):
self.sendNegativeResponse(tag, str(c))
else:
- log.err()
+ logger.error()
self.sendBadResponse(
tag, "Server error encountered while creating mailbox")
@@ -561,8 +564,7 @@ class LEAPIMAPServer(imap4.IMAP4Server):
if failure.check(imap4.MailboxException):
self.sendNegativeResponse(tag, str(m))
else:
- print "SERVER: other error"
- log.err()
+ logger.error()
self.sendBadResponse(
tag,
"Server error encountered while deleting mailbox")
@@ -598,7 +600,7 @@ class LEAPIMAPServer(imap4.IMAP4Server):
def _ebAppendGotMailbox(self, failure, tag):
self.sendBadResponse(
tag, "Server error encountered while opening mailbox.")
- log.err(failure)
+ logger.error(failure)
def __cbAppend(self, result, tag, mbox):
diff --git a/src/leap/bitmask/mail/imap/service/__init__.py b/src/leap/bitmask/mail/imap/service/__init__.py
index d9cd335..b0ad05d 100644
--- a/src/leap/bitmask/mail/imap/service/__init__.py
+++ b/src/leap/bitmask/mail/imap/service/__init__.py
@@ -17,18 +17,17 @@
"""
IMAP Service Initialization.
"""
-import logging
import os
from collections import defaultdict
from twisted.cred.portal import Portal, IRealm
-from twisted.mail.imap4 import IAccount
from twisted.internet import defer
from twisted.internet import reactor
from twisted.internet.error import CannotListenError
from twisted.internet.protocol import ServerFactory
-from twisted.python import log
+from twisted.logger import Logger
+from twisted.mail.imap4 import IAccount
from zope.interface import implementer
from leap.common.events import emit_async, catalog
@@ -38,7 +37,7 @@ from leap.bitmask.mail.imap.server import LEAPIMAPServer
# TODO: leave only an implementor of IService in here
-logger = logging.getLogger(__name__)
+logger = Logger()
DO_MANHOLE = os.environ.get("LEAP_MAIL_MANHOLE", None)
if DO_MANHOLE:
diff --git a/src/leap/bitmask/mail/mail.py b/src/leap/bitmask/mail/mail.py
index 7a16b46..30fbd49 100644
--- a/src/leap/bitmask/mail/mail.py
+++ b/src/leap/bitmask/mail/mail.py
@@ -24,7 +24,6 @@ In the future, pluggable transports will expose this generic API.
"""
import itertools
import uuid
-import logging
import StringIO
import time
import weakref
@@ -32,11 +31,10 @@ import weakref
from collections import defaultdict
from twisted.internet import defer
-from twisted.python import log
+from twisted.logger import Logger
from leap.common.check import leap_assert_type
from leap.common.events import emit_async, catalog
-
from leap.bitmask.mail.adaptors.soledad import SoledadMailAdaptor
from leap.bitmask.mail.constants import INBOX_NAME
from leap.bitmask.mail.constants import MessageFlags
@@ -45,7 +43,7 @@ from leap.bitmask.mail.plugins import soledad_sync_hooks
from leap.bitmask.mail.utils import find_charset, CaseInsensitiveDict
from leap.bitmask.mail.utils import lowerdict
-logger = logging.getLogger(name=__name__)
+logger = Logger()
# TODO LIST
@@ -193,7 +191,7 @@ class MessagePart(object):
try:
part_map = sub_pmap[str(part)]
except KeyError:
- log.msg("getSubpart for %s: KeyError" % (part,))
+ logger.debug("getSubpart for %s: KeyError" % (part,))
raise IndexError
return MessagePart(part_map, cdocs=self._cdocs, nested=True)
@@ -441,7 +439,7 @@ class MessageCollection(object):
d.addCallback(
lambda uid: self.get_message_by_uid(
uid, get_cdocs=get_cdocs))
- d.addErrback(lambda f: log.err(f))
+ d.addErrback(logger.error)
return d
def get_message_by_uid(self, uid, absolute=True, get_cdocs=False):
@@ -614,7 +612,7 @@ class MessageCollection(object):
headers = lowerdict(msg.get_headers())
moz_draft_hdr = "X-Mozilla-Draft-Info"
if moz_draft_hdr.lower() in headers:
- log.msg("Setting fast notify to False, Draft detected")
+ logger.debug("setting fast notify to False, Draft detected")
notify_just_mdoc = False
if notify_just_mdoc:
@@ -659,7 +657,7 @@ class MessageCollection(object):
d.addCallback(insert_mdoc_id, wrapper)
d.addCallback(self.cb_signal_unread_to_ui)
d.addCallback(self.notify_new_to_listeners)
- d.addErrback(lambda failure: log.err(failure))
+ d.addErrback(logger.error)
return d
@@ -746,7 +744,7 @@ class MessageCollection(object):
def insert_doc(_, mbox_uuid, doc_id):
d = self.mbox_indexer.get_uid_from_doc_id(mbox_uuid, doc_id)
d.addCallback(insert_conditionally, mbox_uuid, doc_id)
- d.addErrback(lambda err: log.failure(err))
+ d.addErrback(logger.error)
d.addCallback(log_result)
return d
@@ -804,7 +802,7 @@ class MessageCollection(object):
self.store, self.mbox_uuid)
mdocs_deleted.addCallback(get_uid_list)
mdocs_deleted.addCallback(delete_uid_entries)
- mdocs_deleted.addErrback(lambda f: log.err(f))
+ mdocs_deleted.addErrback(logger.error)
return mdocs_deleted
# TODO should add a delete-by-uid to collection?
diff --git a/src/leap/bitmask/mail/outgoing/service.py b/src/leap/bitmask/mail/outgoing/service.py
index 9fe3ec1..f483763 100644
--- a/src/leap/bitmask/mail/outgoing/service.py
+++ b/src/leap/bitmask/mail/outgoing/service.py
@@ -35,8 +35,8 @@ from OpenSSL import SSL
from twisted.mail import smtp
from twisted.internet import reactor
from twisted.internet import defer
+from twisted.logger import Logger
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 emit_async, catalog
@@ -55,6 +55,11 @@ from leap.bitmask.mail.rfc3156 import PGPEncrypted
# [ ] rename this module to something else, service should be the implementor
# of IService
+logger = Logger()
+
+
+logger = Logger()
+
class SSLContextFactory(ssl.ClientContextFactory):
def __init__(self, cert, key):
@@ -162,7 +167,7 @@ class OutgoingMail(object):
"""
dest_addrstr = smtp_sender_result[1][0][0]
fromaddr = self._from_address
- log.msg('Message sent from %s to %s' % (fromaddr, dest_addrstr))
+ logger.info('Message sent from %s to %s' % (fromaddr, dest_addrstr))
emit_async(catalog.SMTP_SEND_MESSAGE_SUCCESS,
fromaddr, dest_addrstr)
@@ -185,8 +190,7 @@ class OutgoingMail(object):
# temporal error. We might want to notify the permanent errors
# differently.
- err = failure.value
- log.err(err)
+ logger.error(failure)
if self._bouncer:
self._bouncer.bounce_message(
@@ -204,7 +208,7 @@ class OutgoingMail(object):
:type encrypt_and_sign_result: tuple
"""
message, recipient = encrypt_and_sign_result
- log.msg("Connecting to SMTP server %s:%s" % (self._host, self._port))
+ logger.info("Connecting to SMTP server %s:%s" % (self._host, self._port))
msg = message.as_string(False)
# we construct a defer to pass to the ESMTPSenderFactory
@@ -297,7 +301,7 @@ class OutgoingMail(object):
def if_key_not_found_send_unencrypted(failure, message):
failure.trap(KeyNotFound, KeyAddressMismatch)
- log.msg('Will send unencrypted message to %s.' % to_address)
+ logger.info('Will send unencrypted message to %s.' % to_address)
emit_async(catalog.SMTP_START_SIGN, self._from_address, to_address)
d = self._sign(message, from_address)
d.addCallback(signal_sign)
@@ -307,8 +311,8 @@ class OutgoingMail(object):
emit_async(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))
+ logger.info("Will encrypt the message with %s and sign with %s."
+ % (to_address, from_address))
emit_async(catalog.SMTP_START_ENCRYPT_AND_SIGN,
self._from_address,
"%s,%s" % (self._from_address, to_address))
diff --git a/src/leap/bitmask/mail/rfc3156.py b/src/leap/bitmask/mail/rfc3156.py
index 7d7bc0f..1ab631f 100644
--- a/src/leap/bitmask/mail/rfc3156.py
+++ b/src/leap/bitmask/mail/rfc3156.py
@@ -22,7 +22,8 @@ Implements RFC 3156: MIME Security with OpenPGP.
import base64
from StringIO import StringIO
-from twisted.python import log
+from twisted.logger import Logger
+
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email import errors
@@ -33,6 +34,7 @@ from email.generator import (
_make_boundary,
)
+logger = Logger()
#
# A generator that solves http://bugs.python.org/issue14983
@@ -163,7 +165,7 @@ def encode_base64(msg):
except KeyError:
msg['Content-Transfer-Encoding'] = 'base64'
elif encoding is not 'base64':
- log.err('Unknown content-transfer-encoding: %s' % encoding)
+ logger.error('Unknown content-transfer-encoding: %s' % encoding)
def encode_base64_rec(msg):
diff --git a/src/leap/bitmask/mail/smtp/__init__.py b/src/leap/bitmask/mail/smtp/__init__.py
index f8b8e65..90baf66 100644
--- a/src/leap/bitmask/mail/smtp/__init__.py
+++ b/src/leap/bitmask/mail/smtp/__init__.py
@@ -17,16 +17,16 @@
"""
SMTP gateway helper function.
"""
-import logging
import os
from twisted.internet import reactor
from twisted.internet.error import CannotListenError
+from twisted.logger import Logger
from leap.common.events import emit_async, catalog
from leap.bitmask.mail.smtp.gateway import SMTPFactory
-logger = logging.getLogger(__name__)
+logger = Logger()
SMTP_PORT = 2013
@@ -68,4 +68,4 @@ def run_service(soledad_sessions, keymanager_sessions, sendmail_opts,
emit_async(catalog.SMTP_SERVICE_FAILED_TO_START, str(port))
except Exception as exc:
logger.error("Unhandled error while launching smtp gateway service")
- logger.exception(exc)
+ logger.error('%r' % exc)
diff --git a/src/leap/bitmask/mail/smtp/gateway.py b/src/leap/bitmask/mail/smtp/gateway.py
index 16e1af9..b1fafad 100644
--- a/src/leap/bitmask/mail/smtp/gateway.py
+++ b/src/leap/bitmask/mail/smtp/gateway.py
@@ -39,7 +39,7 @@ from twisted.cred.portal import Portal, IRealm
from twisted.mail import smtp
from twisted.mail.imap4 import LOGINCredentials, PLAINCredentials
from twisted.internet import defer, protocol
-from twisted.python import log
+from twisted.logger import Logger
from leap.common.check import leap_assert_type
from leap.common.events import emit_async, catalog
@@ -56,6 +56,8 @@ generator.Generator = RFC3156CompliantGenerator
LOCAL_FQDN = "bitmask.local"
+logger = Logger()
+
@implementer(IRealm)
class LocalSMTPRealm(object):
@@ -296,7 +298,7 @@ class SMTPDelivery(object):
# verify if recipient key is available in keyring
def found(_):
- log.msg("Accepting mail for %s..." % user.dest.addrstr)
+ logger.debug("Accepting mail for %s..." % user.dest.addrstr)
emit_async(catalog.SMTP_RECIPIENT_ACCEPTED_ENCRYPTED,
self._userid, user.dest.addrstr)
@@ -308,8 +310,9 @@ class SMTPDelivery(object):
emit_async(catalog.SMTP_RECIPIENT_REJECTED, self._userid,
user.dest.addrstr)
raise smtp.SMTPBadRcpt(user.dest.addrstr)
- log.msg("Warning: will send an unencrypted message (because "
- "encrypted_only' is set to False).")
+ logger.warn(
+ 'Warning: will send an unencrypted message (because '
+ '"encrypted_only" is set to False).')
emit_async(
catalog.SMTP_RECIPIENT_ACCEPTED_UNENCRYPTED,
self._userid, user.dest.addrstr)
@@ -341,8 +344,9 @@ class SMTPDelivery(object):
# accept mail from anywhere. To reject an address, raise
# smtp.SMTPBadSender here.
if str(origin) != str(self._userid):
- log.msg("Rejecting sender {0}, expected {1}".format(origin,
- self._userid))
+ logger.error(
+ "Rejecting sender {0}, expected {1}".format(origin,
+ self._userid))
raise smtp.SMTPBadSender(origin)
self._origin = origin
return origin
@@ -392,7 +396,7 @@ class EncryptedMessage(object):
:returns: a deferred
"""
- log.msg("Message data complete.")
+ logger.debug("Message data complete.")
self._lines.append('') # add a trailing newline
raw_mail = '\r\n'.join(self._lines)
@@ -402,8 +406,8 @@ class EncryptedMessage(object):
"""
Log an error when the connection is lost.
"""
- log.msg("Connection lost unexpectedly!")
- log.err()
+ logger.error("Connection lost unexpectedly!")
+ logger.error()
emit_async(catalog.SMTP_CONNECTION_LOST, self._userid,
self._user.dest.addrstr)
# unexpected loss of connection; don't save
diff --git a/src/leap/bitmask/mail/smtp/service.py b/src/leap/bitmask/mail/smtp/service.py
index 07c182d..48e6865 100644
--- a/src/leap/bitmask/mail/smtp/service.py
+++ b/src/leap/bitmask/mail/smtp/service.py
@@ -17,16 +17,16 @@
"""
SMTP gateway helper function.
"""
-import logging
import os
from twisted.internet import reactor
from twisted.internet.error import CannotListenError
+from twisted.logger import Logger
from leap.common.events import emit_async, catalog
from leap.bitmask.mail.smtp.gateway import SMTPFactory
-logger = logging.getLogger(__name__)
+logger = Logger()
SMTP_PORT = 2013
@@ -70,4 +70,4 @@ def run_service(soledad_sessions, keymanager_sessions, sendmail_opts,
emit_async(catalog.SMTP_SERVICE_FAILED_TO_START, str(port))
except Exception as exc:
logger.error("Unhandled error while launching smtp gateway service")
- logger.exception(exc)
+ logger.error('%r' % exc)
diff --git a/src/leap/bitmask/mail/sync_hooks.py b/src/leap/bitmask/mail/sync_hooks.py
index ff4bf56..de3a0c1 100644
--- a/src/leap/bitmask/mail/sync_hooks.py
+++ b/src/leap/bitmask/mail/sync_hooks.py
@@ -20,19 +20,17 @@ Soledad PostSync Hooks.
Process every new document of interest after every soledad synchronization,
using the hooks that soledad exposes via plugins.
"""
-import logging
-
from re import compile as regex_compile
from zope.interface import implements
from twisted.internet import defer
from twisted.plugin import IPlugin
-from twisted.python import log
+from twisted.logger import Logger
from leap.bitmask.mail import constants
from leap.soledad.client.interfaces import ISoledadPostSyncPlugin
-logger = logging.getLogger(__name__)
+logger = Logger()
def _get_doc_type_preffix(s):
@@ -58,7 +56,7 @@ class MailProcessingPostSyncHook(object):
for doc_id in doc_id_list:
if _get_doc_type_preffix(doc_id) in self.watched_doc_types:
- log.msg("Mail post-sync hook: processing %s" % doc_id)
+ logger.info("Mail post-sync hook: processing %s" % doc_id)
process_fun(doc_id)
return defer.gatherResults(self._processing_deferreds)
@@ -79,7 +77,7 @@ class MailProcessingPostSyncHook(object):
mbox_uuid = _get_mbox_uuid(mdoc_id)
if mbox_uuid:
chash = _get_chash_from_mdoc(mdoc_id)
- logger.debug("Making index table for %s:%s" % (mbox_uuid, chash))
+ logger.debug('making index table for %s:%s' % (mbox_uuid, chash))
index_docid = constants.METAMSGID.format(
mbox_uuid=mbox_uuid.replace('-', '_'),
chash=chash)
@@ -93,7 +91,7 @@ class MailProcessingPostSyncHook(object):
def _process_queued_docs(self):
assert(self._has_configured_account())
pending = self._pending_docs
- log.msg("Mail post-sync hook: processing queued docs")
+ logger.info("Mail post-sync hook: processing queued docs")
def remove_pending_docs(res):
self._pending_docs = []
diff --git a/src/leap/bitmask/mail/testing/imap.py b/src/leap/bitmask/mail/testing/imap.py
index 75ee9c7..92bf4d3 100644
--- a/src/leap/bitmask/mail/testing/imap.py
+++ b/src/leap/bitmask/mail/testing/imap.py
@@ -27,7 +27,7 @@ from twisted.cred.portal import Portal, IRealm
from twisted.mail import imap4
from twisted.internet import defer
from twisted.protocols import loopback
-from twisted.python import log
+from twisted.logger import Logger
from zope.interface import implementer
from leap.bitmask.mail.adaptors import soledad as soledad_adaptor
@@ -38,6 +38,8 @@ from leap.bitmask.mail.testing.common import SoledadTestMixin
TEST_USER = "testuser@leap.se"
TEST_PASSWD = "1234"
+logger = Logger()
+
#
# Simple IMAP4 Client for testing
@@ -180,7 +182,7 @@ class IMAP4HelperMixin(SoledadTestMixin):
self.client.transport.loseConnection()
self.server.transport.loseConnection()
if hasattr(self, 'function'):
- log.err(failure, "Problem with %r" % (self.function,))
+ logger.error(failure, "Problem with %r" % (self.function,))
def loopback(self):
return loopback.loopbackAsync(self.server, self.client)