[Baypiggies] code review or tool suggestion

Simeon Franklin simeonf at gmail.com
Tue Nov 24 21:05:17 CET 2009


Hey all -

I'm messing with a problem that isn't my forte and thought I'd solicit
some advice. Despite not really liking the sysadmin hat I'm managing a
server for a real estate office whose disk space has gotten tight due
to stored mail. Real estate agents like to schlep around 20Mb
documents via email - who knew?

Anyway I started to implement some policies to reclaim a bit of space
- one of which was deleting large attachments from old files and sent
files. I haven't been able to find a tool that will do this
automatically - the only thing I could find was a tool written in Perl
by Dan Born last updated back in 2005 (http://danborn.net/delatt/) and
I couldn't actually get it to work.

I made my usual decision (try to write a new tool in Python rather
than trying to debug Perl). delatt is only about 300 lines of perl and
supports mbox as well as maildir, plus uses regexes to parse out the
mime attachments - I figured it wouldn't take much work despite never
having used the email module in the standard lib.

The result is pydelatt (see http://gist.github.com/242055). If anyone
knows of a linux console tool that does what I'm trying to do (strip
attachments from emails in maildir format) I'll take any suggestions.
More to the point of Baypiggies though - if anyone wants to take a
look at my code I'd be happy for any pointers.

The email module in the stdlib seems to have changed quite a bit
between the python versions I tested it on (2.4 and 2.5) and generally
the API seemed a little clunky to me. Mime messages can be parsed into
a tree structure but the .walk() method of the Message class didn't
walk all the multipart nodes of the tree as I expected. Also I
couldn't see a built in way of removing nodes so I ended up rebuilding
the tree of the parent node of the attachment I wanted to delete...
What I have works (I ran it on about 100 Gigs of email without any
problems) but I wondered if I'm missing something...

-regards
Simeon Franklin


More information about the Baypiggies mailing list