Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(783)

Unified Diff: codereview/views.py

Issue 6852059: Proper handling of incoming mail without charset and encoding. (Closed)
Patch Set: Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/test_incomingmail.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: codereview/views.py
===================================================================
--- a/codereview/views.py
+++ b/codereview/views.py
@@ -3946,6 +3946,13 @@
# As a workaround we try to decode the payload ourselves.
if payload.encoding == '8bit' and payload.charset:
body = payload.payload.decode(payload.charset)
+ # If neither encoding not charset is set, but payload contains
+ # non-ASCII chars we can't use payload.decode() because it returns
+ # payload.payload unmodified. The later type cast to db.Text fails
+ # with a UnicodeDecodeError then.
+ elif payload.encoding is None and payload.charset is None:
+ # assume utf-8 but set replace flag to go for sure.
+ body = payload.payload.decode('utf-8', 'replace')
else:
body = payload.decode()
break
« no previous file with comments | « no previous file | tests/test_incomingmail.py » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b