Commits

Zhang Huangbin committed ccba1ee

Code cleanup.

Comments (0)

Files changed (5)

 * python-ldap ( >= 2.2.0 ): http://python-ldap.org/
 
 # Document
-http://www.iredmail.org/doc.html
+* iRedMail documentations:
+  http://www.iredmail.org/doc.html
+
+* Postfix SMTP Access Policy Delegation:
+  http://www.postfix.org/SMTPD_POLICY_README.html

src/iredapd-rr.py

 from libs import __version__, SMTP_ACTIONS
 
 class apd_channel(asynchat.async_chat):
-    def __init__(self, conn, remoteaddr):
+    def __init__(self, conn, remote_addr):
         asynchat.async_chat.__init__(self, conn)
+        self.remote_addr = remote_addr
         self.buffer = []
         self.map = {}
         self.set_terminator('\n')
-        logging.debug("Connect from " + remoteaddr[0])
+        logging.debug("Connect from %s, port %s." % self.remote_addr)
 
     def push(self, msg):
         asynchat.async_chat.push(self, msg + '\n')
                 logging.debug('Error: %s. Use default action instead: %s' %
                         (str(e), str(action)))
 
-            logging.info('%s -> %s, %s' %
-                    (self.map['sender'], self.map['recipient'], action))
-            self.push('action=' + action)
-            self.push('')
+            # Log final action.
+            logging.info('[%s] %s -> %s, %s' % (self.map['client_address'],
+                                                self.map['sender'],
+                                                self.map['recipient'],
+                                                action,
+                                               ))
+
+            self.push('action=' + action + '\n')
             asynchat.async_chat.handle_close(self)
             logging.debug("Connection closed")
         else:
             action = SMTP_ACTIONS['defer']
             logging.debug("replying: " + action)
-            self.push(action)
-            self.push('')
+            self.push(action + '\n')
             asynchat.async_chat.handle_close(self)
             logging.debug("Connection closed")
 
                 (__version__, os.getpid(), ip, str(port)))
 
     def handle_accept(self):
-        conn, remoteaddr = self.accept()
-        channel = apd_channel(conn, remoteaddr)
+        conn, remote_addr = self.accept()
+        channel = apd_channel(conn, remote_addr)
 
 
 class SQLModeler:
 
 
 class apd_channel(asynchat.async_chat):
-    def __init__(self, conn, remoteaddr):
+    def __init__(self, conn, remote_addr):
         asynchat.async_chat.__init__(self, conn)
+        self.remote_addr = remote_addr
         self.buffer = []
         self.map = {}
         self.set_terminator('\n')
-        logging.debug("Connect from " + remoteaddr[0])
+        logging.debug("Connect from %s, port %s." % self.remote_addr)
 
     def push(self, msg):
         asynchat.async_chat.push(self, msg + '\n')
                 logging.debug('Error: %s. Use default action instead: %s' %
                         (str(e), str(action)))
 
-            logging.info('%s -> %s, %s' %
-                    (self.map['sender'], self.map['recipient'], action))
-            self.push('action=' + action)
-            self.push('')
+            # Log final action.
+            logging.info('[%s] %s -> %s, %s' % (self.map['client_address'],
+                                                self.map['sender'],
+                                                self.map['recipient'],
+                                                action,
+                                               ))
+
+            self.push('action=' + action + '\n')
             asynchat.async_chat.handle_close(self)
             logging.debug("Connection closed")
         else:
             action = SMTP_ACTIONS['defer']
             logging.debug("replying: " + action)
-            self.push(action)
-            self.push('')
+            self.push(action + '\n')
             asynchat.async_chat.handle_close(self)
             logging.debug("Connection closed")
 
                 (__version__, os.getpid(), ip, str(port)))
 
     def handle_accept(self):
-        conn, remoteaddr = self.accept()
-        channel = apd_channel(conn, remoteaddr)
+        conn, remote_addr = self.accept()
+        channel = apd_channel(conn, remote_addr)
 
 
 def main():

src/libs/ldaplib.py

 class LDAPModeler:
     def __init__(self, cfg, logger):
         self.cfg = cfg
+        self.logger = logger
 
         # Read LDAP server related settings.
         self.uri = self.cfg.get('ldap', 'uri', 'ldap://127.0.0.1:389')
         self.binddn = self.cfg.get('ldap', 'binddn')
         self.bindpw = self.cfg.get('ldap', 'bindpw')
         self.baseDN = self.cfg.get('ldap', 'basedn')
-        self.logger = logger
 
         # Initialize ldap connection.
         try:
                             logger=self.logger,
                         )
 
-                        self.logger.debug('Response from plugin (%s): %s' % (module.__name__, pluginAction))
+                        self.logger.debug('Response (%s): %s' % (module.__name__, pluginAction))
                         if not pluginAction.startswith('DUNNO'):
-                            self.logger.info('Response from plugin (%s): %s' % (module.__name__, pluginAction))
+                            self.logger.info('Response (%s): %s' % (module.__name__, pluginAction))
                             return pluginAction
                     except Exception, e:
                         self.logger.debug('Error while apply plugin (%s): %s' % (module, str(e)))

src/libs/sqllib.py

                             logger=self.logger,
                         )
 
-                        self.logger.debug('Response from plugin (%s): %s' % (module.__name__, pluginAction))
+                        self.logger.debug('Response (%s): %s' % (module.__name__, pluginAction))
                         if not pluginAction.startswith('DUNNO'):
-                            self.logger.info('Response from plugin (%s): %s' % (module.__name__, pluginAction))
+                            self.logger.info('Response (%s): %s' % (module.__name__, pluginAction))
                             return pluginAction
                     except Exception, e:
                         self.logger.debug('Error while apply plugin (%s): %s' % (module, str(e)))