How can I get text of the body (payload) of an email?
jeffrey at fro.man
Sat Oct 16 17:06:53 CEST 2004
andrew blah wrote:
> I want to get the text of the body - every character from the new line
> after the headers until the end of the message.
> My objective is to do an SHA hash on the body text so the get_payload
> method isn't what I am after.
Funny, I recently undertook the same task. Here's my solution:
msg = email.message_from_string(foo)
x = sha.new()
for line in email.Iterators.body_line_iterator(msg):
hash = x.digest()
This very cool iterator returns every body line, but skips all the headers,
including the headers present in each sub-part of the email. If you only
want plain text parts, you might combine this iterator with
More information about the Python-list