a python script which will parse an email message

C

chuck amadi

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
 
W

William Park

chuck amadi said:
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 .

Can you rephrase this with some example of "input" and "output" you
want? As is, emails are already in a file, so there is no need to parse
it to a file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top