Since I am having problems with standard GAE's e-mail functionality when e-mail subject is UTF-8 encoded, I am trying to handle it manually:
msg_encoding = self.request.headers['Content-Type'].split('charset=')[1] # message/rfc822; charset=UTF-8
msg = email.message_from_string(self.request.body)
if msg:
logging.debug(msg.get_content_charset()) # None
logging.debug(msg['to'])
logging.debug(msg['from'])
logging.debug(msg['Subject'].decode(msg_encoding))
Do I do it correctly? Should I decode Subject? Or is it done by email parser automatically?
The following simplified code (text/plain only, no attachments) works well for me: