Extract MIME from incoming mail extract_mime - shell wrapper extract_mime.py - python script The extract_mime.py program uses mimetools and multifile lib modules, which require that input file supports random access (seek). Usually MTA (sendmail) passes mail to stdin (which is not seekable). To work around this I wrote a shell wrapper that chdir to a work directory, removes temp file (if there are any), saves stdin to a real file and runs python script. Python script tests whether the message is really MIME message (if not it aborts - you need some tweaking here if you want to get simple mail), splits incoming message into parts and saves is as files. The first two parts of any MIME message are MIME warning (for MIME-incapable MUAs) and message text. My script skips both - I don't need it. Again, it is easy to teach my program to caught message text. After these two parts there are attachments. Python script extracts these attachments and saves it under original names (if mail message provides ones; if there are no filenames my scripts generates ones in form of "outfile%d", where %d is ordinal number of attachment. This lead to a problem if you pass many mail messages to the program at once - some outfiles could overwrite others). To use these programs you need to teach your MTA to "send" mail to the shell wrapper. For sendmail and compatibles you need to edit /etc/aliases (or /etc/mail/aliase or such) and run newaliases. Add the following line to /etc/aliases: robot: "| /path/to/extract_mime" Now all messages sent to robot@your.host.domain will be passed to extract_mime! Usually MTA is running under user root (I am talking about Unix systems. If you are using other system as mail server - you are in big trouble :). To make your program more secure, run them under different user: robot: "| su umail -c /path/to/extract_mime". Make sure the directory where the program writes files is readable and writeable. For MTAs that are not running as root you either agree to run these program under mail user (whatever) or you may change the user. Just compile setuid wrapper (there is nice setuid-prog.c in python distribution), make it setuid (setgid) and run via /etc/aliases: robot: "| /path/to/setuid_wrapper" Don't forget to run newaliases after changing the aliases file.