Commits

Zhang Huangbin committed 07a9f44

Fix incorrect sender list in plugin: block_amavisd_blacklisted_senders.py.

Comments (0)

Files changed (1)

src/plugins/block_amavisd_blacklisted_senders.py

 #!/usr/bin/env python
 # encoding: utf-8
 
-# Author: Zhang Huangbin <michaelbibby (at) gmail.com>
+# Author: Zhang Huangbin (zhb@iredmail.org)
 
 import sys
 
 def restriction(smtpSessionData, ldapRecipientLdif, **kargs):
     # Get sender address.
     sender = smtpSessionData.get('sender').lower()
+    splited_sender_domain = str(sender.split('@')[-1]).split('.')
+
+    # Get correct domain name and sub-domain name.
+    # Sample sender domain: sub2.sub1.com.cn
+    #   -> sub2.sub1.com.cn
+    #   -> .sub2.sub1.com.cn
+    #   -> .sub1.com.cn
+    #   -> .com.cn
+    #   -> .cn
+    list_senders = [sender, '@'+sender.split('@')[-1],]
+    for counter in range(len(splited_sender_domain)):
+        # Append domain and sub-domain.
+        list_senders += ['@.' + '.'.join(splited_sender_domain)]
+        splited_sender_domain.pop(0)
 
     # Get value of amavisBlacklistedSender.
-    blSenders = ldapRecipientLdif.get('amavisBlacklistSender', [])
+    blSenders = [v.lower() for v in ldapRecipientLdif.get('amavisBlacklistSender', [])]
 
-    if sender in [ v.lower() for v in blSenders ]:
+    if len(set(list_senders) & set(blSenders)) > 0:
+        # Reject blacklisted senders.
         return 'REJECT Not Authorized'
     else:
         return 'DUNNO'
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.