parsing emails and saving attached application files
Andrew Gould
andrewgould at yahoo.com
Mon Jun 9 17:49:09 EDT 2003
I figured this one out:
1. Open a file in writing and binary mode.
2. Decode the payload.
3. Write the decoded payload to the binary file.
Thanks,
Andrew
--- Andrew Gould <andrewgould at yahoo.com> wrote:
> As a learning exercise I'm trying to parse my email
> messages. (The next step will be to save the
> components in a database.) How do I save attached
> application files separately from the email?
>
> In the script below, the email message contains some
> text and 2 excel files. Variable payload1a will give
> me the contents of of Book1.xls as a string. How do
> I
> save the contents as an Excel file (rather than a
> text
> file with unreadable content)?
>
> # begin script
> import email
>
> msgfile = open('a:/testmsg','r')
> msg = email.message_from_file(msgfile)
>
> payload1 = msg.get_payload(i=1,decode=0)
> payload1a = payload1.get_payload(i=None,decode=0)
> # end script
>
> Any help would be greatly appreciated.
>
> Thanks,
>
> Andrew
>
> --
> http://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list