import email, logging
# BTW, why do I need to import email? My code is not using it directly?

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import mail_handlers
from google.appengine.api import mail

class MailHandler(mail_handlers.InboundMailHandler):
	def receive(self, message):
		logging.info("Received email from %s" % message.sender)
		plaintext = message.bodies(content_type='text/plain')
		
		for text in plaintext:
			logging.info("Body is %s" % text[0])
		
def main():
	logging.getLogger().setLevel(logging.DEBUG)
	logging.debug("Test script")

	app = webapp.WSGIApplication([('/.*', MailHandler)], debug=True)
	run_wsgi_app(app)

if __name__ == '__main__':
	main()

###==========================

Traceback (most recent call last):
  File "C:\Program\Google\appengine\google\appengine\ext\webapp\__init__.py", line 509, in __call__
    handler.post(*groups)
  File "C:\Program\Google\appengine\google\appengine\ext\webapp\mail_handlers.py", line 58, in post
    self.receive(mail.InboundEmailMessage(self.request.body))
  File "C:\Program\Google\appengine\google\appengine\api\mail.py", line 526, in __init__
    self.update_from_mime_message(mime_message)
  File "C:\Program\Google\appengine\google\appengine\api\mail.py", line 1060, in update_from_mime_message
    mime_message = _parse_mime_message(mime_message)
  File "C:\Program\Google\appengine\google\appengine\api\mail.py", line 211, in _parse_mime_message
    return email.message_from_file(mime_message)
  File "C:\Program\Python25\lib\email\__init__.py", line 66, in message_from_file
    return Parser(*args, **kws).parse(fp)
  File "C:\Program\Python25\lib\email\parser.py", line 68, in parse
    data = fp.read(8192)
AttributeError: Message instance has no attribute 'read'

###================================

# From google appengine/api/mail.py:

def _parse_mime_message(mime_message):
  """Helper function converts a mime_message in to email.Message.Message.

  Args:
    mime_message: MIME Message, string or file containing mime message.

  Returns:
    Instance of email.Message.Message.  Will return mime_message if already
    an instance.
  """
  if isinstance(mime_message, email.Message.Message):
    return mime_message
  elif isinstance(mime_message, basestring):
    return email.message_from_string(mime_message)
  else:
    return email.message_from_file(mime_message)