By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,350 Members | 1,228 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,350 IT Pros & Developers. It's quick & easy.

a python script which will parse an email message

P: n/a
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

Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
chuck amadi <ch*********@ntlworld.com> wrote:
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.

--
William Park, Open Geometry Consulting, <op**********@yahoo.ca>
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.