Re: need to strip stuff off email
- Original Message - From: "Tim Williams" <[EMAIL PROTECTED]> To: Sent: Wednesday, June 22, 2005 10:48 AM Subject: Re: need to strip stuff off email > > > > "nephish" <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED] > > > 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 !!! :( -- http://mail.python.org/mailman/listinfo/python-list
Re: need to strip stuff off email
> "nephish" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > 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. -- http://mail.python.org/mailman/listinfo/python-list
Re: need to strip stuff off email
"nephish" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > 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 -- http://mail.python.org/mailman/listinfo/python-list
need to strip stuff off email
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 -- http://mail.python.org/mailman/listinfo/python-list