The lib email parse problem...

叮叮当当 guotie.9 at gmail.com
Tue Aug 29 04:59:10 EDT 2006


this is not enough.

when a part is mulitpart/alternative, i must find out which sub part i
need, not all the subparts. so i must know when the alternative is
ended.


John Machin 写道:

> 叮叮当当 wrote:
> > hi, all
> >
> > when a email body consist with multipart/alternative,  i must know when
> > the boundary ends to parse it,
> >
> > but the email lib have not provide some function to indicate the
> > boundary end, how to solve it ?
>
> By reading the manual.
> http://docs.python.org/lib/module-email.Message.html
>
> You don't need to concern yourself with boundaries -- a high-level
> parser is provided.
>
> Here's a simple example:
>
> This script:
>
> msg_text = """
> [snip -- message is some plain text plus an attached file]
> """
> import email
> pmsg = email.message_from_string(msg_text)
> for part in pmsg.walk():
>     print part.get_content_type(), part.get_filename("<<NoFileName>>")
>
> produced this output:
>
> multipart/mixed <<NoFileName>>
> text/plain <<NoFileName>>
> application/octet-stream Extract.py
>
> For a more comprehensive example, see
> http://docs.python.org/lib/node597.html
> 
> HTH,
> John




More information about the Python-list mailing list