a python script which will parse an email message

chuck amadi chuck.amadi at ntlworld.com
Thu May 27 21:11:41 EDT 2004


any python script which will parse an email messages into a file to poplulate a database.

Im trying with UnixMailbox but I cant figure out howto abstract the all email data messages to a file .

## mailbox-Survey.py
#!/usr/bin/env python
import mailbox,rfc822

                                                                                                                           # Open Users Mailbox
mb = mailbox.UnixMailbox(open("/var/spool/mail/chucka"))
                                                                                                                            
while 1:
    msg = mb.next()
    if not msg:
        break
    for k, v in msg.items():
        print k, "=", v
    body = msg.fp.read()

## built-in function len gives you the length of a list.
    print len(body), "bytes in body"

# Abstract email messages into a tmp file

#mb.next()
#mb = ("/var/spool/mail/chucka")
#mb = sys.stdin

Cheers

Chuck






More information about the Python-list mailing list