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)
74 self.fp = StringIO.StringIO()
75 self.canon_from =
'@'.join(parse_addr(mailfrom))
76 self.fp.write(
'From %s %s\n' % (self.canon_from,time.ctime()))
77 return Milter.CONTINUE
82 def envrcpt(self, to, *str):
84 self.R.append(rcptinfo)
86 return Milter.CONTINUE
90 def header(self, name, hval):
91 self.fp.write(
"%s: %s\n" % (name,hval))
92 return Milter.CONTINUE
97 return Milter.CONTINUE
100 def body(self, chunk):
102 return Milter.CONTINUE
106 msg = email.message_from_file(self.fp)
107 self.setreply(
'250',
'2.5.1',
'Grokked by pymilter')
110 self.addrcpt(
'<%s>' %
'spy@example.com')
116 return Milter.CONTINUE
120 return Milter.CONTINUE
125 logq.put((msg,self.id,time.time()))
132 print "%s [%d]" % (time.strftime(
'%Y%b%d %H:%M:%S',time.localtime(ts)),id),
134 for i
in msg:
print i,
140 bt = Thread(target=background)
142 socketname =
"/home/stuart/pythonsock"
145 Milter.factory = myMilter
146 flags = Milter.CHGBODY + Milter.CHGHDRS + Milter.ADDHDRS
147 flags += Milter.ADDRCPT
148 flags += Milter.DELRCPT
149 Milter.set_flags(flags)
150 print "%s milter startup" % time.strftime(
'%Y%b%d %H:%M:%S')
155 print "%s bms milter shutdown" % time.strftime(
'%Y%b%d %H:%M:%S')
157 if __name__ ==
"__main__":