[lug] Splitting mail file

Riggs, Rob RRiggs at doubleclick.net
Fri Aug 24 11:42:24 MDT 2001


Yeah -- Python! :-)

The following script accepts a mailbox filename on the command line and
splits each message into files named "1", "2", "3", etc. within the current
directory.


#!/usr/bin/python

import sys, os

from mailbox import UnixMailbox

mboxFile = open(sys.argv[1])
mbox = UnixMailbox(mboxFile)

count = 1

while 1:
        mesg = mbox.next()
        if not mesg: break
        fp = open('%d' % count, 'w')
        for line in mesg.headers:
                fp.write(line)
        fp.write('\n')
        fp.write(mesg.fp.read())
        fp.close()
        count = count + 1

-----Original Message-----
From: Ken Weinert [mailto:kenw at ihs.com]

Any know of any utilities off hand that will take a mail spool and split
it so that each message gets put into its own file?




More information about the LUG mailing list