Skip to content
Snippets Groups Projects
Commit b3d63281 authored by Stuart Gathman's avatar Stuart Gathman
Browse files

Fix template so it actually runs - makes a better example that way :-)

parent 2133942c
Branches
Tags
No related merge requests found
...@@ -11,8 +11,9 @@ import Milter ...@@ -11,8 +11,9 @@ import Milter
import StringIO import StringIO
import time import time
import email import email
import sys
from socket import AF_INET, AF_INET6 from socket import AF_INET, AF_INET6
from Milter import parse_addr from Milter.utils import parse_addr
class myMilter(Milter.Base): class myMilter(Milter.Base):
...@@ -23,7 +24,7 @@ class myMilter(Milter.Base): ...@@ -23,7 +24,7 @@ class myMilter(Milter.Base):
# each connection runs in its own thread and has its own myMilter # each connection runs in its own thread and has its own myMilter
# instance. Python code must be thread safe. This is trivial if only stuff # instance. Python code must be thread safe. This is trivial if only stuff
# in myMilter instances is referenced. # in myMilter instances is referenced.
@noreply @Milter.noreply
def connect(self, IPname, family, hostaddr): def connect(self, IPname, family, hostaddr):
# (self, 'ip068.subnet71.example.com', AF_INET, ('215.183.71.68', 4720) ) # (self, 'ip068.subnet71.example.com', AF_INET, ('215.183.71.68', 4720) )
# (self, 'ip6.mxout.example.com', AF_INET6, # (self, 'ip6.mxout.example.com', AF_INET6,
...@@ -71,7 +72,7 @@ class myMilter(Milter.Base): ...@@ -71,7 +72,7 @@ class myMilter(Milter.Base):
## def envrcpt(self, to, *str): ## def envrcpt(self, to, *str):
@noreply @Milter.noreply
def envrcpt(self, recipient, *str): def envrcpt(self, recipient, *str):
rcptinfo = to,Milter.dictfromlist(str) rcptinfo = to,Milter.dictfromlist(str)
self.R.append(rcptinfo) self.R.append(rcptinfo)
...@@ -79,17 +80,17 @@ class myMilter(Milter.Base): ...@@ -79,17 +80,17 @@ class myMilter(Milter.Base):
return Milter.CONTINUE return Milter.CONTINUE
@noreply @Milter.noreply
def header(self, name, hval): def header(self, name, hval):
self.fp.write("%s: %s\n" % (name,hval)) # add header to buffer self.fp.write("%s: %s\n" % (name,hval)) # add header to buffer
return Milter.CONTINUE return Milter.CONTINUE
@noreply @Milter.noreply
def eoh(self): def eoh(self):
self.fp.write("\n") # terminate headers self.fp.write("\n") # terminate headers
return Milter.CONTINUE return Milter.CONTINUE
@noreply @Milter.noreply
def body(self, chunk): def body(self, chunk):
self.fp.write(chunk) self.fp.write(chunk)
return Milter.CONTINUE return Milter.CONTINUE
...@@ -125,6 +126,8 @@ class myMilter(Milter.Base): ...@@ -125,6 +126,8 @@ class myMilter(Milter.Base):
## === ## ===
def main(): def main():
socketname = "/tmp/pythonsock"
timeout = 600
# Register to have the Milter factory create instances of your class: # Register to have the Milter factory create instances of your class:
Milter.factory = myMilter Milter.factory = myMilter
flags = Milter.CHGBODY + Milter.CHGHDRS + Milter.ADDHDRS flags = Milter.CHGBODY + Milter.CHGHDRS + Milter.ADDHDRS
...@@ -133,7 +136,7 @@ def main(): ...@@ -133,7 +136,7 @@ def main():
Milter.set_flags(flags) # tell Sendmail which features we use Milter.set_flags(flags) # tell Sendmail which features we use
print "%s milter startup" % time.strftime('%Y%b%d %H:%M:%S') print "%s milter startup" % time.strftime('%Y%b%d %H:%M:%S')
sys.stdout.flush() sys.stdout.flush()
Milter.runmilter("pythonfilter",socketname,timeout) Milter.runmilter("test",socketname,timeout)
print "%s bms milter shutdown" % time.strftime('%Y%b%d %H:%M:%S') print "%s bms milter shutdown" % time.strftime('%Y%b%d %H:%M:%S')
if __name__ == "__main__": if __name__ == "__main__":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment