Mercurial > libervia-backend
diff sat/plugins/plugin_misc_smtp.py @ 2624:56f94936df1e
code style reformatting using black
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 27 Jun 2018 20:14:46 +0200 |
parents | 26edcf3a30eb |
children | ab2696e34d29 |
line wrap: on
line diff
--- a/sat/plugins/plugin_misc_smtp.py Wed Jun 27 07:51:29 2018 +0200 +++ b/sat/plugins/plugin_misc_smtp.py Wed Jun 27 20:14:46 2018 +0200 @@ -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 @@ 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 @@ 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 @@ """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 @@ 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 @@ 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 @@ 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