a python script which will parse an email message

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • chuck amadi

    a python script which will parse an email message

    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.UnixMai lbox(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



  • William Park

    #2
    Re: a python script which will parse an email message

    chuck amadi <chuck.amadi@nt lworld.com> wrote:[color=blue]
    > 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 .[/color]

    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, <opengeometry@y ahoo.ca>

    Comment

    Working...