]> git.ozlabs.org Git - patchwork/commitdiff
[encoding] Don't output patch mbox as quoted-printable
authorJeremy Kerr <jk@ozlabs.org>
Tue, 7 Oct 2008 02:32:27 +0000 (13:32 +1100)
committerJeremy Kerr <jk@ozlabs.org>
Tue, 7 Oct 2008 02:32:27 +0000 (13:32 +1100)
git-am doesn't like quoted-printable, so output mbox files as raw 7- or
8-bit mbox files. This means we have to create a new MIMEText class, so
that the content isn't automatically QP-encoded on __init__().

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
apps/patchwork/models.py
apps/patchwork/tests/encodings.py

index 3cfbacdacdd7dd75065dba2125ab9c24d55a3019..02fb8b4a4e55fc77489145c3280c0b13169abec3 100644 (file)
@@ -31,11 +31,13 @@ import string
 import random
 
 try:
-    from email.mime.text import MIMEText
+    from email.mime.nonmultipart import MIMENonMultipart
+    from email.encoders import encode_7or8bit
     import email.utils
 except ImportError:
     # Python 2.4 compatibility
-    from email.MIMEText import MIMEText
+    from email.MIMENonMultipart import MIMENonMultipart
+    from email.Encoders import encode_7or8bit
     import email.Utils
     email.utils = email.Utils
 
@@ -167,6 +169,14 @@ class HashField(models.CharField):
     def db_type(self):
         return 'char(%d)' % self.n_bytes
 
+class PatchMbox(MIMENonMultipart):
+    patch_charset = 'utf-8'
+    def __init__(self, _text):
+        MIMENonMultipart.__init__(self, 'text', 'plain',
+                        **{'charset': self.patch_charset})
+        self.set_payload(_text.encode(self.patch_charset))
+        encode_7or8bit(self)
+
 class Patch(models.Model):
     project = models.ForeignKey(Project)
     msgid = models.CharField(max_length=255, unique = True)
@@ -238,7 +248,7 @@ class Patch(models.Model):
 
         body += self.content
 
-        mail = MIMEText(body, _charset = 'utf-8')
+        mail = PatchMbox(body)
         mail['Subject'] = self.name
         mail['Date'] = email.utils.formatdate(
                         time.mktime(self.date.utctimetuple()))
index ac63fb057c36faf857effdbfe27a7d2445515a62..9dde023eeeb6e1137ea67fb758f8070c9fd9dcfa 100644 (file)
@@ -48,6 +48,14 @@ class UTF8PatchViewTest(TestCase):
     def testMboxView(self):
         response = self.client.get('/patch/%d/mbox/' % self.patch.id)
         self.assertEquals(response.status_code, 200)
+        self.assertTrue(self.patch.content in \
+                response.content.decode(self.patch_encoding))
+
+    def testRawView(self):
+        response = self.client.get('/patch/%d/raw/' % self.patch.id)
+        self.assertEquals(response.status_code, 200)
+        self.assertEquals(response.content.decode(self.patch_encoding),
+                self.patch.content)
 
     def tearDown(self):
         self.patch.delete()