summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/mail/smtp/gateway.py
diff options
context:
space:
mode:
authorKali Kaneko (leap communications) <kali@leap.se>2017-04-25 18:00:12 +0200
committerKali Kaneko (leap communications) <kali@leap.se>2017-04-27 19:33:28 +0200
commit9f95446a55533c8cdceec7c4430be5cad752ecb1 (patch)
tree4265c127ee9b2c5f1e038836ad2e7b92ea0cad80 /src/leap/bitmask/mail/smtp/gateway.py
parent9a1548aa01996ce93febe0272f1f8e4dd5e130ff (diff)
[bug] unify logging style using class attr
I changed most of the logger statements to use a class attribute, in this way it's easier to identify which class it's logging them. in some cases I leave a module-level logger, when we're either using functions or when the module it's too small. at the same time I did a general review and cleanup of the logging statements.
Diffstat (limited to 'src/leap/bitmask/mail/smtp/gateway.py')
-rw-r--r--src/leap/bitmask/mail/smtp/gateway.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/leap/bitmask/mail/smtp/gateway.py b/src/leap/bitmask/mail/smtp/gateway.py
index b1fafadd..08d59e11 100644
--- a/src/leap/bitmask/mail/smtp/gateway.py
+++ b/src/leap/bitmask/mail/smtp/gateway.py
@@ -56,8 +56,6 @@ generator.Generator = RFC3156CompliantGenerator
LOCAL_FQDN = "bitmask.local"
-logger = Logger()
-
@implementer(IRealm)
class LocalSMTPRealm(object):
@@ -221,10 +219,13 @@ class SMTPFactory(protocol.ServerFactory):
@implementer(smtp.IMessageDelivery)
class SMTPDelivery(object):
+
"""
Validate email addresses and handle message delivery.
"""
+ log = Logger()
+
def __init__(self, userid, keymanager, encrypted_only, outgoing_mail):
"""
Initialize the SMTP delivery object.
@@ -298,7 +299,7 @@ class SMTPDelivery(object):
# verify if recipient key is available in keyring
def found(_):
- logger.debug("Accepting mail for %s..." % user.dest.addrstr)
+ self.log.debug('Accepting mail for %s...' % user.dest.addrstr)
emit_async(catalog.SMTP_RECIPIENT_ACCEPTED_ENCRYPTED,
self._userid, user.dest.addrstr)
@@ -310,7 +311,7 @@ class SMTPDelivery(object):
emit_async(catalog.SMTP_RECIPIENT_REJECTED, self._userid,
user.dest.addrstr)
raise smtp.SMTPBadRcpt(user.dest.addrstr)
- logger.warn(
+ self.log.warn(
'Warning: will send an unencrypted message (because '
'"encrypted_only" is set to False).')
emit_async(
@@ -344,7 +345,7 @@ class SMTPDelivery(object):
# accept mail from anywhere. To reject an address, raise
# smtp.SMTPBadSender here.
if str(origin) != str(self._userid):
- logger.error(
+ self.log.error(
"Rejecting sender {0}, expected {1}".format(origin,
self._userid))
raise smtp.SMTPBadSender(origin)
@@ -362,6 +363,7 @@ class EncryptedMessage(object):
recipient.
"""
implements(smtp.IMessage)
+ log = Logger()
def __init__(self, user, outgoing_mail):
"""
@@ -396,7 +398,7 @@ class EncryptedMessage(object):
:returns: a deferred
"""
- logger.debug("Message data complete.")
+ self.log.debug('Message data complete.')
self._lines.append('') # add a trailing newline
raw_mail = '\r\n'.join(self._lines)
@@ -406,8 +408,7 @@ class EncryptedMessage(object):
"""
Log an error when the connection is lost.
"""
- logger.error("Connection lost unexpectedly!")
- logger.error()
+ self.log.error('Connection lost unexpectedly!')
emit_async(catalog.SMTP_CONNECTION_LOST, self._userid,
self._user.dest.addrstr)
# unexpected loss of connection; don't save