I've been working on a new package for dealing with message
objects, including mime messages. Mostly this is for use in
Mailman, but they will be generally useful. I want to
eventually replace essentially what's in rfc822.py,
multifile.py, mimetools.py, and taking some of the best
ideas of stuff like mimecntl.py.
The basic idea is that I've separated the object model from
parsing and generating. That way you can drop in different
parsers or generators, and you can manipulate the object
model independently. Conceptually a message object has a
set of headers and a payload. The payload can be just a
string or a message object, or a list of those. Then you
can add/remove headers with semantics similar (but slightly
different) to rfc822, and you can add/remove payload
You pass a root message object to the generator, and it
spits out text suitable for delivery via smtplib.py. It
knows that message objects w/ list payloads are multiparts.
The parser on the other hand, takes text and spits out a
message object tree. parsing->object tree->generator is
For composition, there is a base class that knows about
content-type: headers, and subclasses for common subtypes
(image/*, text/*, etc.). Cool things you can do with this
are: take a mime message, find the image subparts, rip them
out and post them to a webdav server, replacing the image/*
part with a text/* part that contains just a url to the
image; throw away all binary subparts, reordering the
containing multipart, etc. etc.
It's not complete right now and I won't be able to post
anything until I get back my internet connection, but stay
tuned. It'll be distrib'd as a distutils package so it'l be
easy to install. I'm just not sure what to call it (always
the most important thing to decide. :) The two I've come up
with so far are "pantomime" and "mimeo".