summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/mail/smtp
diff options
context:
space:
mode:
authorKali Kaneko (leap communications) <kali@leap.se>2016-10-05 12:28:14 -0400
committerKali Kaneko (leap communications) <kali@leap.se>2016-10-07 10:22:36 -0400
commit99b53c1714d302d7f0884e03b5c102081c483504 (patch)
tree82ac74e776a330338bf94563273aa4d33f578877 /src/leap/bitmask/mail/smtp
parent4a471fb8b434d3df07c5de42fc41590b5d9fc5f5 (diff)
[refactor] use new logger infrastructure
Diffstat (limited to 'src/leap/bitmask/mail/smtp')
-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
3 files changed, 19 insertions, 15 deletions
diff --git a/src/leap/bitmask/mail/smtp/__init__.py b/src/leap/bitmask/mail/smtp/__init__.py
index f8b8e65f..90baf668 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 16e1af97..b1fafadd 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 07c182d6..48e6865b 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)