]> git.ozlabs.org Git - patchwork/blobdiff - apps/patchwork/bin/parsemail.py
[parser] Handle patches with no content charset defined
[patchwork] / apps / patchwork / bin / parsemail.py
index 9aaaa9d9421a87405d566a8b691d11e324d2886a..772728e41e82ffbba9e2d42a54ca17004652e3bf 100755 (executable)
@@ -138,10 +138,16 @@ def find_content(project, mail):
             continue
 
         payload = part.get_payload(decode=True)
-        if not isinstance(payload, unicode):
-            payload = unicode(payload, part.get_content_charset())
+        charset = part.get_content_charset()
         subtype = part.get_content_subtype()
 
+        # if we don't have a charset, assume utf-8
+        if charset is None:
+            charset = 'utf-8'
+
+        if not isinstance(payload, unicode):
+            payload = unicode(payload, charset)
+
         if subtype in ['x-patch', 'x-diff']:
             patchbuf = payload