Hi Arjun, Unfortunately, this is a difficult problem. Gmail goes to a great deal of trouble to get this right.
The de-facto standard for text emails, dating back to the early days of email, is for replies to be included with each line prefixed with a "> ". Similarly, lines are broken at 78 characters. You'll have to figure out which bits are replies, and un-munge linebreaks yourself - that, or use the HTML part of the email, if available. :) -Nick Johnson On Thu, Feb 11, 2010 at 12:30 AM, pythono <[email protected]> wrote: > Hey folks, > > So I set up a couple of my apps (python) to receive email. The > tutorial on the appengine developer's guide is not too clear on > decoding emails. My problem is being able to get strictly the text of > the most recent email in a thread. Currently I'm decoding the 1st > plain-text body of a received email, but this seems to include all the > emails in the thread (shows up under the "show quoted text" link in > gmail). > > Here is the code I'm using: > > bodies = message.bodies(content_type='text/plain') > decoded = False > for body in bodies: > if not decoded: > decoded_body = body[1].decode() > decoded = True > > Also there seem to be endlines where there shouldn't be. Do email > clients like gmail automatically add them? > > Basically I just want the text of the email with only the endlines > explicitly entered by the message sender. Seems simple enough.. > Currently I'm resorting to starting with the 'text/html' bodies and > using the following hack: > > decoded_body.split('<br><br><div class="gmail_quote">') > text = decoded_body[0] > > It works for gmail, but obviously won't for any other client. > > Arjun > > -- > You received this message because you are subscribed to the Google Groups > "Google App Engine" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<google-appengine%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/google-appengine?hl=en. > > -- Nick Johnson, Developer Programs Engineer, App Engine Google Ireland Ltd. :: Registered in Dublin, Ireland, Registration Number: 368047 -- You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.
