49 lines
1.8 KiB
Python
49 lines
1.8 KiB
Python
import Milter
|
|
from socket import AF_INET, AF_INET6
|
|
from Milter.utils import parse_addr
|
|
|
|
class myMilter(Milter.Base):
|
|
|
|
def __init__(self): # A new instance with each new connection.
|
|
self.id = Milter.uniqueID() # Integer incremented with each call.
|
|
|
|
# @Milter.noreply
|
|
# called on connect to MTA
|
|
def connect(self, IPname, family, hostaddr):
|
|
# IPname: the PTR name or bracketed IP of the SMTP client
|
|
# family: one of (socket.AF_INET, socket.AF_INET6, socket.AF_UNIX)
|
|
# hostaddr: a tuple or string with peer IP or socketname
|
|
# (self, 'ip068.subnet71.example.com', AF_INET, ('215.183.71.68', 4720) )
|
|
# (self, 'ip6.mxout.example.com', AF_INET6, ('3ffe:80e8:d8::1', 4720, 1, 0) )
|
|
self.IP = hostaddr[0]
|
|
self.port = hostaddr[1]
|
|
if family == AF_INET6:
|
|
self.flow = hostaddr[2]
|
|
self.scope = hostaddr[3]
|
|
else:
|
|
self.flow = None
|
|
self.scope = None
|
|
self.IPname = IPname # Name from a reverse IP lookup
|
|
self.H = None
|
|
return Milter.CONTINUE
|
|
|
|
# called when the SMTP client says MAIL FROM
|
|
def envfrom(self, mailfrom, *str):
|
|
uwaddr = "csclub.uwaterloo.ca"
|
|
if uwaddr in parse_addr(mailfrom) and self.IP == 25:
|
|
return Milter.REJECT # this will only drop the msg not the connection
|
|
return Milter.CONTINUE
|
|
|
|
|
|
def main():
|
|
socketname = "/var/run/milter-nospoof"
|
|
timeout = 600
|
|
# Register to have the Milter factory create instances of your class:
|
|
Milter.factory = myMilter
|
|
# print "%s milter startup" % time.strftime('%Y%b%d %H:%M:%S')
|
|
# sys.stdout.flush()
|
|
# Milter.runmilter("pythonfilter",socketname,timeout)
|
|
# print "%s bms milter shutdown" % time.strftime('%Y%b%d %H:%M:%S')
|
|
if __name__ == "__main__":
|
|
main()
|