4 from __future__
import print_function
10 internal_tlds = [
"corp",
"personal"]
14 def is_internal(hostname):
15 components = hostname.split(
".")
16 return components.pop()
in internal_tlds
20 def are_mixed(hostnames):
21 hostnames_mapped = map(is_internal, hostnames)
24 num_internal_hosts = hostnames_mapped.count(
True)
27 num_external_hosts = hostnames_mapped.count(
False)
29 return num_external_hosts >= 1
and num_internal_hosts >= 1
39 def envfrom(self, mailfrom, *str):
40 self.mailfrom = mailfrom
42 t = parse_addr(mailfrom)
44 self.domains.append(t[1])
46 self.domains.append(
'local')
48 return Milter.CONTINUE
51 def envrcpt(self, to, *str):
55 self.domains.append(t[1])
57 self.domains.append(
'local')
59 if are_mixed(self.domains):
61 self.setreply(
'550',
'5.7.1',
'Mixing internal and external TLDs')
64 return Milter.CONTINUE
67 socketname =
"/var/run/nomixsock"
70 Milter.factory = NoMixMilter
71 print(
"%s milter startup" % time.strftime(
'%Y%b%d %H:%M:%S'))
76 print(
"%s nomix milter shutdown" % time.strftime(
'%Y%b%d %H:%M:%S'))
78 if __name__ ==
"__main__":
def uniqueID()
Definition: __init__.py:30
def runmilter(name, socketname, timeout=0, rmsock=True)
Run the milter.
Definition: __init__.py:835
A do "nothing" Milter base class representing an SMTP connection.
Definition: __init__.py:265
Miscellaneous functions.
Definition: utils.py:1