Permalink
Browse files

Cope with unicode issues from email subject lines

  • Loading branch information...
1 parent 4f89f94 commit 5c82348b202a854824effe2ac582e484c661fe9e @lovett committed Nov 19, 2010
Showing with 7 additions and 3 deletions.
  1. +7 −3 appengine/models.py
View
10 appengine/models.py
@@ -225,16 +225,20 @@ def formatEmail(self):
sender = re.sub("[><]", "", sender)
try:
- encoded_subject = decode_header(message.subject)
+ # The unicode() function is used to handle errors such as:
+ # 'ascii' codec can't decode byte 0x92 in position 59: ordinal not in range(128)
+ # This error was observed in a email subject that used a curly apostrophe.
+ encoded_subject = decode_header(unicode(message.subject, errors="ignore"))
subject = encoded_subject[0][0]
encoding = encoded_subject[0][1]
if encoding:
subject = subject.decode(encoding)
if not isinstance(subject, unicode):
subject = unicode(subject)
-
+ except UnicodeDecodeError:
+ subject = "(subject not available)"
except AttributeError:
- subject = "no subject"
+ subject = "(no subject)"
self.message_for_web = "E-mail has arrived from %s" % sender
self.message_for_im = "E-mail has arrived from %s:\n%s" % (sender, subject)

0 comments on commit 5c82348

Please sign in to comment.