email package - how to get message body
Gerhard Häring
gh at ghaering.de
Mon May 12 07:20:06 EDT 2003
Mario Premke wrote:
> Hi,
> possibly a stupid question, but anyhow, I can not find a method in the
> email package to get an email body ( I mean the text seperated from
> the header by one blank line). I can parse an email file so that I
> have the object model of an email and play around with it (alter
> header properties, etc. ) - what I wonder now is if there is a method
> which returns the simple text message ???
Maybe something like this:
#v+
import email
def get_plain_body(s):
msg = email.message_from_string(s)
assert not msg.is_multipart()
return unicode(msg.get_payload(), msg.get_content_charset())
#v-
get_payload() is the key method here.
-- Gerhard
More information about the Python-list
mailing list