aboutsummaryrefslogtreecommitdiffstats
path: root/Mailman/Utils.py
diff options
context:
space:
mode:
authorMark Sapiro <mark@msapiro.net>2015-01-23 15:50:47 -0800
committerMark Sapiro <mark@msapiro.net>2015-01-23 15:50:47 -0800
commit792407be592b8e7d523cb134a01b09101cbc2cad (patch)
treef66aaacb3c7781e490ea9c365510c75e46818f81 /Mailman/Utils.py
parent0e3c1fbaf0c80ed865945a14e604954daaf80a6a (diff)
downloadmailman2-792407be592b8e7d523cb134a01b09101cbc2cad.tar.gz
mailman2-792407be592b8e7d523cb134a01b09101cbc2cad.tar.xz
mailman2-792407be592b8e7d523cb134a01b09101cbc2cad.zip
Implemented the equivalent domains feature for list posting/moderation.
Diffstat (limited to 'Mailman/Utils.py')
-rw-r--r--Mailman/Utils.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/Mailman/Utils.py b/Mailman/Utils.py
index 0cb9f122..13c4ed8b 100644
--- a/Mailman/Utils.py
+++ b/Mailman/Utils.py
@@ -1216,3 +1216,37 @@ def IsDMARCProhibited(mlist, email):
return False
+
+def check_eq_domains(email, domains_list):
+ """The arguments are an email address and a string representing a
+ list of lists in a form like 'a,b,c;1,2' representing [['a', 'b',
+ 'c'],['1', '2']]. The inner lists are domains which are
+ equivalent in some sense. The return is an empty list or a list
+ of email addresses equivalent to the first argument.
+ For example, given
+
+ email = 'user@me.com'
+ domains_list = '''domain1, domain2; mac.com, me.com, icloud.com;
+ domaina, domainb
+ '''
+
+ check_eq_domains(email, domains_list) will return
+ ['user@mac.com', 'user@icloud.com']
+ """
+ if not domains_list:
+ return []
+ try:
+ local, domain = email.rsplit('@', 1)
+ except ValueError:
+ return []
+ domain = domain.lower()
+ domains_list = re.sub('\s', '', domains_list).lower()
+ domains = domains_list.split(';')
+ domains_list = []
+ for d in domains:
+ domains_list.append(d.split(','))
+ for domains in domains_list:
+ if domain in domains:
+ return [local + '@' + x for x in domains if x != domain]
+ return []
+