Zhang Huangbin avatar Zhang Huangbin committed 9a7b574

Code cleanup for PEP8.

Comments (0)

Files changed (8)

+* rename variables: ldapSenderLdif -> sender_ldif or ldif_of_sender
 * plugin/ldap_expired_passwd.py: set password last update date to today if
   shadowLastChange is not present or 0?
-* plugins/{ldap, sql}
 * Query required SQL columns instead of all
 * Plugins:
+    + HELO
     + Greylisting (server-wide and per-user, per-domain)
     + White/Blacklisting (server-wide and per-domain)
 * Detect protocol_state=RCPT in smtp session
                 'defer': 'DEFER_IF_PERMIT Service temporarily unavailable',
                 'reject': 'REJECT Not authorized',
                 'default': 'DUNNO',
-               }
+                }
 
 LDAP_ACCESS_POLICIES_OF_MAIL_LIST = {
     'public': 'Unrestricted',

libs/ldap_conn_utils.py

 import settings
 from libs import SMTP_ACTIONS
 
+
 def get_account_ldif(conn, account, attrlist=None):
     logging.debug('[+] Getting LDIF data of account: %s' % account)
 
 
     logging.debug('search filter: %s' % ldap_filter)
     logging.debug('search attributes: %s' % str(attrlist))
-    #if attrlist:
-    #    logging.debug('search attributes: %s' % str(attrlist))
-    #else:
-    #    # Attribute list must be None if it's a empty list.
-    #    attrlist = None
+    if not isinstance(attrlist, list):
+        # Attribute list must be None or non-empty list
+        attrlist = None
 
     try:
         result = conn.search_s(settings.ldap_basedn,
         logging.debug('!!! ERROR !!! result: %s' % str(e))
         return (None, None)
 
+
 def get_allowed_senders_of_mail_list(conn,
                                      base_dn,
                                      dn_of_mail_list,
         searchFilter = "(&(|(objectclass=mailUser)(objectClass=mailExternalUser))(accountStatus=active)(memberOfGroup=%s))" % (recipient, )
 
         # Get both mail and shadowAddress.
-        searchAttrs = ['mail', 'shadowAddress',]
+        searchAttrs = ['mail', 'shadowAddress', ]
 
     elif policy in ['allowedonly', 'moderatorsonly', 'moderators']:
         # Get mail list moderators.
         # Policy: policy==membersAndModeratorsOnly or not set.
         # Filter used to get both members and moderators.
         searchFilter = "(|(&(|(objectClass=mailUser)(objectClass=mailExternalUser))(memberOfGroup=%s))(&(objectclass=mailList)(mail=%s)))" % (recipient, recipient, )
-        searchAttrs = ['mail', 'shadowAddress', 'listAllowedUser',]
+        searchAttrs = ['mail', 'shadowAddress', 'listAllowedUser', ]
 
     logging.debug('base dn: %s' % basedn)
     logging.debug('search scope: %s' % searchScope)
                 searchFilter += '(mail=%s)' % i
             searchFilter += '))'
 
-            searchAttrs = ['shadowAddress',]
+            searchAttrs = ['shadowAddress', ]
 
             logging.debug('base dn: %s' % basedn)
             logging.debug('search scope: 2 (ldap.SCOPE_SUBTREE)')
 
             try:
                 resultOfShadowAddresses = conn.search_s(
-                    'ou=Users,'+domaindn,
+                    'ou=Users,' + domaindn,
                     2,  # ldap.SCOPE_SUBTREE
                     searchFilter,
-                    ['mail', 'shadowAddress',],
+                    ['mail', 'shadowAddress', ],
                 )
 
                 for obj in resultOfShadowAddresses:
         logging.debug('Error: %s' % str(e))
         return []
 
+
 def apply_plugin(plugin, **kwargs):
     action = SMTP_ACTIONS['default']
 
         logging.debug('<!> Error: %s' % str(e))
 
     return action
-
                     plugins_for_misc=[],
                     sender_search_attrlist=None,
                     recipient_search_attrlist=None,
-                   ):
+                    ):
         # No sender or recipient in smtp session.
         if not 'sender' in smtp_session_map or not 'recipient' in smtp_session_map:
             return SMTP_ACTIONS['defer']
                          'senderLdif': None,
                          'recipientDn': None,
                          'recipientLdif': None,
-                        }
+                         }
 
         if get_sender_ldif:
             senderDn, senderLdif = ldap_conn_utils.get_account_ldif(
                 return action
 
         return SMTP_ACTIONS['default']
-

plugins/amavisd_block_blacklisted_senders.py

 SENDER_SEARCH_ATTRLIST = []
 RECIPIENT_SEARCH_ATTRLIST = ['amavisBlacklistSender', 'amavisWhitelistSender']
 
+
 def restriction(**kwargs):
     smtpSessionData = kwargs['smtpSessionData']
     ldapRecipientLdif = kwargs['recipientLdif']
     #   -> @.cn
     splited_sender_domain = str(sender.split('@', 1)[-1]).split('.')
 
-    # Default senders (user@domain.ltd): ['@.', 'user@domain.ltd', @domain.ltd']
-    valid_amavisd_senders = set(['@.', sender, '@'+sender.split('@', 1)[-1],])
+    # Default senders (user@domain.ltd):
+    # ['@.', 'user@domain.ltd', @domain.ltd']
+    valid_amavisd_senders = set(['@.', sender, '@' + sender.split('@', 1)[-1], ])
     for counter in range(len(splited_sender_domain)):
         # Append domain and sub-domain.
         valid_amavisd_senders.update(['@.' + '.'.join(splited_sender_domain)])

plugins/ldap_domain_wblist.py

 
 import logging
 
-REQUIRE_LOCAL_SENDER_= False
+REQUIRE_LOCAL_SENDER = False
 REQUIRE_LOCAL_RECIPIENT = False
 SENDER_SEARCH_ATTRLIST = []
 RECIPIENT_SEARCH_ATTRLIST = []
 
+
 def restriction(**kwargs):
     ldapConn = kwargs['conn']
     ldapBaseDn = kwargs['baseDn']
     sender = smtpSessionData['sender'].lower()
     splitedSenderDomain = str(sender.split('@')[-1]).split('.')
 
-    #filterOfSender = '(domainWhitelistSender=%s)' % (sender,)
     filterOfSenders = ''
     listOfRestrictedSenders = [sender, '@'+sender.split('@')[-1],]
     for counter in range(len(splitedSenderDomain)):

plugins/sql_alias_access_policy.py

 from web import sqlquote
 from libs import SMTP_ACTIONS
 
-REQUIRE_LOCAL_SENDER_= False
+REQUIRE_LOCAL_SENDER = False
 REQUIRE_LOCAL_RECIPIENT = True
 
 # Policies. MUST be defined in lower case.

plugins/sql_user_restrictions.py

 from web import sqlquote
 from libs import SMTP_ACTIONS
 
-REQUIRE_LOCAL_SENDER_= False
+REQUIRE_LOCAL_SENDER = False
 REQUIRE_LOCAL_RECIPIENT = False
 
 def restriction(dbConn, senderReceiver, smtpSessionData, **kargs):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.