summaryrefslogtreecommitdiffstats
path: root/apps/patchwork
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2008-10-23 14:22:33 +1100
committerJeremy Kerr <jk@ozlabs.org>2008-10-23 14:22:33 +1100
commitd45218b2e3894211e11313820bea9f59677c4bf2 (patch)
tree09968c074fbd82ad55fd21b1385092bcc577aa82 /apps/patchwork
parent64b4f583066dc0757a82257d1dd2c97d451ce7d4 (diff)
downloadpatchwork-d45218b2e3894211e11313820bea9f59677c4bf2.tar.bz2
patchwork-d45218b2e3894211e11313820bea9f59677c4bf2.tar.xz
[parser] Handle patches with no content charset defined
If we don't have an incoming charset defined, assume utf-8. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'apps/patchwork')
-rwxr-xr-xapps/patchwork/bin/parsemail.py10
-rw-r--r--apps/patchwork/tests/patchparser.py11
2 files changed, 19 insertions, 2 deletions
diff --git a/apps/patchwork/bin/parsemail.py b/apps/patchwork/bin/parsemail.py
index 9aaaa9d..772728e 100755
--- a/apps/patchwork/bin/parsemail.py
+++ b/apps/patchwork/bin/parsemail.py
@@ -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
diff --git a/apps/patchwork/tests/patchparser.py b/apps/patchwork/tests/patchparser.py
index e508dc0..3518432 100644
--- a/apps/patchwork/tests/patchparser.py
+++ b/apps/patchwork/tests/patchparser.py
@@ -83,6 +83,17 @@ class UTF8InlinePatchTest(InlinePatchTest):
content_encoding = self.patch_encoding)
(self.patch, self.comment) = find_content(self.project, email)
+class NoCharsetInlinePatchTest(InlinePatchTest):
+ """ Test mails with no content-type or content-encoding header """
+ patch_filename = '0001-add-line.patch'
+
+ def setUp(self):
+ self.orig_patch = read_patch(self.patch_filename)
+ email = create_email(self.test_comment + '\n' + self.orig_patch)
+ del email['Content-Type']
+ del email['Content-Transfer-Encoding']
+ (self.patch, self.comment) = find_content(self.project, email)
+
class SignatureCommentTest(InlinePatchTest):
patch_filename = '0001-add-line.patch'
test_comment = 'Test comment\nmore comment'