[lug] Splitting mail file

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


Check out the Python library mimetools package docs. (www.python.org and
follow the documentation link.) The mimetools package can split the MIME
attachments and decode them for you.

-----Original Message-----
From: Ken Weinert [mailto:kenw at ihs.com]
Sent: Friday, August 24, 2001 11:52 AM
To: lug at lug.boulder.co.us
Subject: Re: [lug] Splitting mail file


Thanks! What would I have to add to split any attachements into their
own file? :)

No need to reply if it's going to take a bunch of time - just getting
this much is a great help.

* Riggs, Rob (RRiggs at doubleclick.net) [010824 17:44]:
> 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?
> 
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug

-- 
Ken Weinert   kenw at ihs.com 303-858-6956 (V) 303-705-4258 (F)
GnuPG KeyID: 9274F1CE           GnuPG available at http://www.gnupg.org/
GnuPG Key Fingerprint: 1D87 3720 BB77 4489 A928  79D6 F8EC DD76 9274 F1CE
Excess on occasion is exhilarating. It prevents moderation from
acquiring the deadening effect of a habit. --Somerset Maugham




More information about the LUG mailing list