By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,818 Members | 1,313 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,818 IT Pros & Developers. It's quick & easy.

need to strip stuff off email

P: n/a
hey there,
i have a script that retrieves my email, but i need it to
be able to strip all the stuff off except the body (the message itself)
so i can later write it to a text file.

anyone know how to accomplish this?
thanks
Jul 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"nephish" <ne*****@xit.net> wrote in message
news:ma**************************************@pyth on.org...
hey there,
i have a script that retrieves my email, but i need it to
be able to strip all the stuff off except the body (the message itself)
so i can later write it to a text file.

anyone know how to accomplish this?
thanks


See the example at the end of the email package documentation.

John Roth

Jul 19 '05 #2

P: n/a
nephish wrote:
i have a script that retrieves my email, but i need it to
be able to strip all the stuff off except the body (the message itself)
so i can later write it to a text file.

anyone know how to accomplish this?


Without more context and info, I think the best one can say at this
stage is "use the email" module.

Have you tried that? Whether you have or not, sample code would help a
lot in understanding what you're doing, or perhaps more description
about your platform, what form the mail message is in, maybe an example
of the before and after state of the message, and such things...

-Peter
Jul 19 '05 #3

P: n/a

"nephish" <ne*****@xit.net> wrote in message
news:ma**************************************@pyth on.org...
hey there,
i have a script that retrieves my email, but i need it to
be able to strip all the stuff off except the body (the message itself)
so i can later write it to a text file.

anyone know how to accomplish this?
thanks


The body is: The rest of the email after "the first blank line after the
subject header". In practice it is the first blank line.

If you get the message into a string it can sometimes be easier to just
RSPLIT the string at '\r\n\r\n', if the message is in a list then the body
= '\r\n'.join(msg[x:]) where x = that blank line +1 , that way if you
don't need any of the header info, you don't have to decode the message and
rebuild it in a file.

if you *are* using the email module, eg

msg = email.message_from_file(a_file)

then rsplit the msg to get the same result.

As someone will no doubt point out, some emails are broken and parts of
the headers will end up in the body (even when you view the email it in a
client), this is very rare though.


Jul 19 '05 #4

P: n/a
----- Original Message -----
From: "Tim Williams" <li********@tdw.net>
To: <py*********@python.org>
Sent: Wednesday, June 22, 2005 10:48 AM
Subject: Re: need to strip stuff off email


"nephish" <ne*****@xit.net> wrote in message
news:mailman.723.1119399951.10512.py*********@pyth on.org...
hey there,
i have a script that retrieves my email, but i need it to
be able to strip all the stuff off except the body (the message itself) so i can later write it to a text file.

anyone know how to accomplish this?
thanks

The body is: The rest of the email after "the first blank line after the
subject header". In practice it is the first blank line.

If you get the message into a string it can sometimes be easier to just
RSPLIT the string at '\r\n\r\n', if the message is in a list then the

body = '\r\n'.join(msg[x:]) where x = that blank line +1 , that way if you
don't need any of the header info, you don't have to decode the message and rebuild it in a file.

if you *are* using the email module, eg

msg = email.message_from_file(a_file)

then rsplit the msg to get the same result.

As someone will no doubt point out, some emails are broken and parts of
the headers will end up in the body (even when you view the email it in a
client), this is very rare though.


Ah, trying to do anything before my first cup of coffee in the morning is
always a mistake - substitute RSPLIT with LSPLIT for both occurrences above
!!! :(

Jul 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.