[Pymilter] Re: simple email list in python

Stuart D. Gathman stuart at bmsi.com
Fri Jan 18 13:21:14 EST 2008


On Mon, 14 Jan 2008, Mark wrote:

> so can i start reading the emails to python from that mta
> 
> How to set this up to read messages from the mta

In pymilter, you collect the email in header and body.

For instance:

  def envfrom(self,f,*str):
    self.log("mail from",f,str)
    self.fp = StringIO.StringIO()	# or use temp file
    self.bodysize = 0
...

  def header(self,name,val):
    ...
    self.fp.write("%s: %s\n" % (name,val))    # add header to buffer
    return Milter.CONTINUE

  def eoh(self):
    self.fp.write("\n")	# blank line after header
    ...
    return Milter.CONTINUE

  def body(self,chunk):         # copy body to temp file
    self.fp.write(chunk)      # IOError causes TEMPFAIL in milter
    self.bodysize += len(chunk)
    return Milter.CONTINUE

  def eom(self):
    self.fp.seek(0)
    msg = mime.message_from_file(self.fp)
    ...

-- 
	      Stuart D. Gathman <stuart at bmsi.com>
    Business Management Systems Inc.  Phone: 703 591-0911 Fax: 703 591-6154
"Confutatis maledictis, flammis acribus addictis" - background song for
a Microsoft sponsored "Where do you want to go from here?" commercial.





More information about the Pymilter mailing list