diff src/plugins/plugin_misc_smtp.py @ 594:e629371a28d3

Fix pep8 support in src/plugins.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 18 Jan 2013 17:55:35 +0100
parents beaf6bec2fcd
children 6fd1095b2b7b
line wrap: on
line diff
--- a/src/plugins/plugin_misc_smtp.py	Mon Jan 21 00:59:50 2013 +0100
+++ b/src/plugins/plugin_misc_smtp.py	Fri Jan 18 17:55:35 2013 +0100
@@ -21,33 +21,32 @@
 
 from logging import debug, info, error
 import warnings
-from twisted.internet import protocol,defer
+from twisted.internet import protocol, defer
 from twisted.words.protocols.jabber import error as jab_error
-from twisted.cred import portal,checkers,credentials
+from twisted.cred import portal, checkers, credentials
 from twisted.cred import error as cred_error
 from twisted.mail import smtp
 from twisted.python import failure
 from email.parser import Parser
 from email.utils import parseaddr
 from twisted.mail.imap4 import LOGINCredentials, PLAINCredentials
-import os,os.path
+import os
 from twisted.internet import reactor
 import sys
 
-
 from zope.interface import implements
 
+PLUGIN_INFO = {
+    "name": "SMTP server Plugin",
+    "import_name": "SMTP",
+    "type": "Misc",
+    "protocols": [],
+    "dependencies": ["Maildir"],
+    "main": "SMTP_server",
+    "handler": "no",
+    "description": _("""Create a SMTP server that you can use to send your "normal" type messages""")
+}
 
-PLUGIN_INFO = {
-"name": "SMTP server Plugin",
-"import_name": "SMTP",
-"type": "Misc",
-"protocols": [],
-"dependencies": ["Maildir"],
-"main": "SMTP_server",
-"handler": "no",
-"description": _("""Create a SMTP server that you can use to send your "normal" type messages""")
-}
 
 class SMTP_server(object):
 
@@ -74,13 +73,14 @@
         self.server_factory = SmtpServerFactory(self.host)
         reactor.listenTCP(port, self.server_factory)
 
+
 class SatSmtpMessage(object):
     implements(smtp.IMessage)
 
     def __init__(self, host, profile):
-        self.host=host
-        self.profile=profile
-        self.message=[]
+        self.host = host
+        self.profile = profile
+        self.message = []
 
     def lineReceived(self, line):
         """handle another line"""
@@ -90,25 +90,26 @@
         """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()
-            error(_("Can't send message: %s") % exc_value) #The email is invalid or incorreclty parsed
+            error(_("Can't send message: %s") % exc_value)  # The email is invalid or incorreclty parsed
             return defer.fail()
-        self.message=None
+        self.message = None
         return defer.succeed(None)
 
     def connectionLost(self):
         """handle message truncated"""
         raise smtp.SMTPError
 
+
 class SatSmtpDelivery(object):
     implements(smtp.IMessageDelivery)
 
     def __init__(self, host, profile):
-        self.host=host
-        self.profile=profile
+        self.host = host
+        self.profile = profile
 
     def receivedHeader(self, helo, origin, recipients):
         """
@@ -144,18 +145,20 @@
         """
         return origin
 
+
 class SmtpRealm(object):
     implements(portal.IRealm)
 
-    def __init__(self,host):
+    def __init__(self, host):
         self.host = host
 
     def requestAvatar(self, avatarID, mind, *interfaces):
         debug('requestAvatar')
-        profile=avatarID.decode('utf-8')
+        profile = avatarID.decode('utf-8')
         if smtp.IMessageDelivery not in interfaces:
             raise NotImplementedError
-        return smtp.IMessageDelivery, SatSmtpDelivery(self.host,profile), lambda:None
+        return smtp.IMessageDelivery, SatSmtpDelivery(self.host, profile), lambda: None
+
 
 class SatProfileCredentialChecker(object):
     """
@@ -167,7 +170,6 @@
     credentialInterfaces = (credentials.IUsernamePassword,
                             credentials.IUsernameHashedPassword)
 
-
     def __init__(self, host):
         self.host = host
 
@@ -182,26 +184,26 @@
         if not credentials.username in profiles:
             return defer.fail(cred_error.UnauthorizedLogin())
         password = self.host.memory.getParamA("Password", "Connection", profile_key=credentials.username)
-        return defer.maybeDeferred(
-            credentials.checkPassword,
-            password).addCallback(
-            self._cbPasswordMatch, credentials.username)
+        return defer.maybeDeferred(credentials.checkPassword,
+                                   password).addCallback(self._cbPasswordMatch,
+                                                         credentials.username)
+
 
 class SmtpServerFactory(smtp.SMTPFactory):
 
     def __init__(self, host):
         self.protocol = smtp.ESMTP
-        self.host=host
+        self.host = host
         _portal = portal.Portal(SmtpRealm(self.host))
         _portal.registerChecker(SatProfileCredentialChecker(self.host))
         smtp.SMTPFactory.__init__(self, _portal)
 
     def startedConnecting(self, connector):
-        debug (_("SMTP server connection started"))
+        debug(_("SMTP server connection started"))
         smtp.SMTPFactory.startedConnecting(self, connector)
 
     def clientConnectionLost(self, connector, reason):
-        debug (_("SMTP server connection lost (reason: %s)"), reason)
+        debug(_("SMTP server connection lost (reason: %s)"), reason)
         smtp.SMTPFactory.clientConnectionLost(self, connector, reason)
 
     def buildProtocol(self, addr):
@@ -209,4 +211,3 @@
         # add the challengers from imap4, more secure and complicated challengers are available
         p.challengers = {"LOGIN": LOGINCredentials, "PLAIN": PLAINCredentials}
         return p
-