POP3 Filter

Tim Williams listserver at tdw.net
Sat Oct 9 17:07:56 CEST 2004


"Ross Boylan" <RossBoylan at stanfordalumni.org> wrote in message
news:pan.2004.10.09.04.31.10.107762 at stanfordalumni.org...
> On Fri, 24 Sep 2004 11:11:43 -0700, crystal1 wrote:

> > Has anyone created a python script that listens on the default POP3 port
> > for incoming mail, kills certain messages based on a criteria, and
> > forwards the output to a non-standard port the POP3 server is listening
on?

POP3 doesn't listen for incoming email or forward/send email,  SMTP does
that part..    POP3 servers listen for mailbox access requests

> > Upon recieving requests from a sender, the script would transparently
> > forward traffic to the off port unless a violating condition is
encountered.
> >
> > I'd like to use the listening python script to check for a correct 'to:'
> >   address format, attachment size limit, etc.
>
> It's doable, and has been done.  For example, I use mailfilter (though
> I don't think it's in python).
>
> POP3 does allow you to kill individual messages before downloading
> them.  The problem is that, if you want to avoid downloading them, you
> can't get too much info.  I think it would be possible to be cleverer
> than mailfilter, since (at least some) POP servers can give you the
> start of a message without giving you the whole thing.

Yes, this is a problem when filtering pop3 mail,  you often need to download
each email into the filter *before* being able to run any filters on it.
Often,  using plain old mailbox rules might make more sense if the checks
are simple.

There are such things as POP3 proxying filters,   where the mail client asks
*the proxy* for its email,   the proxy then fetches the email from the
mailbox and checks it before passing it to the client.  However,  this is
done in real-time and whilst modifying the email (marking it as spam, or
removing the content ) wouldn't cause problems,  if the proxy decides not to
pass an email to the client,  the client might error.

Have a look at popf.py (proxying spam filter) at
http://christophe.delord.free.fr/en/popf/index.html  and spambayes (spam
filters and clients) at http://spambayes.sourceforge.net/    They might both
be able to explain all the technical issues you will come up against.

You may also consider a slightly different approach,   you can use a mail
server that allows you to script your own checks.   That way you can get
many more built in features,  plus you are able to implement the checks you
need

I have an implementation in one organisation that uses VPOP3 (albeit an
older version) from www.pscs.co.uk     It accepts incoming SMTP and also
downloads from multiple pop3 mailboxes,  then calls my scripts (some are
python) as pre-processors (virus, spam, spf, rbl, header validation checks
etc).  Once the mail is accepted, it is handled in the way that org  needs
(distribution and mailing lists,  local mailboxes,  forwarding to other
addresses and other servers on (non-)standard ports.etc

HTH




More information about the Python-list mailing list