Zhang Huangbin avatar Zhang Huangbin committed 720284c

Code cleanup for PEP8.

Comments (0)

Files changed (9)

     * Plugin renamed:
       block_amavisd_blacklisted_senders -> ldap_amavisd_block_blacklisted_senders
     * New plugin for SQL backends: sql_user_restrictions.
-      Note, it requires 4 new columns on table `vmail.mailbox`, please refer
-      to iRedMail upgrade tutorials.
+      Note: 4 new columns on table `vmail.mailbox`, please refer to iRedMail
+      upgrade tutorials.
 
 iRedAPD-1.3.8:
     * Add rc scripts for OpenBSD.

libs/ldaplib/conn_utils.py

         basedn = domaindn
         # 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, )
+        searchFilter = "(|(&(|(objectClass=mailUser)(objectClass=mailExternalUser))(memberOfGroup=%s))(&(objectclass=mailList)(mail=%s)))" % (recipient, recipient)
         searchAttrs = ['mail', 'shadowAddress', 'listAllowedUser', ]
 
     logging.debug('base dn: %s' % basedn)

libs/ldaplib/modeler.py

                     smtp_session_data,
                     plugins=[],
                     sender_search_attrlist=[],
-                    recipient_search_attrlist=[],
-                   ):
+                    recipient_search_attrlist=[]):
         # No sender or recipient in smtp session.
         if not 'sender' in smtp_session_data or \
-           not 'recipient' in smtp_session_data:
+                not 'recipient' in smtp_session_data:
             return SMTP_ACTIONS['default']
 
         # Not a valid email address.
                          'sender_dn': None,
                          'sender_ldif': None,
                          'recipient_dn': None,
-                         'recipient_ldif': None,
-                        }
+                         'recipient_ldif': None}
 
         # TODO Perform addition plugins which don't require sender/recipient info
         # e.g.
-        #   - enforce TLS: encryption_protocol=TLSv1/SSLv3
-
+        #   - security enforce: encryption_protocol=TLSv1/SSLv3
 
         for plugin in plugins:
             # Get LDIF data of sender if required
             if plugin.REQUIRE_LOCAL_SENDER \
-               and plugin_kwargs['sender_dn'] is None:
+                    and plugin_kwargs['sender_dn'] is None:
                 sender_dn, sender_ldif = conn_utils.get_account_ldif(
                     conn=self.conn,
                     account=smtp_session_data['sender'],
 
             # Get LDIF data of recipient if required
             if plugin.REQUIRE_LOCAL_RECIPIENT \
-               and plugin_kwargs['recipient_dn'] is None:
+                    and plugin_kwargs['recipient_dn'] is None:
                 recipient_dn, recipient_ldif = conn_utils.get_account_ldif(
                     conn=self.conn,
                     account=smtp_session_data['recipient'],
         logging.debug('<!> Error: %s' % str(e))
 
     return action
-

plugins/ldap_domain_wblist.py

     splitedSenderDomain = str(sender.split('@')[-1]).split('.')
 
     filterOfSenders = ''
-    listOfRestrictedSenders = [sender, '@'+sender.split('@')[-1],]
+    listOfRestrictedSenders = [sender, '@' + sender.split('@')[-1]]
     for counter in range(len(splitedSenderDomain)):
         # Append domain and sub-domain.
         listOfRestrictedSenders += ['@.' + '.'.join(splitedSenderDomain)]

plugins/ldap_expired_password.py

 # Force mail user to change password in how many days. Default is 90.
 EXPIRED_DAYS = 90
 
+
 def restriction(**kwargs):
     sender_ldif = kwargs['sender_ldif']
 
         return 'REJECT Password expired, please change your password before sending email.'
 
     return SMTP_ACTIONS['default']
-

plugins/ldap_maillist_access_policy.py

         try:
             qr = conn.search_s(
                 base_dn,
-                1, # 1 == ldap.SCOPE_ONELEVEL
+                1,  # 1 == ldap.SCOPE_ONELEVEL
                 "(&(objectClass=mailDomain)(|(domainName=%s)(domainAliasName=%s)))" % (recipient_domain, recipient_domain),
                 ['domainName', 'domainAliasName', ],
             )
             if qr:
                 dn, entries = qr[0]
-                recipient_alias_domains = \
-                        entries.get('domainName', []) + \
-                        entries.get('domainAliasName', [])
+                recipient_alias_domains = entries.get('domainName', []) + entries.get('domainAliasName', [])
         except Exception, e:
             logging.debug('Error while fetching alias domains: %s' % str(e))
 

plugins/ldap_recipient_restrictions.py

 # Value of mailWhitelistRecipient and mailBlacklistRecipient:
 #   - Single address:   user@domain.ltd
 #   - Whole domain:     @domain.ltd
-#   - Whole Domain and its sub-domains: @.domain.ltd
-#   - All recipient:       @.
+#   - Domain and its sub-domains: @.domain.ltd
+#   - All addresses:    @.
 
 import logging
 
 SENDER_SEARCH_ATTRLIST = ['mailBlacklistedRecipient', 'mailWhitelistRecipient']
 RECIPIENT_SEARCH_ATTRLIST = []
 
+
 def restriction(**kwargs):
     sender_ldif = kwargs['sender_ldif']
     smtp_session_data = kwargs['smtp_session_data']
     #   -> .sub1.com.cn
     #   -> .com.cn
     #   -> .cn
-    allowed_recipients = ['@.', recipient, '@' + recipient.split('@')[-1],]
+    allowed_recipients = ['@.', recipient, '@' + recipient.split('@')[-1]]
     for counter in range(len(splited_recipient_domain)):
         # Append domain and sub-domain.
         allowed_recipients += ['@.' + '.'.join(splited_recipient_domain)]
         splited_recipient_domain.pop(0)
 
+    logging.debug('Allowed recipients: %s' % ', '.join(allowed_recipients))
     # Get value of mailBlacklistedRecipient, mailWhitelistRecipient.
-    blacklisted_rcpts = [v.lower() for v in sender_ldif.get('mailBlacklistRecipient', [])]
-    whitelisted_rcpts = [v.lower() for v in sender_ldif.get('mailWhitelistRecipient', [])]
+    blacklisted_rcpts = [v.lower()
+                         for v in sender_ldif.get('mailBlacklistRecipient', [])]
+    whitelisted_rcpts = [v.lower()
+                         for v in sender_ldif.get('mailWhitelistRecipient', [])]
 
     # Bypass whitelisted recipients if has intersection set.
     if len(set(allowed_recipients) & set(whitelisted_rcpts)) > 0:

plugins/sql_alias_access_policy.py

     elif policy == MAILLIST_POLICY_SUBDOMAIN:
         # Bypass all users under the same domain or sub domains.
         if senderReceiver['sender'].endswith(senderReceiver['recipient_domain']) or \
-           senderReceiver['sender'].endswith('.' + senderReceiver['recipient_domain']):
+                senderReceiver['sender'].endswith('.' + senderReceiver['recipient_domain']):
             return 'DUNNO'
         else:
             return SMTP_ACTIONS['reject']
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.