Just went through a little hell robustifying my inbound mail handler, and
though some of you would find this interesting.
1) Subject lines can contain line breaks. Who knew?
It appears that subject lines can be word-wrapped in transit, and the inbound
mail handler leaves them wrapped. I was parsing the subject with a RE, and, of
course, my .'s didn't match the \n, which led to various problems.
My fix: subject = re.sub('[\n\r]*', '', message.subject)
2) Decoded bodies are not necessarily valid unicode.
I will not pretend that I have the slightest understanding of how strings work
in Python. Coming from the land of java, I just find the whole thing a
confusing mess.
Anyway, what I learned is that if you have a db.TextProperty() and you expect
to stuff the result of payload.decode() into it, it might not work. The error
I got was:
'ascii' codec can't decode byte 0xbe in position 4228: ordinal not in
range(128)
After trying a dozen different incantations to try to sanitize the message so I
could get *something* that perhaps a human could read, I finally found this one:
msg.message = allBodies.decode('ascii','replace').encode('ascii',
'backslashreplace')
I have no idea what that means, but it works. No exception was generated, and
the message looks right to me.
-Joshua
--
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=.