15 from socket
import AF_INET, AF_INET6
18 from multiprocessing
import Process
as Thread, Queue
20 from threading
import Thread
21 from Queue
import Queue
23 logq = Queue(maxsize=4)
34 def connect(self, IPname, family, hostaddr):
39 self.port = hostaddr[1]
40 if family == AF_INET6:
41 self.flow = hostaddr[2]
42 self.scope = hostaddr[3]
49 self.receiver = self.getsymval(
'j')
50 self.log(
"connect from %s at %s" % (IPname, hostaddr) )
52 return Milter.CONTINUE
56 def hello(self, heloname):
59 self.log(
"HELO %s" % heloname)
60 if heloname.find(
'.') < 0:
62 self.setreply(
'550',
'5.7.1',
'Sheesh people! Use a proper helo name!')
65 return Milter.CONTINUE
68 def envfrom(self, mailfrom, *str):
72 self.user = self.getsymval(
'{auth_authen}')
73 self.log(
"mail from:", mailfrom, *str)
77 self.fp = StringIO.StringIO()
78 self.canon_from =
'@'.join(parse_addr(mailfrom))
79 self.fp.write(
'From %s %s\n' % (self.canon_from,time.ctime()))
80 return Milter.CONTINUE
85 def envrcpt(self, to, *str):
87 self.R.append(rcptinfo)
89 return Milter.CONTINUE
93 def header(self, name, hval):
94 self.fp.write(
"%s: %s\n" % (name,hval))
95 return Milter.CONTINUE
100 return Milter.CONTINUE
103 def body(self, chunk):
105 return Milter.CONTINUE
109 msg = email.message_from_file(self.fp)
112 self.addrcpt(
'<%s>' %
'spy@example.com')
118 return Milter.CONTINUE
122 return Milter.CONTINUE
127 logq.put((msg,self.id,time.time()))
134 print "%s [%d]" % (time.strftime(
'%Y%b%d %H:%M:%S',time.localtime(ts)),id),
136 for i
in msg:
print i,
142 bt = Thread(target=background)
144 socketname =
"/home/stuart/pythonsock" 147 Milter.factory = myMilter
148 flags = Milter.CHGBODY + Milter.CHGHDRS + Milter.ADDHDRS
149 flags += Milter.ADDRCPT
150 flags += Milter.DELRCPT
151 Milter.set_flags(flags)
152 print "%s milter startup" % time.strftime(
'%Y%b%d %H:%M:%S')
157 print "%s bms milter shutdown" % time.strftime(
'%Y%b%d %H:%M:%S')
159 if __name__ ==
"__main__":