5 from __future__
import print_function
11 internal_tlds = [
"corp",
"personal"]
15 def is_internal(hostname):
16 components = hostname.split(
".")
17 return components.pop()
in internal_tlds
21 def are_mixed(hostnames):
22 hostnames_mapped = map(is_internal, hostnames)
25 num_internal_hosts = hostnames_mapped.count(
True)
28 num_external_hosts = hostnames_mapped.count(
False)
30 return num_external_hosts >= 1
and num_internal_hosts >= 1
40 def envfrom(self, mailfrom, *str):
41 self.mailfrom = mailfrom
43 t = parse_addr(mailfrom)
45 self.domains.append(t[1])
47 self.domains.append(
'local')
49 return Milter.CONTINUE
52 def envrcpt(self, to, *str):
56 self.domains.append(t[1])
58 self.domains.append(
'local')
60 if are_mixed(self.domains):
62 self.setreply(
'550',
'5.7.1',
'Mixing internal and external TLDs')
65 return Milter.CONTINUE
68 socketname =
"/var/run/nomixsock"
71 Milter.factory = NoMixMilter
72 print(
"%s milter startup" % time.strftime(
'%Y%b%d %H:%M:%S'))
77 print(
"%s nomix milter shutdown" % time.strftime(
'%Y%b%d %H:%M:%S'))
79 if __name__ ==
"__main__":
A do "nothing" Milter base class representing an SMTP connection.
Definition: __init__.py:265
Miscellaneous functions.
Definition: utils.py:1
def runmilter(name, socketname, timeout=0, rmsock=True)
Run the milter.
Definition: __init__.py:835
def uniqueID()
Definition: __init__.py:30