code style reformatting using black

This commit is contained in:
Goffi 2018-06-27 20:14:46 +02:00
commit 744cb0c503

View file

@ -20,6 +20,7 @@
from sat.core.i18n import _
from sat.core.constants import Const as C
from sat.core.log import getLogger
log = getLogger(__name__)
from twisted.internet import defer
from twisted.cred import portal, checkers, credentials
@ -42,7 +43,9 @@ PLUGIN_INFO = {
C.PI_DEPENDENCIES: ["Maildir"],
C.PI_MAIN: "SMTP_server",
C.PI_HANDLER: "no",
C.PI_DESCRIPTION: _("""Create a SMTP server that you can use to send your "normal" type messages""")
C.PI_DESCRIPTION: _(
"""Create a SMTP server that you can use to send your "normal" type messages"""
),
}
@ -62,7 +65,7 @@ class SMTP_server(object):
log.info(_("Plugin SMTP Server initialization"))
self.host = host
#parameters
# parameters
host.memory.updateParams(self.params)
port = int(self.host.memory.getParamA("SMTP Port", "Mail Server"))
@ -88,11 +91,20 @@ class SatSmtpMessage(object):
"""handle end of message"""
mail = Parser().parsestr("\n".join(self.message))
try:
self.host._sendMessage(parseaddr(mail['to'].decode('utf-8', 'replace'))[1], mail.get_payload().decode('utf-8', 'replace'), # TODO: manage other charsets
subject=mail['subject'].decode('utf-8', 'replace'), mess_type='normal', profile_key=self.profile)
self.host._sendMessage(
parseaddr(mail["to"].decode("utf-8", "replace"))[1],
mail.get_payload().decode(
"utf-8", "replace"
), # TODO: manage other charsets
subject=mail["subject"].decode("utf-8", "replace"),
mess_type="normal",
profile_key=self.profile,
)
except:
exc_type, exc_value, exc_traceback = sys.exc_info()
log.error(_(u"Can't send message: %s") % exc_value) # The email is invalid or incorreclty parsed
log.error(
_(u"Can't send message: %s") % exc_value
) # The email is invalid or incorreclty parsed
return defer.fail()
self.message = None
return defer.succeed(None)
@ -151,8 +163,8 @@ class SmtpRealm(object):
self.host = host
def requestAvatar(self, avatarID, mind, *interfaces):
log.debug('requestAvatar')
profile = avatarID.decode('utf-8')
log.debug("requestAvatar")
profile = avatarID.decode("utf-8")
if smtp.IMessageDelivery not in interfaces:
raise NotImplementedError
return smtp.IMessageDelivery, SatSmtpDelivery(self.host, profile), lambda: None
@ -164,16 +176,19 @@ class SatProfileCredentialChecker(object):
Check if the profile exists, and if the password is OK
Return the profile as avatarId
"""
implements(checkers.ICredentialsChecker)
credentialInterfaces = (credentials.IUsernamePassword,
credentials.IUsernameHashedPassword)
credentialInterfaces = (
credentials.IUsernamePassword,
credentials.IUsernameHashedPassword,
)
def __init__(self, host):
self.host = host
def _cbPasswordMatch(self, matched, profile):
if matched:
return profile.encode('utf-8')
return profile.encode("utf-8")
else:
return failure.Failure(cred_error.UnauthorizedLogin())
@ -181,14 +196,15 @@ class SatProfileCredentialChecker(object):
profiles = self.host.memory.getProfilesList()
if not credentials.username in profiles:
return defer.fail(cred_error.UnauthorizedLogin())
d = self.host.memory.asyncGetParamA("Password", "Connection", profile_key=credentials.username)
d = self.host.memory.asyncGetParamA(
"Password", "Connection", profile_key=credentials.username
)
d.addCallback(credentials.checkPassword)
d.addCallback(self._cbPasswordMatch, credentials.username)
return d
class SmtpServerFactory(smtp.SMTPFactory):
def __init__(self, host):
self.protocol = smtp.ESMTP
self.host = host