[Tutor] Working with Email question [new 'email' module in Python 2.2]

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Sat, 23 Feb 2002 13:22:30 -0800 (PST)

On Sat, 23 Feb 2002, Joel Ricker wrote:

> Wow, things have changed since I've last worked with Python which was
> in 1.5(.2?).
> As a warmup excercise to get back into the swing of things, I want to
> write a spam filter.  I'm pretty liberal with my e-mail address, which
> is great because people can find me but the drawback is of course that
> so can all the spammers in the world :(

Hi Joel,

(If you'd like to use something "out of the box", you may want to look at


There are a lot of subtle issues involved in writing a spam filter, and
the SpamAssassin folks apparently have been thinking really hard about
those issues.  It's not Python, but it's not bad either.  *grin*)

> Digging around I found the libraries for working with MIME data that
> seems to be related to working with email but they seem to be more for
> working with MIME files (building up files rather that analyzing
> already created emails).  Is there a library already for working with
> messages?  Something like given the text of a message, you can easily
> extract the body, to: lines, etc, or am I'm going to have to write one
> myself?  Just wanted to check before I re-invent anything.

Yes, we can use the rfc822 library... wait, wait... [flipping through the
library documentation]


Wow!  I didn't notice this module before.  There's a new 'email' module
that was introduced in Python 2.2, and it looks interesting.  Does anyone
have any experiement with the 'email' module?  This might be what you're
looking for; it looks like it handles email parsing.

Good luck!