The lib email parse problem...

Fredrik Lundh fredrik at pythonware.com
Tue Aug 29 05:31:54 EDT 2006


"????" wrote:

> the plain text is abcd, and the alternative content type is text/html,
> i should prefer explain the html content, and i must not explaint the
> two part ,so i want to get the boundary end.

so use the email module:

    import email

    message_text = "..."

    message = email.message_from_string(message_text)

    for part in message.walk():
        if part.get_content_type() == "text/html":
            print "html is", repr(part.get_payload())

(the message instances either contains a payload or sequence of submessages;
use message.is_multipart() to see if it's a sequence or not.  the walk() method
used in this example loops over all submessages, in message order).

</F> 






More information about the Python-list mailing list