[lug] Splitting mail file

Ken Weinert kenw at ihs.com
Fri Aug 24 11:52:27 MDT 2001


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 240 bytes
Desc: not available
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20010824/277436f0/attachment.pgp>


More information about the LUG mailing list